I am using the Cortex M4F port for an Infineon XMC4500 and I have a strange problem. I am developing a test task that writes and reads the S25FL032 flash memory. To ensure each operation is done in one go I am trying with a critical section per operation. The problem is, I get BusFaults and strange problems (for example, it makes one complete write/read loop and in the next loop, the first exit of a critical section returns to 0x000000, like if the stack was wrong.
I have checked the SP register and it is always higher thsn the top of stack that the Wittenstein Stateviewer states for the task, which makes me paranoid like if there was some problem with the stack. I am using big stack capacities.
All the code inside the flash driver is peripheral related and there are no interrupts. I have a BusFault handler but it doesnt help because lr is usually garbage or vPortCriticalEnd last asm instruction.
The most strange thing, I discovered that if I eliminate the Bad rate calculation function it doesnt hang up. I checked the function and it is just some calculations. Tomorrow I can post some more info, I knlw this is vague, but if there arent interrupts, just one task, no FreeRTOS API calls except the critical sections… Anyone has any idea what could be wrong or what I can check? Is it normal that the sp register and the stateviewer are not matching? The BusFaults do not happen without critical sections.