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

cross mob
Dave_Long
Level 3
Level 3
10 replies posted 10 questions asked 10 sign-ins

Hi:

  Is there any way to set the constant array at a absolutely address in the flash by modustoolbox?

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

Hello @Dave_Long ,

Yes, this is possible. Determine the right address for storing the array in the flash by having a look at the map file so that you do not overwrite any of the existing sections. 

To place the array in flash, you need to use the const keyword and to place it at a fixed address you need to use the __attribute__((section ("<sectionName>"))) .

So here are the steps:

1) Navigate to your linker script folder. It can be found here: mtb_shared\TARGET_CY8CPROTO-062-4343W\latest-v2.X\COMPONENT_CM4\TOOLCHAIN_GCC_ARM\

2) Copy the linker script (.ld) and paste it in your project root folder. You can rename it if required.

3) Edit the makefile to indicate you are using a custom linker script:

 

# Path to the linker script to use (if empty, use the default linker script).
LINKER_SCRIPT=cy8c6xxa_cm4_dual.ld

 

4) Edit the linker script to add the following lines (see attached linker script for reference):

 

_array_start_address = 0x10020000;

.arraySection _array_start_address :
{
  KEEP(*(.arraySection));
} > flash

 

 

5) Declare your array in your code as follows to put it into this section.

 

const uint8_t __attribute__((section (".arraySection"))) myArray[2] = {0, 1};

 

 

6) You should be able to see your array at the fixed address you have defined as shown below:

DheerajK_81_0-1625029595785.png

 

Hope this helps! 🙂

Regards,
Dheeraj

View solution in original post

1 Reply
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello @Dave_Long ,

Yes, this is possible. Determine the right address for storing the array in the flash by having a look at the map file so that you do not overwrite any of the existing sections. 

To place the array in flash, you need to use the const keyword and to place it at a fixed address you need to use the __attribute__((section ("<sectionName>"))) .

So here are the steps:

1) Navigate to your linker script folder. It can be found here: mtb_shared\TARGET_CY8CPROTO-062-4343W\latest-v2.X\COMPONENT_CM4\TOOLCHAIN_GCC_ARM\

2) Copy the linker script (.ld) and paste it in your project root folder. You can rename it if required.

3) Edit the makefile to indicate you are using a custom linker script:

 

# Path to the linker script to use (if empty, use the default linker script).
LINKER_SCRIPT=cy8c6xxa_cm4_dual.ld

 

4) Edit the linker script to add the following lines (see attached linker script for reference):

 

_array_start_address = 0x10020000;

.arraySection _array_start_address :
{
  KEEP(*(.arraySection));
} > flash

 

 

5) Declare your array in your code as follows to put it into this section.

 

const uint8_t __attribute__((section (".arraySection"))) myArray[2] = {0, 1};

 

 

6) You should be able to see your array at the fixed address you have defined as shown below:

DheerajK_81_0-1625029595785.png

 

Hope this helps! 🙂

Regards,
Dheeraj