How can I define symbols using the start address of memory regions?
A standard linker script contains a part that defines the memory layout of your microcontroller. In the following, a simple example is described.
MEMORY
{
flash : org = 0x00000000, len = 1536k
ram : org = 0x40000000, len = 94k
}
Derived from the name of the memory regions the user can define symbols.
flash_size = LENGTH(flash);
flash_start = ORIGIN(flash);
flash_end = ORIGIN(flash) + LENGTH(flash);
ram_size = LENGTH(ram);
ram_start = ORIGIN(ram);
ram_end = ORIGIN(ram) + LENGTH(ram);
These symbols can be used in the C-source code of your application.
/* Check, if flash memory is empty */
int i;
unsigned char* cp;
extern int flash_size[];
extern int flash_start[];
bool flash_empty = TRUE;
cp = (unsigned char*) flash_start;
for (i = 0; i < flash_size; i++) {
if (*cp != 0xff) {
flash_empty = FALSE;
break;
}
cp++;
}
This example is not complete, it needs to be customized according to your setup. This is an example of how such a setup can look. |