I have a lot of data structures that I need to place on calculated addresses in flash memory.
The same code will be used on many different RX devices, but the calculations can be performed using numbers in the r_flash_rx header file.
My expectation was to calculate the addresses using the preprocessor, but it appear the #pragma address implementation is limited to literal hex string values. :-(
Reading in the forum, I find several mentions of using the C99 pragma extension, or the Microsoft specific pragma extension, and it seems to resolve some problems.
However specifically for the #pragma address appear to fall short. Please see my tests below, which indicates that they all suffer from the same problem:
#define INFO_ADDRESS_X 0xFFFE0000 #define INFO_ADDRESS_XX (INFO_ADDRESS_X+2) /// Please only enable one of the below pragma statements at a time. /// Orginary pragma implementation, set with defines. #pragma address VersionInFlash=0xFFFE0000 // ok - address is a hex string. #pragma address VersionInFlash=4294836224 // E0523005:Invalid pragma declaration - so the address can not be decimal. #pragma address VersionInFlash=(0xFFFE0000+2) // E0523005:Invalid pragma declaration - My guess is this is also a decimal address problem? #pragma address VersionInFlash=INFO_ADDRESS_X // ok - address is still a hex string. #pragma address VersionInFlash=INFO_ADDRESS_XX // E0523005:Invalid pragma declaration - My guess is this is also a decimal address problem. /// C99 pragma extension - The string-literal is the input to _Pragma. Outer quotes and leading/trailing whitespace are removed. \" is replaced with " and \\ is replaced with \. Must not be inside #if's _Pragma ("address VersionInFlash=0xFFFE0000") // ok - address is a hex string. _Pragma ("address VersionInFlash=4294836224") // E0523005:Invalid pragma declaration - so the address can not be decimal. _Pragma ("address VersionInFlash=INFO_ADDRESS_X") // ok - address is still a hex string. _Pragma ("address VersionInFlash=INFO_ADDRESS_XX") // E0523005:Invalid pragma declaration - My guess is this is also a decimal address problem. ///Microsoft pragma extension __pragma (address VersionInFlash=0xFFFE0000) // ok = Compiles correctly - But E2Studio complains "Type 'address' could not be resolved" __pragma (address VersionInFlash=4294836224) // E0523005:Invalid pragma declaration - so again the address can not be decimal. __pragma (address VersionInFlash=INFO_ADDRESS_X) // E0523005:Invalid pragma declaration - My guess is this is also a decimal address problem. __pragma (address VersionInFlash=INFO_ADDRESS_XX) // E0523005:Invalid pragma declaration - My guess is this is also a decimal address problem. const uint32_t VersionInFlash = { 42 };
For now this means I need to calculate all the addresses by hand every time we add a new MCU, which isn't optimal.
Alternatively I need to place the calculations in an external script, which is called during the pre_build stage, but that's not optimal either.
Are there other alternatives that I have missed?
I'd like to make a feature request, so that addresses such as this in the future can be calculated using preprocessor macros.
Hello fsteff,
As you already mentioned, #pragma address derivative on CC-RX compiler is supported only for literal hex string values.
We will inform the dev team with your request for a possible future update.
Regards