Placing uint32 array with compiler optimization "size"

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

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()

  {

        ...

  }

pastedImage_1.png

pastedImage_3.png

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

pastedImage_4.png

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

0 Likes
1 Solution
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

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);

        UART_UartPutString(buffer);

    }

    for(;;)

    {

        /* Place your application code here. */

    }

}

Here's the output (decimal values):

pastedImage_3.png

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.

pastedImage_7.png

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

View solution in original post

0 Likes
2 Replies
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

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);

        UART_UartPutString(buffer);

    }

    for(;;)

    {

        /* Place your application code here. */

    }

}

Here's the output (decimal values):

pastedImage_3.png

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.

pastedImage_7.png

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

0 Likes

Hello Dheeraj-san,

Thank you very much for your advice.

You are right.

After changing the code, the array was placed.

pastedImage_0.png

pastedImage_1.png

pastedImage_2.png

pastedImage_3.png

Best regards,

Yocchi

0 Likes