- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Is there any way to set the constant array at a absolutely address in the flash by modustoolbox?
Solved! Go to Solution.
- Labels:
-
PSoC 6 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
Hope this helps! 🙂
Regards,
Dheeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
Hope this helps! 🙂
Regards,
Dheeraj