使用USART接口進(jìn)行STM32F0的在線(xiàn)升級(jí)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
1 前言
STSW-STM32116是ST官網(wǎng)基于標(biāo)準(zhǔn)庫(kù)的針對(duì)STM32F0的USART進(jìn)口IAP示例程序,下載鏈接:http://www.stmcu.org/document/detail/index/id-213120
工程原本是針對(duì)STM32F051,本文將介紹如何移植到STM32F070,并針對(duì)移植的過(guò)程中的問(wèn)題逐個(gè)處理。
2 KEIL下移植IAP程序一般分為兩個(gè),一個(gè)是IAP,一個(gè)是APP,IAP存放在內(nèi)置FLASH的0x8000000的起始位置,而APP則存放在離這個(gè)位置一定距離的位置,這個(gè)距離一定是大于或等于IAP本身所占空間大小,本例子為0x8003000。
下載資源后,打開(kāi)STM32F0xx_AN4065_FW_V1.0.0ProjectSTM32F0xx_IAP下的binary_template工程,這個(gè)就是APP工程,首先用KEIL打開(kāi),修改device為STM32F070,
并編譯,結(jié)果發(fā)現(xiàn)原始的公式是編譯不過(guò)的,如下錯(cuò)誤信息:
linking...
.STM320518_EVALSTM320518_EVAL.axf:Error:L6971E:system_stm32f0xx.o(.data)typeRWincompatiblewithmain.o(.ARM.__AT_0x20000000)typeZIinerRW_IRAM1.
Notenoughinformationtolistimagesymbols.
Finished:1information,0warningand1errormessages.
".STM320518_EVALSTM320518_EVAL.axf"-1Error(s),0Warning(s).
Targetnotcreated.
BuildTimeElapsed:00:00:08
從字面上判斷為編譯system_stm32f0xx.c文件生成的目標(biāo)文件system_stm32f0xx.o中的數(shù)據(jù)段(.data)內(nèi)的RW數(shù)據(jù)與main.o中的數(shù)據(jù)在地址0x20000000產(chǎn)生沖突。
仔細(xì)查看代碼,發(fā)現(xiàn)main函數(shù)之前這么一段:
#if(defined(__CC_ARM))
__IOuint32_tVectorTable[48]__attribute__((at(0x20000000)));
#elif(defined(__ICCARM__))
#pragmalocation=0x20000000
__no_init__IOuint32_tVectorTable[48];
#elifdefined(__GNUC__)
__IOuint32_tVectorTable[48]__attribute__((section(".RAMVectorTable")));
#elifdefined(__TASKING__)
__IOuint32_tVectorTable[48]__at(0x20000000);
#endif
可見(jiàn)代碼是要將中斷向量表VectorTable強(qiáng)制定義在內(nèi)存0x20000000上,但是此地址與system_stm32f0xx.c定義的全局變量位置有沖突。于是,需要修改避免沖突。中斷向量的地址是固定的,但其他全局變量的地址可以相應(yīng)地移動(dòng)下,并且APP的燒錄位置為0x8003000,如下圖:
再次編譯,錯(cuò)誤就會(huì)消失了。
另外需要將main函數(shù)內(nèi)前面幾行代碼做些修改:
intmain(void)
{
uint32_ti=0;
/*! thisisdonethroughSystemInit()functionwhichiscalledfromstartup file(startup_stm32f0xx.s)beforetobranchtoapplicationmain. ToreconfigurethedefaultsettingofSystemInit()function,referto system_stm32f0xx.cfile */ /*RelocatebysoftwarethevectortabletotheinternalSRAMat0x20000000***/ /*CopythevectortablefromtheFlash(mappedatthebaseoftheapplication loadaddress0x08003000)tothebaseaddressoftheSRAMat0x20000000.*/ for(i=0;i<48;i++) { VectorTable[i]=*(__IOuint32_t*)(APPLICATION_ADDRESS+(i<<2)); } /*EnabletheSYSCFGperipheralclock*/ //RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);//需要修改成這樣 /*RemapSRAMat0x00000000*/ SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM); /... } 打開(kāi)對(duì)應(yīng)的map文件,有如下內(nèi)容: GPIO_PIN0x08003470Data8stm320518_eval.o(.constdata) GPIO_CLK0x08003478Data16stm320518_eval.o(.constdata) BUTTON_PIN0x08003488Data14stm320518_eval.o(.constdata) BUTTON_CLK0x08003498Data28stm320518_eval.o(.constdata) BUTTON_EXTI_LINE0x080034b4Data14stm320518_eval.o(.constdata) BUTTON_PORT_SOURCE0x080034c2Data14stm320518_eval.o(.constdata) BUTTON_PIN_SOURCE0x080034d0Data14stm320518_eval.o(.constdata) BUTTON_IRQn0x080034deData14stm320518_eval.o(.constdata) COM_USART_CLK0x080034ecData4stm320518_eval.o(.constdata) COM_TX_PORT_CLK0x080034f0Data4stm320518_eval.o(.constdata) COM_RX_PORT_CLK0x080034f4Data4stm320518_eval.o(.constdata) COM_TX_PIN0x080034f8Data2stm320518_eval.o(.constdata) COM_RX_PIN0x080034faData2stm320518_eval.o(.constdata) COM_TX_PIN_SOURCE0x080034fcData2stm320518_eval.o(.constdata) COM_RX_PIN_SO