2021-10-15 20:08:11 索炜达电子 819
项目编号:E1531
文件大小:964K
源码说明:带中文注释
开发环境:C编译器
简要概述:
花了四天时间才把IAP功能做好。其中也遇到许多的坑,这次把这次IAP功能实现过程遇到的坑把它分享出来。
一开始做iap的时候也是先从网上看别人的实现方法,其中就下载了一套别人的程序,不过主控芯片是STM32F103zv,就是不是我想要的那个型号,还有他的逻辑跟我的有点不一样。所以才走了那么多天的坑。
1、先移植别人的flash烧写代码跟运行APP应用程序的代码,基本各个版本大同小异。
2、然后实现自己的UART,实现串口接收程序(因为要通过串口接收APP应用固件)
3、然后接收到的固件烧写进flash
4、最后就是运行到APP应用程序了。
基本实现iap也是这几个步骤,但是就是不成功一开始。
然后就开始查找问题:
1、查看接收的固件对不对
2、通过keil编译器里的仿真可以看到flash的具体数值,判断memory里的数据是不是跟串口接收的数据一样的。
查找了之后自己感觉是对的(其实没有仔细验证),然后就开始跑到APP应用程序,每一次运行到APP程序时就进入了硬件错误中断HardFault_Handler();就是这个问题我查找了两天得不到解决。
最后实在没办法了才有查找接收的问题,发现接收处理是有问题的,因为芯片的SRAM是有限的,接收数组不可能开的太大,我的方法是开两个数组轮流接收固件,一个数组接收满了之后就先写进flash,另一个数组继续接收。因为固件我是通过串口助手发送给芯片的,所以串口助手一次性发完一个固件不间断。后面改了这个接收的问题,然后再去检查接收到的固件写进FLASH时是否是对的,这两部做好之后基本不会有什么大问题。
1、另一个需要注意的就是地址的偏移,Bootloader地址跟APP应用地址分开来。
2、进入APP应用程序之前需要清除中断,把一些GPIO,ADC之类的都关闭。
3、APP应用端要配置好中断偏移向量。
基本以上步骤检查好了,iap应用是没有问题的。
目录│文件列表:
└ 在线应用升级
├ APP
│ ├ CMSIS
│ │ │ core_cm3.c
│ │ │ core_cm3.h
│ │ │ stm32f10x.h
│ │ │ system_stm32f10x.c
│ │ │ system_stm32f10x.h
│ │ └ startup
│ │ │ startup_stm32f10x_hd.s
│ │ │ startup_stm32f10x_ld.s
│ │ └ startup_stm32f10x_md.s
│ ├ FWlib
│ │ ├ inc
│ │ │ │ misc.h
│ │ │ │ stm32f10x_adc.h
│ │ │ │ stm32f10x_bkp.h
│ │ │ │ stm32f10x_can.h
│ │ │ │ stm32f10x_crc.h
│ │ │ │ stm32f10x_dac.h
│ │ │ │ stm32f10x_dbgmcu.h
│ │ │ │ stm32f10x_dma.h
│ │ │ │ stm32f10x_exti.h
│ │ │ │ stm32f10x_flash.h
│ │ │ │ stm32f10x_fsmc.h
│ │ │ │ stm32f10x_gpio.h
│ │ │ │ stm32f10x_i2c.h
│ │ │ │ stm32f10x_iwdg.h
│ │ │ │ stm32f10x_pwr.h
│ │ │ │ stm32f10x_rcc.h
│ │ │ │ stm32f10x_rtc.h
│ │ │ │ stm32f10x_sdio.h
│ │ │ │ stm32f10x_spi.h
│ │ │ │ stm32f10x_tim.h
│ │ │ │ stm32f10x_usart.h
│ │ │ └ stm32f10x_wwdg.h
│ │ └ src
│ │ │ misc.c
│ │ │ stm32f10x_adc.c
│ │ │ stm32f10x_bkp.c
│ │ │ stm32f10x_can.c
│ │ │ stm32f10x_crc.c
│ │ │ stm32f10x_dac.c
│ │ │ stm32f10x_dbgmcu.c
│ │ │ stm32f10x_dma.c
│ │ │ stm32f10x_exti.c
│ │ │ stm32f10x_flash.c
│ │ │ stm32f10x_fsmc.c
│ │ │ stm32f10x_gpio.c
│ │ │ stm32f10x_i2c.c
│ │ │ stm32f10x_iwdg.c
│ │ │ stm32f10x_pwr.c
│ │ │ stm32f10x_rcc.c
│ │ │ stm32f10x_rtc.c
│ │ │ stm32f10x_sdio.c
│ │ │ stm32f10x_spi.c
│ │ │ stm32f10x_tim.c
│ │ │ stm32f10x_usart.c
│ │ └ stm32f10x_wwdg.c
│ ├ my_c
│ │ │ usart1.c
│ │ └ usart1.h
│ ├ Output
│ │ │ STM32-DEMO.bin
│ │ └ STM32-DEMO.hex
│ ├ souceinsight
│ │ │ c8t6_host.IAB
│ │ │ c8t6_host.IAD
│ │ │ c8t6_host.IMB
│ │ │ c8t6_host.IMD
│ │ │ c8t6_host.PFI
│ │ │ c8t6_host.PO
│ │ │ c8t6_host.PR
│ │ │ c8t6_host.PRI
│ │ └ c8t6_host.PS
│ └ USER
│ │ core_cm3._2i
│ │ EventRecorderStub.scvd
│ │ JLink Regs CM3.txt
│ │ JLinkSettings.ini
│ │ main.c
│ │ misc._2i
│ │ STM32-DEMO.fed
│ │ STM32-DEMO.l2p
│ │ STM32-DEMO.uvgui.lm
│ │ STM32-DEMO.uvgui.Ping
│ │ STM32-DEMO.uvguix.123
│ │ STM32-DEMO.uvguix.lm
│ │ STM32-DEMO.uvopt
│ │ STM32-DEMO.uvoptx
│ │ STM32-DEMO.uvprojx
│ │ stm32f10x_conf.h
│ │ stm32f10x_it.c
│ │ stm32f10x_it.h
│ │ SysTick.c
│ │ SysTick.h
│ └ DebugConfig
│ └ ADC-DEMO_STM32F103C8_1.0.0.dbgconf
└ IAP
├ CMSIS
│ │ core_cm3.c
│ │ core_cm3.h
│ │ stm32f10x.h
│ │ system_stm32f10x.c
│ │ system_stm32f10x.h
│ └ startup
│ │ startup_stm32f10x_hd.s
│ │ startup_stm32f10x_ld.s
│ └ startup_stm32f10x_md.s
├ FWlib
│ ├ inc
│ │ │ misc.h
│ │ │ stm32f10x_adc.h
│ │ │ stm32f10x_bkp.h
│ │ │ stm32f10x_can.h
│ │ │ stm32f10x_crc.h
│ │ │ stm32f10x_dac.h
│ │ │ stm32f10x_dbgmcu.h
│ │ │ stm32f10x_dma.h
│ │ │ stm32f10x_exti.h
│ │ │ stm32f10x_flash.h
│ │ │ stm32f10x_fsmc.h
│ │ │ stm32f10x_gpio.h
│ │ │ stm32f10x_i2c.h
│ │ │ stm32f10x_iwdg.h
│ │ │ stm32f10x_pwr.h
│ │ │ stm32f10x_rcc.h
│ │ │ stm32f10x_rtc.h
│ │ │ stm32f10x_sdio.h
│ │ │ stm32f10x_spi.h
│ │ │ stm32f10x_tim.h
│ │ │ stm32f10x_usart.h
│ │ └ stm32f10x_wwdg.h
│ └ src
│ │ misc.c
│ │ stm32f10x_adc.c
│ │ stm32f10x_bkp.c
│ │ stm32f10x_can.c
│ │ stm32f10x_crc.c
│ │ stm32f10x_dac.c
│ │ stm32f10x_dbgmcu.c
│ │ stm32f10x_dma.c
│ │ stm32f10x_exti.c
│ │ stm32f10x_flash.c
│ │ stm32f10x_fsmc.c
│ │ stm32f10x_gpio.c
│ │ stm32f10x_i2c.c
│ │ stm32f10x_iwdg.c
│ │ stm32f10x_pwr.c
│ │ stm32f10x_rcc.c
│ │ stm32f10x_rtc.c
│ │ stm32f10x_sdio.c
│ │ stm32f10x_spi.c
│ │ stm32f10x_tim.c
│ │ stm32f10x_usart.c
│ └ stm32f10x_wwdg.c
├ my_c
│ │ CAN_bus.c
│ │ CAN_bus.h
│ │ DataToPC.c
│ │ DataToPC.h
│ │ device_check.c
│ │ device_check.h
│ │ drv_AS5600.c
│ │ drv_AS5600.h
│ │ drv_spi.c
│ │ drv_spi.h
│ │ drv_TLE5012B.c
│ │ drv_TLE5012B.h
│ │ IIC.c
│ │ IIC.h
│ │ SPI_SSC.c
│ │ SPI_SSC.h
│ │ usart1.c
│ │ usart1.h
│ └ IAP
│ │ iap.c
│ │ iap.h
│ │ stmflash.c
│ └ stmflash.h
├ Output
│ └ STM32-DEMO.hex
├ souceinsight
│ │ c8t6_host.IAB
│ │ c8t6_host.IAD
│ │ c8t6_host.IMB
│ │ c8t6_host.IMD
│ │ c8t6_host.PFI
│ │ c8t6_host.PO
│ │ c8t6_host.PR
│ │ c8t6_host.PRI
│ └ c8t6_host.PS
├ USB
│ │ Queue.c
│ │ Queue.h
│ │ USB_Data.c
│ │ USB_Data.h
│ ├ Config
│ │ │ hw_config.c
│ │ │ hw_config.h
│ │ │ platform_config.h
│ │ │ usb_conf.h
│ │ │ usb_desc.c
│ │ │ usb_desc.h
│ │ │ usb_endp.c
│ │ │ usb_istr.c
│ │ │ usb_istr.h
│ │ │ usb_it.c
│ │ │ usb_prop.c
│ │ │ usb_prop.h
│ │ │ usb_pwr.c
│ │ └ usb_pwr.h
│ └ Core
│ │ usb_core.c
│ │ usb_core.h
│ │ usb_def.h
│ │ usb_init.c
│ │ usb_init.h
│ │ usb_int.c
│ │ usb_int.h
│ │ usb_lib.h
│ │ usb_mem.c
│ │ usb_mem.h
│ │ usb_regs.c
│ │ usb_regs.h
│ │ usb_sil.c
│ │ usb_sil.h
│ └ usb_type.h
└ USER
│ core_cm3._2i
│ EventRecorderStub.scvd
│ JLink Regs CM3.txt
│ JLinkSettings.ini
│ main.c
│ misc._2i
│ STM32-DEMO.fed
│ STM32-DEMO.l2p
│ STM32-DEMO.uvgui.lm
│ STM32-DEMO.uvgui.Ping
│ STM32-DEMO.uvguix.123
│ STM32-DEMO.uvguix.lm
│ STM32-DEMO.uvopt
│ STM32-DEMO.uvoptx
│ STM32-DEMO.uvprojx
│ stm32f10x_conf.h
│ stm32f10x_it.c
│ stm32f10x_it.h
│ SysTick.c
│ SysTick.h
└ DebugConfig
└ ADC-DEMO_STM32F103C8_1.0.0.dbgconf