I notice an issue when returning to a ramfunc from a flash func. The stack pointer is not correct. In this case it is 2 less than it should be. The stack points to a value 0x0000 which eventually results in Illegal_ISR() call.
I am running bootloader. The code jumps to run-time program. Everything is fine until a specific function is called. The caller is located in RAM. The destination function is located in flash. If i step over the function call in RAM, the stack pointer is less than it should be. This is the dissassembly for the flash function:
FE08 ADDB SP, #8
7D45 MOV *-SP[5], AR5
1E44 MOVL *-SP[4], ACC
7C41 MOV *-SP[1], AR4
28AC000E MOV @T, #0x000e
8F0128E6 MOVL XAR4, #0x0128e6
E2880044 I32TOF32 R0H, *-SP[4]
3041 MPYXU ACC, T, *-SP[1]
560100A4 ADDL @XAR4, ACC
E2AF01C4 MOV32 R1H, *+XAR4[0], UNCF
E7000008 MPYF32 R0H, R1H, R0H
7700 NOP
E2030048 MOV32 *-SP[8], R0H
9245 MOV AL, *-SP[5]
EC0D SBF C$L1, EQ
3041 MPYXU ACC, T, *-SP[1]
8F0128E8 MOVL XAR4, #0x0128e8
560100A4 ADDL @XAR4, ACC
E2AF01C4 MOV32 R1H, *+XAR4[0], UNCF
E7100008 ADDF32 R0H, R1H, R0H
7700 NOP
E2030048 MOV32 *-SP[8], R0H
FE88 SUBB SP, #8
0006 LRETR
More details about this: C28 RWAIT = 3, C28x clock is 150MHz, M3 is 75MHz, ECC is disabled, Prefetch is enabled.
If I changed the flash wait state to RWAIT = 8, the code seems to execute normally. However RWAIT < 8 does not.
If I add a few lines of code causing the placement of the flash function to change (even just by 6 address locations), the symptons go away. I wonder if the issue is just masked in this case?
Also, i saw a note in the silicon errata regarding SBF and the flash prefetch causing an issue. I used the -me option, and the problem seems to go away. However, i am not convinced that all issues have been solved. Has it just moved to a different location?
Any ideas? I am concerned i have this issue in other function calls, but maybe the stack pointer just happens to be correct although the data used may not be.