Cortex-M3/M4與M0架構IAP過程簡單總結
本文主要側重Cortex-M3/M4與Cortex-M0/Cortex-M0+的IAP過程中,關於向量表寄存器討論。
Cortex-M3/M4架構下的IAP
Cortex-M3/M4架構下因爲具備可修改的向量表寄存器,中斷向量表重映射過程相對簡單很多,只需要對SCB->VTOR寄存器進行操作就可以,例如STM32CubeMX生成的STM32F10x系列代碼中,system_stm32f1xx.c文件裏有相關的寄存器操作:
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif
Cortex-M0架構下的IAP
因爲沒有SCB->VTOR寄存器,M0架構下的向量表重映射要麻煩點,原來的APP必須增加一段代碼,將中斷向量表從內部FLASH拷貝到SRAM後再執行REMAP到SRAM。
詳細STM32F0xxIAP過程參考這裏
Cortex-M0+架構區別
STM32G0系列屬於Cortex-M0+架構。
在STM32G0的system_stm32f1xx.c文件中找到了M3/M4中才有的SCB->VTOR寄存器操作
/**
* @brief Setup the microcontroller system.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
在文件stm32g071xx.h中,
#define __VTOR_PRESENT 1 /*!< Vector Table Register supported */
根據以上信息,作爲M0的plus版本,stm32g0在IAP過程中應該可以跟M3/M4一樣簡單。