We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm trying to configure some software that has different start addresses based on how the FLASH gets updated. If FLASH is updated via a UART then the code should start at 0 otherwise it should start at 24K. I thought the following would work - where FLASH_VIA_UART is defined in the C51 preprocessor symbols menu.
#ifdef FLASH_VIA_UART #define RUNTIME_CODE_START_ADDRESS (RUNTIME_CODE_START_AT_0H) #else #define RUNTIME_CODE_START_ADDRESS (RUNTIME_CODE_START_AT_24kH) #endif
However, this doesn't work. Instead I have to hardcode it by commenting out everything but the 2nd line. Then the software works fine.
The RUNTIME_CODE_START_ADDRESS define could be used in other defines and macros so I suspect that there is a scope problem or something. Note that this code is in a .h file which is then used in multiple files.
"FLASH_VIA_UART is defined in the C51 preprocessor symbols menu."
This should work, so you must be doing it wrong!
You need to provide more detail of how you are defining it "in the C51 preprocessor symbols menu"
"this code is in a .h file which is then used in multiple files"
Maybe you are just defining the symbol for one file (or group of files)? You would need the definition to apply to the whole project - or, at least, to all source filse that use this header...
Rather than just have the flag defined or not, it may be "safer" to require it to have a specific value - that way you can catch any problems where the definition is accidentally missing; eg,
#ifdef FLASH_VIA_UART // It's defined - check its value, and use it if valid #if FLASH_VIA_UART == 2 #define RUNTIME_CODE_START_ADDRESS (RUNTIME_CODE_START_AT_0H) #elif FLASH_VIA_UART == 3 #define RUNTIME_CODE_START_ADDRESS (RUNTIME_CODE_START_AT_24kH) #else #error Invalid value for FLASH_VIA_UART #endif #else // It's not defined #error FLASH_VIA_UART must be defined #endif
Note that I've avoided 0 and 1 as values - as these are likely to be used by (some) compilers when the symbol is defined without a specific value...