When I compile my code the linker put some variables in overlay zone. Since some are from main call tree and others from ISR call tree, I get corrupted data. I know that I can instruct the linker to not overlay that segment but I cannot understand why it do it and I'm afraid that some other similar problem is hidden somewhere and I didn't notice it.
From BL51 user guide: The local variables and parameters of function_a are overlaid with the variables and parameters of function_b only under the following conditions: (...) The functions A and B may be invoked by only one program event or root: either the main root or an interrupt but not both. It is impossible to overlay variables and parameters if a function is called by an interrupt and the main program or by two interrupts.
This are the two functions using the variables
void FRAM_writeB(uint32_t addr, uint8_t* datas, uint8_t qtyB) { uint8_t savedSFRPage = SFRPAGE; (...) void getMaximumValues (trendPoint *maxValues, uint32_t startPtr, uint8_t nPoints, const uint32_t tableStart, const uint32_t tableEnd) { (...)
Here some parts of the linker map file, where the call tree is correct but the variable are overlayed.
*** NEW ROOT ******************************** TIMER4_ISR/INTERRUPTS ----- ----- ----- ----- ----- ----- +--> MEMS_DATA/BMA280 (...) MEMS_DATA/BMA280 ----- ----- 0034H 0041H ----- ----- +--> _FRAM_WRITEB/FRAM (...) _FRAM_WRITEB/FRAM ----- ----- 0058H 0060H ----- ----- +--> _FRAM_STARTWRITE/FRAM (...) *** NEW ROOT ******************************** ?C_C51STARTUP ----- ----- ----- ----- ----- ----- +--> MAIN/HMT (...) MAIN/HMT ----- ----- 0051H 0053H ----- ----- +--> TRENDMANAGEPOWERON/TREND (...) TRENDMANAGEPOWERON/TREND ----- ----- 0054H 0057H ----- ----- +--> _GETMAXIMUMVALUES/TREND (...) _GETMAXIMUMVALUES/TREND ----- ----- 0058H 0067H 007AH 0083H (...) SYMBOL TABLE OF MODULE: HMT.OMF.CRBUILD (BMA280) VALUE REP CLASS TYPE SYMBOL NAME ==================================================== (...) 00000060H SYMBOL DATA DWORD tableStart (...) 00000060H SYMBOL DATA BYTE savedSFRPage