基于stm32的usb iap程序升级步骤

来源:互联网 发布:中原工学院软件类专业 编辑:程序博客网 时间:2024/05/17 07:58

作者:plauajoke

转自:http://blog.csdn.net/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文件即可.

[cpp] view plaincopy
  1. int main(void)  
  2. {  
  3.   DFU_Button_Config();//配置usb自动升级程序的按键标识  
  4.   
  5.   /* Check if the Key push-button on STM3210x-EVAL Board is pressed */  
  6.   if (DFU_Button_Read() != 0x00)  
  7.   { /* Test if user code is programmed starting from address 0x8003000 */  
  8.     if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)  
  9.     { /* Jump to user application */  
  10.   
  11.       JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);  
  12.       Jump_To_Application = (pFunction) JumpAddress;  
  13.       /* Initialize user application's Stack Pointer */  
  14.       __set_MSP(*(__IO uint32_t*) ApplicationAddress);  
  15.       Jump_To_Application();  
  16.     }  
  17.   } /* Otherwise enters DFU mode to allow user to program his application */  
  18.   
  19.   /* Enter DFU mode */  
  20.   DeviceState = STATE_dfuERROR;  
  21.   DeviceStatus[0] = STATUS_ERRFIRMWARE;  
  22.   DeviceStatus[4] = DeviceState;  
  23.   
  24.   Set_System();  
  25.   Set_USBClock();  
  26.   USB_Init();  
  27.   
  28.   /* Main loop */  
  29.   while (1)  
  30.   {  
  31.   }  
  32. }  


原创粉丝点击