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

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)
  {
  }
}


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值