The experience summary when using DSP28335 is mainly some problems of using large-dimensional two-dimensional arrays

This part mainly wants to use an array with a larger dimension, here is 112X112.

1. Array or pointer

The first is the use of arrays. You can use pointers or direct arrays. In fact, a two-dimensional array in memory is one-dimensional. It stores one line first, and then stores other lines. The storage order in consecutive addresses is: a[ 0][0], a[0][1], a[0][2]....a[1][0], a[1][1], a[1][2].. ..........'About the pointer and the above equivalent expression array is: (*((Uint16 *)a+(N*i)+j)), where N is the column size of the array, that is How many data is there in a row, then i is the row number, and j is the column. The difference between directly using arrays and pointers is actually the running speed of the program. Generally speaking, pointers will run faster, but it also depends on how the code is written, because their essence is memory addresses, so if you start learning , just want to realize the function, just use the array directly.

2. When an array is passed to a function as a parameter

Because arrays and pointers are shared, after defining a[][], it is also possible to use **a, or even use & to call the defined array, but each has a different meaning, so when the input parameter of the function has an array Or pointers to pay attention to. Here you can give an example, in the function

float *factor(float **e,Uint16 n) 
{
    Uint16 i = 0;
	Uint16 j = 0;
    float factor0[3];
    for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{

            *((float *)e+(n*i)+j) = n*i+j;
        }
    }
    factor0[0]  = *((float *)e);  //[0][0]
	factor0[1]  = *((float *)e+1);;  //[0][1]
	factor0[2]  = *((float *)e+n);   //[1][0]
    return factor0;
}

Then when calling in main:

float e[N][N];
float * factor0;

factor0 = factor((float **)e,N) 

You must pay attention to the calling method when the function is input or output when the array is used. You can compare it yourself. If it is difficult to understand, just write it as you like, or observe the values ​​​​of these variables in the CCSdebug window. During transmission, some addresses may be transmitted.

3. Regarding the use of large arrays in CCS

My version here is V6. First of all, it is not possible to perform pure software simulation, so it is necessary to perform software configuration according to the previous version to perform pure software simulation. Finally, it is actually to configure different emulator parameters to perform pure software simulation or connect the development board. Hardware simulation, this can be done by Baidu to configure software simulation of CCS. Then there is the issue of memory size. At first, I set the N of the two-dimensional array to define. After the algorithm function is completed, when N is small, the calculation can be performed, but when N is increased, the program cannot If it runs successfully, it will even get stuck in the first few steps of variable declaration and system clock initialization of the main function, and it will keep looping. The following algorithm calculation will not be performed, but no error will be reported.

At first I thought it was a problem of memory allocation. You can see the memory usage in the view. I have allocated a larger memory, even the zone7 external expansion address in xintf, but it still doesn't work. After several days of experiments, the summary is as follows:

When performing large-scale array operations:

To use global variables or dynamic allocation, the global variable is the variable defined on the main, the test can realize a large-scale array, the dynamic allocation did not test successfully, it should be that I will not allocate. Among them, why global variables can be used, but local variables cannot be used, it seems that the local variables are defined in a fixed part of the current, and this size seems to be fixed and small, so when the array itself is large, there is no continuous The remaining addresses are placed, while global variables are placed in the cmd file, and the size can be customized.

And this cmd file, in the final analysis, is the declaration and allocation of the memory address of 28335. It is to name the address segment and the starting address and length in page0 and page1. This is allocated according to the actual memory address of 28335. It should be noted that That is, when using the address of xintf, it should be configured or initialized first. I used to directly assign .bss to the address of zone7, so when debugging, it will be displayed behind the variable of this part, and the address cannot be used. read. Also, the cmd file can be modified by yourself, because it is a beginner, I thought it was a configuration file. After dividing the memory address of the chip into segments (it is possible to put some address segments together, as long as the addresses are not repeated), it is necessary to allocate memory to the code segments and variables in the program, such as .text, .ebss, Everyone knows these things on Baidu. Here are some cmds I modified:

MEMORY
{
PAGE 0 :
   /* BEGIN is used for the "boot to SARAM" bootloader mode      */
   /* BOOT_RSVD is used by the boot ROM for stack.               */
   /* This section is only reserved to keep the BOOT ROM from    */
   /* corrupting this area during the debug process              */
   
   BEGIN      : origin = 0x000000, length = 0x000002     /* Boot to M0 will go here                      */
   BOOT_RSVD  : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */               
 //  RAMM0      : origin = 0x000050, length = 0x0003B0
   RAMM0      : origin = 0x000050, length = 0x0007B0
//   RAML0      : origin = 0x008000, length = 0x001000
//   RAML1      : origin = 0x009000, length = 0x001000
 //  RAML2      : origin = 0x00A000, length = 0x001000
//   RAML3      : origin = 0x00B000, length = 0x001000
   ZONE6A     : origin = 0x100000, length = 0x00FC00    /* XINTF zone 6 - program space */ 
   CSM_RSVD   : origin = 0x33FF80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
   CSM_PWL    : origin = 0x33FFF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA            */
   ADC_CAL    : origin = 0x380080, length = 0x000009  //0x000009
   RESET      : origin = 0x3FFFC0, length = 0x000002
   IQTABLES   : origin = 0x3FE000, length = 0x000b50
   IQTABLES2  : origin = 0x3FEB50, length = 0x00008c
   FPUTABLES  : origin = 0x3FEBDC, length = 0x0006A0
   BOOTROM    : origin = 0x3FF27C, length = 0x000D44               

         
PAGE 1 : 
//   RAMM1      : origin = 0x000400, length = 0x000400  //0x000400   /* on-chip RAM block M1 */
 //  RAML4      : origin = 0x00C000, length = 0x001000
  // RAML5      : origin = 0x00D000, length = 0x001000
//   RAML6      : origin = 0x00E000, length = 0x001000
 //  RAML7      : origin = 0x00F000, length = 0x001000
  RAML4      : origin = 0x008000, length = 0x008000
   ZONE7B     : origin = 0x20FC00, length = 0x000400 //0x000400    /* XINTF zone 7 - data space */

	SARAML0      : origin = 0x3F8000, length = 0x002000
}
 
 
SECTIONS
{
   /* Setup for "boot to SARAM" mode: 
      The codestart section (found in DSP28_CodeStartBranch.asm)
      re-directs execution to the start of user code.  */
   codestart        : > BEGIN,     PAGE = 0
   ramfuncs         : > RAMM0,     PAGE = 0    //RAML0
   .text            : > RAML4,     PAGE = 1   //RAML1
   .cinit           : > RAMM0,     PAGE = 0  //RAML0
   .pinit           : > RAMM0,     PAGE = 0   //RAML0
   .switch          : > RAMM0,     PAGE = 0   //RAML0
   
  .stack           : > RAMM0,     PAGE = 0    //RAMM1
   .ebss            : > RAML4,     PAGE = 1   //RAML4
   .econst          : > RAML4,     PAGE = 1        //RAML5
   .esysmem         : > RAMM0,     PAGE =0   //RAMM1

.bss            : > RAML4,     PAGE = 1

   IQmath           : > RAMM0,     PAGE = 0   //RAML1
   IQmathTables     : > IQTABLES,  PAGE = 0, TYPE = NOLOAD 
   IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD 
   FPUmathTables    : > FPUTABLES, PAGE = 0, TYPE = NOLOAD 
      
   DMARAML4         : > RAML4,     PAGE = 1
//   DMARAML5         : > RAML5,     PAGE = 1
 //  DMARAML6         : > RAML6,     PAGE = 1
//   DMARAML7         : > RAML7,     PAGE = 1
   
   ZONE7DATA        : > ZONE7B,    PAGE = 1

   .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used                    */
   csm_rsvd         : > CSM_RSVD   PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
   csmpasswds       : > CSM_PWL    PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
   
   /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
   .adc_cal     : load = ADC_CAL,   PAGE = 0, TYPE = NOLOAD
     
}

Then talk about the test process: When I use the local variable array for small-dimensional calculations, there is no problem. When the dimension is expanded, it will not expand, but the program has been initializing the loop. Then define the array as a global variable , the cmd file will report an error, because the .ebss address for storing the global variable is not enough, (that is, when the program only has memory problems, it will automatically report an error, because I have been thinking about it before. Dynamic The memory is not enough, because the memory of some of these variables is enough, but the program fails to run, thinking that there are other memory consumption during the calculation process, but now it seems that it is not, when the program is compiled, it has been automatically considered Memory problem), so just splicing a large address segment to ebss . (Some also said that you can add | to the address, which means "or" other addresses, but it still doesn't seem to work. I will directly block some of them later, and directly splice them into a large address space)

Guess you like

Origin blog.csdn.net/qq_43811597/article/details/129816525