How to reserve space in Flash
StellarisWare provides functions to read/write data into flash to provide persistant data for the application. This entry describes how to reserve space in the flash, to prevent it being used by the application code and data.
We suggest that you the top of flash memory is reserved for your persistent data.
To stop Red Suite from using the reserved area it must be excluded from the linker scripts memory map. By default, Red Suite manages the linker script, but to reserve space, you must manually edit and maintain the linker script. Note that in Stellaris chips, flash is managed in 1K pages, and so you will need to reserve the space in 1K blocks.
The changes required to an existing project are described below. The following example is for a 6965, but the principle is the same for any part.
1. Stop Red Suite managing the linker script. By default Red Suite will generate the linker script whenever the project changes.
Select the Target section of the Linker properties. (Project->Properties, Settings, MCU Linker, Target)
- uncheck the "Manage linker script" flag
- OK
- Edit the linker script to reserve the top of flash. This will prevent the linker from trying to load anything into this area. In fact, it will report an error if this occurs. In this example, I reserve 2K (0x800).
- find the MEMORY configuration section
- change the FLASH line to
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x40000 - 0x800
where:
0x40000 is the size of the flash on a 6965, and
0x800 (2048) is the amount you wish to reserve- save the linker script
Now, when you build your application, the top 2k of flash will be reserved.
- If you wanted to have a pointer to this in C, you can do the following:
- create a RESERVED_FLASH memory region. Between the FLASH and SRAM line in the MEMORY configurtion, add:
RESERVED_FLASH (rx) : ORIGIN = 0x40000 - 0x800, LENGTH = 0x800
- define the RESERVED_FLASH as a section, and place a symbol in it. In the SECTIONS configuration, add
.reserved_flash :
{
_reservedFlashStart = . ;
} > RESERVED_FLASHThis defines a section called ".reserved_flash" and defines a symbol "_reservedFlashStart" in it, and locates it in the RESERVED_FLASH region.
- declare the symbol in C and take it's address
extern void _eReservedFlashStart ; void *ptr = &_reservedFlashStart ;
