作者:plauajoke
转自:http://blog.youkuaiyun.com/plauajoke/article/details/8270281
usb自动更新程序IAP(in application programming)DFU(develepment firemeware upgrate).整个芯片有512k的片内flash,用户程序下载在里面运行,flash的地址是0x8000000,大小为0x80000,usb自动更新程序首先下载0x8000000——0x80002FFF,总大小为12K,用户程序下载到0x80003000,大小为0x7D000(500K),usb自动更新代码为如下,如果按键按下,就进入DFU模式,否则就启动用户代码。
用户程序除了在void NVIC_Configuration(void)
{
/* Set the Vector Table base location at 0x3000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x3000);
}
里面修改,还要修改编译的地址,修改为0x80003000,大小为0x7d000,
iap程序编译地址为0x80000000,结束为0x80002fff,大小为0x3000,这样分别烧写用户程序和usb iap程序,启动即可。需要pc主机安装st公司的dfuse_demo_v3.0,其中会有dfu的驱动程序,插上usb后手动安装驱动程序C:\Program Files\STMicroelectronics\Software\DfuSe\Driver\x86\文件就好了运行DFU filemanager将编译生成的.hex文件转换成.dfu,然后运行DFUse demonstration upgrade生成的.dfu文件即可.
- int main(void)
- {
- DFU_Button_Config();//配置usb自动升级程序的按键标识
- /* Check if the Key push-button on STM3210x-EVAL Board is pressed */
- if (DFU_Button_Read() != 0x00)
- { /* Test if user code is programmed starting from address 0x8003000 */
- if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
- { /* Jump to user application */
- JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
- Jump_To_Application = (pFunction) JumpAddress;
- /* Initialize user application's Stack Pointer */
- __set_MSP(*(__IO uint32_t*) ApplicationAddress);
- Jump_To_Application();
- }
- } /* Otherwise enters DFU mode to allow user to program his application */
- /* Enter DFU mode */
- DeviceState = STATE_dfuERROR;
- DeviceStatus[0] = STATUS_ERRFIRMWARE;
- DeviceStatus[4] = DeviceState;
- Set_System();
- Set_USBClock();
- USB_Init();
- /* Main loop */
- while (1)
- {
- }
- }