STM32F072 的BootLoader 不能夠進行Vector table的relocation的解決方案


在RM中給出了解決方案。

Unlike Cortex® M3 and M4, the M0 CPU does not support the vector table relocation. For application code which is located in a different address than 0x0800 0000, some additional code must be added in order to be able to serve the application interrupts. A solution will be to relocate by software the vector table to the internal SRAM:
• Copy the vector table from the Flash (mapped at the base of the application load address) to the base address of the SRAM at 0x2000 0000.
• Remap SRAM at address 0x0000 0000, using SYSCFG configuration register 1.
• Then once an interrupt occurs, the Cortex®-M0 processor will fetch the interrupt handler start address from the relocated vector table in SRAM, then it will jump to
execute the interrupt handler located in the Flash. This operation should be done at the initialization phase of the application. Please refer to
AN4065 and attached IAP code from www.st.com for more details.

自己在stm32CubeIDE中實現的代碼如下,在main初始化的適當位置中可以對其進行調用。注意需要包含頭文件

stm32f0xx_hal.h

void vector_table_and_remap(void)
{
    uint32_t addr = 0x08008000; //this address should be same as defined in linker file of this project.
    memcpy((void*)0x20000000, (void*)addr, VECTOR_SIZE);
    /* this feature is not the part of "STM32 Cortex-M0 processor programming
       model, instruction set and core peripherals."
       please refer to "System configuration controller (SYSCFG)" in RM.
    and refer to "Boot configuration".
    as is
    "Boot from main Flash memory: the main Flash memory is aliased in the boot memory space (0x00000000),
     but still accessible from its original memory space(0x08000000).
     In other words, the Flash memory contents can be accessed starting from address 0x00000000 or 0x08000000."

     *
     *  */
    __HAL_SYSCFG_REMAPMEMORY_SRAM(); //20200317. first tested, it works.

}

 

不同內核的芯片的處理方式是不一樣的。在是stm32cubeide中,以一個stm32F4的芯片為例,src文件夾下面的system_stm32f4xx.c提供了SystemInit()提供了中斷的vector table的offset的設置。
可以將vector table放到ram當中去即可。這種處理方式由於硬件的支持而變得更加靈活和合理。

術語表示:
Boot:CAN BootLoader的簡稱。由一個獨立的工程創建。只有在通過can對設備進行升級的時候使用。
App: 由一個獨立的工程創建,完成所有功能。由於STM32F072這款芯片的特殊性(是Cortex M0內核),存在少量對boot的依賴。

先設定STM32的BootLoader占用空間為32K。

對App的修改如下:
1、對RAM和Flash的修改
所以App的的Flash起始地址需要從 0x08008000 開始。
由於該芯片的Vector table無法實現relocation。而使用芯片的參考手冊中提到的__HAL_SYSCFG_REMAPMEMORY_SRAM()可以解決這個問題。整個中斷向量表的位置放置在RAM中。APP的RAM的起始地址為0x200000C0。


2、對Boot的依賴
在加入BootLoader后,第一次調試app之前,需要對MCU刷入任意版本的boot的二進制文件,否則可能導致程序無法正常啟動,無法運行。
由於加入了boot之后,里面存在相互依賴。

3、需要在app的main.c中加入一行特殊的初始化的代碼。
此項為重大修改。否則整個app無法正常工作。

對於Boot的修改如下:

由於boot是一個單獨的工程,所以,在App已完成適配的前提下,不需要做特殊處理。除非原定的32K的Flash空間不能夠容納boot。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM