Skip to main content
Vu.Andy
Associate III
July 19, 2016
Question

Could someone explain this ''Reset Handler''?

  • July 19, 2016
  • 3 replies
  • 4559 views
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

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    July 19, 2016
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Vu.Andy
    Vu.AndyAuthor
    Associate III
    July 19, 2016
    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)

      {

      }

    }

    Tesla DeLorean
    Guru
    July 20, 2016
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..