cancel
Showing results for 
Search instead for 
Did you mean: 

Could someone explain this ''Reset Handler''?

Vu.Andy
Associate III
Posted on July 20, 2016 at 00:08

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.                 ENDP

3 REPLIES 3
Posted on July 20, 2016 at 01:26

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Vu.Andy
Associate III
Posted on July 20, 2016 at 01:57

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)

  {

  }

}

Posted on July 20, 2016 at 02:52

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..