2 Replies Latest reply on Mar 29, 2020 5:19 PM by YoIs_1298666

    Placing uint32 array with compiler optimization "size"

    YoIs_1298666

      Hello,

       

      If we compile the following code with optimazation "debug",  we can place uint32 array in FLASH area.

       

      [main.c]

      #include <projcect.h>

      volatile int32 g_vsin[360] __attribute__ ((section (".FlashData"))) =

                        {0x0F8,0x0FC,0x100,0x105,0x109,0x10D,0x112,0x116,0x11A,0x11F,

                          ...

                        };

       

        int main()

        {

              ...

        }

      But if we compile the code with optimazation "size" or "speed",  we can not place uint32 array in FLASH area.

      How can we place int32 array?

      In addition, in case of uint8 array size, we could place it in compiler optimazation "size".

       

      Best regards,

      Yocchi

        • 1. Re: Placing uint32 array with compiler optimization "size"
          DheerajK_81

          Hello Yocci,

           

          How are using the array inside the main function? The optimization on the array depends on what operations you are performing on it. If the compiler feels that the section you have declared for the array is not required then you won't see it in the map file.

           

          For example, I declared the array first.

           

          volatile int32 g_vsin[360] __attribute__ ((section (".FlashData"))) =

                        {0x0F8,0x0FC,0x100,0x105,0x109,0x10D,0x112,0x116,0x11A,0x11F,

                          ...

                          };

           

          And then inside main, I'm printing the values inside the array:

          int main(void)
          {
              CyGlobalIntEnable; /* Enable global interrupts. */
          
          
              /* Place your initialization/startup code here (e.g. MyInst_Start()) */
              
              UART_Start();
              
              char buffer[500];
              
              UART_UartPutString("Uart initialized\r\n\n");
              
              sprintf(buffer, "Size of array: %d \n\n\r", sizeof(g_vsin));
              UART_UartPutString(buffer);
              
              for(uint i = 0; i < 360; i++)
              {
                  if(i % 10 == 0 && i > 0){
                      UART_UartPutString("\n\r");
                  }
                  sprintf(buffer, " %ld ", g_vsin[i]);
                  UART_UartPutString(buffer);
              }
          
          
              for(;;)
              {
                  /* Place your application code here. */
              }
          }
          

           

          Here's the output (decimal values):

           

          Now irrespective of the optimization I set (debug, size, speed), I see the array present in my flash.

          flash.PNG

           

          If I comment out the operations I do on the array in main, I do not see this section in the memory map file because it is unused.

           

          In case you want the arrray to be available even when the section is unused in your code, you can go to Build Settings > ARM GCC > Linker > Optimization > Remove Unused Sections > False.

           

           

          You should see the array values now in the provided address. In my case, I used 0x2000 because I tried it on the PSoC4 BLE Pioneer kit to avoid overlapping over another section at 0x1000.

          flash2.PNG

           

          Hope this helps

           

          Regards,

          Dheeraj

          • 2. Re: Placing uint32 array with compiler optimization "size"
            YoIs_1298666

            Hello Dheeraj-san,

             

            Thank you very much for your advice.

            You are right.

            After changing the code, the array was placed.

            Best regards,

            Yocchi