Hello,
if i power up my system i get an BusFault. On a lucky punch it works. If i Debug the system the fault doesnt happen.
I have found out where the fault happens and the reason why is absolutely clear. But i cant find out how the system comes in this state for the fault.
This is a short code snipped where the fault happend
nrfx_err_t uarte_get_async_data(uarte_select_e const sel, uarte_rx_buffer_t ** const pp_data) { ... ... (*pp_data)->lengh = 0; //there the fault happens //save buffer location uarte_rx_buffer_t * tmp = *pp_data; //disable irq while operate on global rxDatas //only change the two buffers, do not copy content __disable_irq(); *pp_data = p_cont->rxDatas.buffer; p_cont->rxDatas.buffer = tmp; __enable_irq(); return... }
in the line where i set the lengh to 0 the fault happen because of some reason *pp_data points to a wrong address eg 0x0601235d!
I have an Cortex-M4 and as debug interface i only can use SWDIO/SWDCLK. I dont have the SWO pin!
I also can use further GPIO pins to morse some status codes to my logic analyser ;).
first step i have done is to check why the busfault occure:
-> check BFSR Register -> IMPRECISSER Bit was set -> disable caching:
volatile uint32_t* ACTLR = (uint32_t*)0xe000e008; *ACTLR |= 0x2;
-> now BFSR Register -> PRECISERR is set and BFAR Register is: 0x0601235d -> match with the content of the *pp_data if i attach the debugger when the system is already crashed!!
Okey thats it, i also know definitly that anywhere write to the content of my *pp_data variable! But where because when i debug the fault doesnt happen!
The next step i tried:
-> Use Data Watchpoint and Trace Unit (DWT)!
DWT work if i use the Debugger and the CPU HALT, but the problem only occure during power up without debugger! DWT without debugger CANT HALT the CPU it is only possible to send an Debug event and call the DebugMon_Handler!
I thought if the memory access to the variable occure the DWT send an Debug event and call the DebugMon_Handler, in the handler i run while(true). If this happend i have enought time to attach the debugger and check the stackframe!
i configured the moinitor exception like this:
CoreDebug->DEMCR |= 0x10000; //MON_EN CoreDebug->DEMCR |= 0x1000000; //TRCENA CoreDebug->DEMCR |= 0x7F0; //Debug Traps
I have tested the DebugMon_Handler if i insert an __asm("bkpt") the DebugMon_Handler will be called! but when i do an write access to the pp_data variable the DebugMon_Handler wont be called! As i already said if i debug and write to the pp_data variable the CPU HALT -> DWT seems to work, but only with connected Debugger, on disconnected Debugger the DebugMon_Handler wont be called.
I configured the DWT like this, if i write 0x0601235d to the variable "check" the CPU halt:
DWT->COMP3 = (uint32_t)✓ DWT->COMP1 = 0x0601235d; DWT->FUNCTION1 = 0x3b06;
Any further proposals what i can do/check to find out who writes to the pp_data variable?