Place constant at specific location in flash
I need to store a constant value at a specific location in flash.
The idea is that the bootloader can read this location, to know what is the current firmware version.
Ideally, I also need to be able to read this value directly from the .hex file. Therefore, I don't want the APP to write it in flash at runtime.
I started with the following declaration:
static const uint16_t TEST_VERSION __attribute__ ((space(prog),address(0x9D016000))) = 36 ;
To read the value, I simply go with :
uint16_t * ptr ;
ptr = (void *) 0x9D016000 ;
tmpUint16 = (uint16_t) *ptr ;
As seen from several posts in the forum, I tried with/without const, static, volatile.
Also tried some other attributes, but it made no difference
- used: seem to only be made for functions, not for variables/constants
- optimize(-O0) : ignored by compiler
- Tried several flash address, in case there was some specific restrictions for some addresses
Keeping the default settings of my project, this does not work : I the value is always read as 0xFF.
Reading the flash and checking at 0x9D016000, confirms this.
The compiler seem to automatically remove this constant from the program, as it is not used. Setting code optimisation to 0 does not help.
With optimization 1 and unchecking the "remove unused section" parameter in xc32-ld, I am able to read my constant.
However, this will significantly change the program size, from 70kB to 80kO ... which is quite a lot to just add a 16 bit variable !Attachments are not available: Download requirements not met
Is there a simple way to achieve my goal ?
post edited by Vincent44 - 2020/07/07 00:40:37