I am experiencing an high undesirable behavior on C8051F500DK kit. My scenario is: Toolchain: PK51 Prof. Developers Kit for SiLabs Version: 9.52.0.0 Toolchain Path: C:\Keil\C51\BIN C Compiler: C51.Exe V9.52.0.0 Assembler: A51.Exe V8.02b Linker/Locator: BL51.Exe V6.22 Librarian: LIB51.Exe V4.29 Hex Converter: OH51.Exe V2.7.0.0 CPU DLL: S8051.DLL V3.91.0.0 Dialog DLL: DCYG.DLL V2.72.0.0 Target DLL: SiC8051F.dll V3.8.0.0 Dialog DLL: TCYG.DLL V2.70
I am using LARGE memory model, with variables in XDATA. C51 optimization in level 3 (Peephole Optimizing) with emphasis on size.
I have this test case, ALWAYS reproducible:
typedef enum { TPDU_MSG_COMPLETE, TPDU_NO_INIT, TPDU_MSG_NOT_READY, .... } static TpduRetCode_t MyFunc(void) { TpduRetCode_t ret = TPDU_MSG_NOT_READY; // *A* if(...) { ... TPDU_FC_t fc; uint8_t txBuff[TPDU_PACKET_BYTELEN]; ... if(TxHndlr != NULL) { if(TxHndlr(txBuff) == TRUE) // *B* { ... } } } }
At point *A* ret is equal to 2, but when executing function at point *B*, ret becomes equal to 0. TxHndlr() is not affecting ret. For example, ret is located in last run at X:0x06. When entering in TxHndlr() this location is overwritten by function and is NOT restored when exiting the function.
If I remove all optimization (level 0, constant Folding) the problem seems to disappear. Useless to say, if I do not optimize my code is too large for my memory mapping.
What is happening? How can I solve?
Thanks