2016-07-19 03:08 PM
I am using Keil uVision, and occasionally, at start of debug, the program counter would stuck
at the Rest handler routine below. The execution would point to the instruction: ''BLX R0'' (line #2) and would never go to the _Main() routine. Does anyone know what could be the problem? Thanks. ; Reset handler routine Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IMPORT SystemInit 1. LDR R0, =SystemInit 2. BLX R0 3. LDR R0, =__main 4. BX R0 5. ENDP2016-07-19 04:26 PM
It would suggest you have an infinite loop in the SystemInit() code (system_stm32fxxx.c), like waiting for HSE, PLL, or a clock switch. Or some other error/fault.
Turn Off ''run to main()'' and step into the routine to debug it. The code is equivalent to CALL SystemInit JMP __main The code in __main unpacks the load region containing the statics into RAM, before branching to your main() code. If any of the code touches the wrong memory there is the potential for it to Hard Fault. Review the code execution in the debugger. If it gets stuck, and you stop execution, determine where it is stopped/stuck.2016-07-19 04:57 PM
I found out that there is a function call in main() that is causing it though I am not sure why. If I comment out that function, it then would work fine.
I am not sure why because the function is called way down in main(). ISLReadADC() below is rather basic there is nothing unique about it but I am not sure why it would cause problem. The program is fairly basic: int main(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); uint8_t buff[2]; buff[0] = 0x00; buff[1] = 0x00; // ISLReadADC( ); while (1) { } }2016-07-19 05:52 PM
My guess is that you are running a Cortex-M4, this function returns a float, the compiler is using the FPU and you don't actually enable the FPU...
Would suggest you have a Hard Fault Handler that does something, and use the debugger.