1.设置STM32F103C8TX_FLASH.ld文件,将40行代码:
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = K
与stm32f103xb.h文件中573行的代码:
#define FLASH_BASE 0x08000000UL
FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 32K
与
#define FLASH_BASE 0x08008000UL
2. 开启中断向量表偏移,设置为跟FLASH偏移一致。若不修改,会无法正常执行中断。相关代码在system_stm32f1xx.c中,将97行至114行:
#if defined(USER_VECT_TAB_ADDRESS)
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE
#define VECT_TAB_OFFSET 0x00000000U
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE
#define VECT_TAB_OFFSET 0x00000000U
#endif
#endif
将注释消除,并将中断向量表偏移修改为与FLASH一致:
#define USER_VECT_TAB_ADDRESS
#if defined(USER_VECT_TAB_ADDRESS)
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE
#define VECT_TAB_OFFSET 0x00000000U
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE
#define VECT_TAB_OFFSET 0x00000000U
#endif
#endif