Jumping from one firmware to another in MCU internal FLASH

后端 未结 3 952
余生分开走
余生分开走 2021-01-03 09:32

I am currently working on a bootloader firmware application targeted to STM32F030C8. I specified in my scatter file that the bootloader app will occupy main memory location

3条回答
  •  死守一世寂寞
    2021-01-03 10:06

    In file 'startup_stm32f03xx.s', make sure that you have the following piece of code:

    EXTERN  HardFault_Handler_C        ; this declaration is probably missing
    
    __tx_vectors                       ; this declaration is probably there
        DCD     HardFault_Handler
    

    Then, in the same file, add the following interrupt handler (where all other handlers are located):

        PUBWEAK HardFault_Handler
        SECTION .text:CODE:REORDER(1)
    HardFault_Handler
        TST LR, #4
        ITE EQ
        MRSEQ R0, MSP
        MRSNE R0, PSP
        B HardFault_Handler_C
    

    Then, in file 'stm32f03xx.c', add the following ISR:

    void HardFault_Handler_C(unsigned int* hardfault_args)
    {
        printf("R0    = 0x%.8X\r\n",hardfault_args[0]);         
        printf("R1    = 0x%.8X\r\n",hardfault_args[1]);         
        printf("R2    = 0x%.8X\r\n",hardfault_args[2]);         
        printf("R3    = 0x%.8X\r\n",hardfault_args[3]);         
        printf("R12   = 0x%.8X\r\n",hardfault_args[4]);         
        printf("LR    = 0x%.8X\r\n",hardfault_args[5]);         
        printf("PC    = 0x%.8X\r\n",hardfault_args[6]);         
        printf("PSR   = 0x%.8X\r\n",hardfault_args[7]);         
        printf("BFAR  = 0x%.8X\r\n",*(unsigned int*)0xE000ED38);
        printf("CFSR  = 0x%.8X\r\n",*(unsigned int*)0xE000ED28);
        printf("HFSR  = 0x%.8X\r\n",*(unsigned int*)0xE000ED2C);
        printf("DFSR  = 0x%.8X\r\n",*(unsigned int*)0xE000ED30);
        printf("AFSR  = 0x%.8X\r\n",*(unsigned int*)0xE000ED3C);
        printf("SHCSR = 0x%.8X\r\n",SCB->SHCSR);                
        while (1);
    }
    

    If you can't use printf at the point in the execution when this specific Hard-Fault interrupt occurs, then save all the above data in a global buffer instead, so you can view it after reaching the while (1).

    Then, refer to the 'Cortex-M Fault Exceptions and Registers' section at http://www.keil.com/appnotes/files/apnt209.pdf in order to understand the problem, or publish the output here if you want further assistance.

提交回复
热议问题