#define FLASH_STARTING_ADDRESS 0x00000000U
Can we use the definitons from the linker file rather than hardcoding address here
#define FLASH_STARTING_ADDRESS 0x00000000U
Can we use the definitons from the linker file rather than hardcoding address here
Hi Santhosh,
Can you provide more context to this? I am not sure I quite understand what you are asking. Do you mean if you can use definitions as the values inside of the memory directive?
MEMORY
{
FLASH (RX) : origin = 0x00000000, length = 0x0000FFF8
SRAM (RWX) : origin = 0x20000000, length = 0x00001000
BCR_CONFIG (R) : origin = 0x41C00000, length = 0x000000FF
BSL_CONFIG (R) : origin = 0x41C00100, length = 0x00000080
}
Best,
Owen
Hi Santhosh,
There aren't definitions generated for the origin and length in the linker file that you can use in C files. Hardcoding these definitions is likely the best option since memory layouts rarely change during development and it requires the least amount of changes to your project.
If you want to create definitions within the linker file, you would still have to hardcode them. Furthermore, you would have to disable linker file generation within the .syscfg file so that these definitions don't get erased upon building the project. I personally wouldn't recommend this. However, if you want to follow this approach, this is an example of what you would need to add to your linker file:
__FLASH_START = 0x00000000; __FLASH_END = 0x0000FFF7; /* 0x00000000 + 0x0000FFF8 - 1 */ __FLASH_SIZE = 0x0000FFF8; __SRAM_START = 0x20000000; __SRAM_END = 0x20000FFF; /* 0x20000000 + 0x00001000 - 1 */ __SRAM_SIZE = 0x00001000;
You would need to make a copy of the linker file and move it outside of the Debug folder.
Upon building, you can observe GLOBAL SYMBOLS in the .map file. You can then access them in your C file like so:
extern const uint32_t __FLASH_START; extern const uint32_t __FLASH_END; extern const uint32_t __FLASH_SIZE; extern const uint32_t __SRAM_START; extern const uint32_t __SRAM_END; extern const uint32_t __SRAM_SIZE; #define FLASH_STARTING_ADDRESS ((uint32_t)&__FLASH_START) // 0x00000000 #define FLASH_ENDING_ADDRESS ((uint32_t)&__FLASH_END) // 0x0000FFF7
As you can see, this is much more work than hardcoding the definitions in your .c or .h file.
Best,
Owen
Thank you for the reply
How to access this variable without using global variable which means without extern.
I know static declaration it won't work. Any other idea directly access from the Linker file without using global variable.
Hi Santhosh,
I understand the confusion about 'global variables,' but linker symbols are fundamentally different from regular global variables.
The extern declarations are not creating global variables. They're telling the compiler how to access symbols that the linker creates. This is the standard, industry-accepted method used in all embedded systems.
There is no other way to access linker-defined memory regions in C code.
Is there a reason why you don't want to hardcode definitions? This would be essentially as maintainable as defining symbols in the linker file.
Best,
Owen