How to use Linker-generated symbols

From SEGGER Wiki
Jump to: navigation, search

This article will explain how to use linker generated symbol in the right way.

Linker-generated symbols are actually pointers / arrays at the address instead of integers with the address as value.

As such its use might be a bit different and unusual.


The following code snippet shows a example of using Linker-generated symbols:

extern unsigned char __FLASH_segment_start__[];
extern unsigned char __FLASH_segment_end__[];
extern unsigned char __FLASH_segment_size__[];

extern unsigned char __FLASH_segment_used_start__[];
extern unsigned char __FLASH_segment_used_end__[];
extern unsigned char __FLASH_segment_used_size__[];

static void _Print(unsigned int Start, unsigned int End, unsigned int Size) {
 printf("  0x%.8X - 0x%.8X, size: %u\n", Start, End, Size);
}

int main(void) {
 printf("Flash:\n");
 _Print((unsigned int)__FLASH_segment_start__, (unsigned int)__FLASH_segment_end__, (unsigned int)__FLASH_segment_size__);
 printf("Used:\n");
 _Print((unsigned int)__FLASH_segment_used_start__, (unsigned int)__FLASH_segment_used_end__, (unsigned int)__FLASH_segment_used_size__);
}