当前位置:首页 > 单片机 > 单片机
[导读]1 前言STSW-STM32116是ST官网基于标准库的针对STM32F0的USART进口IAP示例程序,下载链接:http://www.stmcu.org/document/detail/index/id-213120工程原本是针对STM32F051,本文将介绍如何移植到STM32F070,并针对移

1 前言

STSW-STM32116是ST官网基于标准库的针对STM32F0的USART进口IAP示例程序,下载链接:http://www.stmcu.org/document/detail/index/id-213120

工程原本是针对STM32F051,本文将介绍如何移植到STM32F070,并针对移植的过程中的问题逐个处理。

2 KEIL下移植

IAP程序一般分为两个,一个是IAP,一个是APP,IAP存放在内置FLASH的0x8000000的起始位置,而APP则存放在离这个位置一定距离的位置,这个距离一定是大于或等于IAP本身所占空间大小,本例子为0x8003000。

下载资源后,打开STM32F0xx_AN4065_FW_V1.0.0ProjectSTM32F0xx_IAP下的binary_template工程,这个就是APP工程,首先用KEIL打开,修改device为STM32F070,


并编译,结果发现原始的公式是编译不过的,如下错误信息:


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文件生成的目标文件system_stm32f0xx.o中的数据段(.data)内的RW数据与main.o中的数据在地址0x20000000产生冲突。

仔细查看代码,发现main函数之前这么一段:


#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

可见代码是要将中断向量表VectorTable强制定义在内存0x20000000上,但是此地址与system_stm32f0xx.c定义的全局变量位置有冲突。于是,需要修改避免冲突。中断向量的地址是固定的,但其他全局变量的地址可以相应地移动下,并且APP的烧录位置为0x8003000,如下图:

再次编译,错误就会消失了。

另外需要将main函数内前面几行代码做些修改:


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);

/...

}

打开对应的map文件,有如下内容:


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

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭