当前位置:网站首页>MCU realizes OTA online upgrade process through UART
MCU realizes OTA online upgrade process through UART
2022-07-06 00:41:00 【strongerHuang】
Focus on + Star sign public Number , Don't miss the highlights
Material source | The Internet
OTA Upgrading is nothing new , Now most IOT terminal devices , Basically have this function .
Today with AT32 As an example, let me share with you OTA The detailed process of upgrading .
summary
Over the air technology OTA(Over-the-Air Technology) Is the user's own program in the process of running User Flash Part of the area to burn , The purpose is to conveniently pass through the reserved communication port after the product is released , Update and upgrade the firmware program in the product . Usually achieve OTA When the function , That is to say, the user program updates itself during operation , You need to write two project codes when you design the firmware program , The first program is Bootloader Area , Second project procedure App The code is the real function code , Perform applications and upgrades . These two parts of project code are burned at the same time User Flash in .
chart 1. OTA Code execution process
In the process shown above ,MCU After reset , from 0x08000004 Address take out the address of reset interrupt vector , And jump to reset interrupt service program , After running the reset interrupt service program, jump to Bootloader Of main function , As shown in the figure ① Shown ; The execution of the Bootloader in the future (App The code is in the figure FLASH Gray bottom part App The starting address of the reset interrupt vector of the program is 0x08000004+N+M), Jump to App Reset vector table of program , Take out App The address of the reset interrupt vector of the program , And jump to execution App Program reset interrupt service program , Then jump to App programmatic main function , As shown in the figure ② and ③ Shown , Again main The function is a loop , And notice that at this point AT32 Of FLASH, In different places , There are two interrupt vector tables .
stay main During function execution , If CPU Get an interrupt request ,PC Pointer is still forced to jump to address 0x08000004 At the interrupt vector table , instead of App Interrupt vector table of program , As shown in the figure ④ Shown ; Program according to our set interrupt vector table offset , Jump to the new interrupt service program corresponding to the interrupt source , As shown in the figure ⑤ Shown ; After executing the interrupt service program , Program return main The function continues to run , As shown in the figure ⑥ Shown .
Through the analysis of the above two processes , We know OTA The program must meet two requirements :
1) App The procedure must be in Bootloader Some offset after the program is x The address begins .
2) Must be App The interrupt vector table of the program moves accordingly , The offset of the movement is x.
AT32 USART OTA Quick ways to use
Hardware resources
Is used in the document AT-START-AT32F403A Take the hardware condition of the experimental board as an example ,OTA demo The source code also includes AT32 Other models , Users only need to compile the corresponding model project and burn it in AT-START Just run the test board .
1) Indicator light LED2/LED3/LED4
2) USART1(PA9/PA10)
3) AT-START Experiment board
Software resources
1) tool_release
● IAP_Programmer.exe,PC machine tool, For demonstration OTA Upgrade process
2) source_code
● Bootloader,Bootloader Source program , function LED2 flashing
● App_led3_toggle,App1 Source program , function LED3 flashing
● App_led4_toggle,App2 Source program , function LED4 flashing
notes : The project is based on keil v5 establish , If the user needs to use on other compilation environments , Please refer to the corresponding BSP Catalog AT32F403A_407_Firmware_Library_V2.x.x\project\at_start_f403a\templates Various compilation environments in ( for example IAR6/7/8,keil 4/5,eclipse_gcc) Make corresponding modifications .
OTA Demo Use
This document describes two commonly used OTA application demo,template app and dual app, Later chapters will introduce .
1) open Bootloader Engineering source program , Select the corresponding MCU Model number target Download to the experimental board after compilation
2) open IAP_Programmer.exe
3) Choose the right serial port 、APP Download address and bin file , Click on Download download , Here's the picture
4) Observe LED2/3/4 flashing ,LED2 flashing -Bootloader Work ,LED3 flashing -App1 Work ,LED4 flashing -App2 Work
chart 2. IAP demo Upper computer
Template app OTA Program settings
Address distribution
chart 3. Flash Address assignment
notes :Bootloader The last sector of the region , Used to store and prevent errors in the upgrade process ( Power failure and other abnormal conditions ) Of flag, Users compile and modify Bootloader when , Make sure not to cover flag The address of .
Execute the process
OTA It is divided into Bootloader、App and Template In the third part of , Apply to App In the implementation of ,Template As new only App Temporary storage space for firmware data . The overall flow chart of program execution is as follows :
chart 4. Program execution flow
Bootloader project Set up
1) Keil Set up
chart 5. Bootloader project in address 1 stay Keil Set up
2) Bootloader Source program modification ota.h In file
chart 6. Bootloader project in address 2 Set... In the program
App project Set up
OTA demo Provides 2 individual App The program is for testing , All with address 2(0x800 4000) Is the starting address .App1 LED3 flashing ,App2 LED4 flashing . With App1 For example , The design steps are as follows :
1) Keil Engineering setup
chart 7. App project in address 2 stay Keil Set up
2) App1 Source program settings
chart 8. App project The vector table offset is set in the program
3) Compile the generated bin file
adopt User tab , Set call after compilation fromelf.exe, according to .axf File generation .bin file , be used for OTA to update . Through the above 3 A step , We can get one .bin Of APP Program , adopt Bootloader The program can be updated .
4) Turn on debug app code function
If you're designing App code In the process, we need to App project Conduct separate debugging , Please follow the steps below .
● To download Bootloader engineering
● Re commissioning App engineering
Dual app OTA And program settings
Address distribution
chart 9. Flash Address assignment
notes :Bootloader At the end of the zone 2 Sectors , To hold App Is it normal flag, Users compile and modify Bootloader when , Make sure not to cover flag The address of .
Execute the process
OTA It is divided into Bootloader、App1 and App2 In the third part of , Apply to App1 or App2 In the implementation of . The overall flow chart of program execution is as follows :
chart 10. Program execution flow
Bootloader project Set up
3) Keil Set up
chart 11. Bootloader project in address 1 stay Keil Set up
4) Bootloader Source program modification ota.h In file
chart 12. Bootloader project in address 2 Set... In the program
App project Set up
OTA demo Provides 2 individual App The program is for testing ,app_led3_toggle With 0x800 4000 Is the starting address ,app_led4_toggle With 0x8080000 Is the starting address .App1 LED3 flashing ,App2 LED4 flashing . With App1 For example , The design steps are as follows :
5) Keil Engineering setup
chart 13. App project in address 2 stay Keil Set up
6) App1 Source program settings
chart 14. App project The vector table offset is set in the program
7) Compile the generated bin file
adopt User tab , Set call after compilation fromelf.exe, according to .axf File generation .bin file , be used for OTA to update . Through the above 3 A step , We can get one .bin Of APP Program , adopt Bootloader The program can be updated .
8) Turn on debug App code function
If you're designing App code In the process, we need to App project Conduct separate debugging , Please follow the steps below .
● To download Bootloader engineering
● Re commissioning App engineering
Bootloader/App Serial communication protocol with upper computer
The program communicates with the upper computer , Receive firmware upgrade data , The communication protocols between the upper computer and the embedded end are as follows :
1) Upper computer communication protocol
chart 15. Upper computer communication protocol
2) Embedded end lower computer communication protocol
chart 16. Lower computer communication protocol
notes :ACK:0xCCDD
NACK:0xEEFF
Data:0x31+Addr+ data +chenksum(1byte)
Addr:4bytes, High in the former
Kbytes, Download data , Insufficient 2K Content filling 0xFF
Checksum:1byte,4bytes Of Addr+2KBytes The lower eight bits of the checksum of the data
------------ END ------------
● special column 《 Embedded tools 》
● special column 《 Embedded development 》
● special column 《Keil course 》
● Embedded column selection tutorial
Pay attention to the reply of the official account “ Add group ” Join the technical exchange group according to the rules , reply “1024” See more .
Click on “ Read the original ” See more sharing .
边栏推荐
- Spark获取DataFrame中列的方式--col,$,column,apply
- Codeforces round 804 (Div. 2) [competition record]
- 图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
- 时间戳的拓展及应用实例
- MCU通过UART实现OTA在线升级流程
- Browser reflow and redraw
- The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
- Spark DF adds a column
- 孤勇者
- Promise
猜你喜欢
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
KDD 2022 | 脑电AI助力癫痫疾病诊断
Model analysis of establishment time and holding time
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
Ffmpeg learning - core module
FFmpeg抓取RTSP图像进行图像分析
AtCoder Beginner Contest 258【比赛记录】
XML配置文件
Opencv classic 100 questions
随机推荐
Idea远程提交spark任务到yarn集群
How spark gets columns in dataframe --column, $, column, apply
Hudi of data Lake (2): Hudi compilation
About the slmgr command
synchronized 和 ReentrantLock
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
notepad++正则表达式替换字符串
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
curlpost-php
Solve the problem of reading Chinese garbled code in sqlserver connection database
Pointer - character pointer
Problems and solutions of converting date into specified string in date class
[designmode] Decorator Pattern
Comment faire votre propre robot
LeetCode 6004. Get operands of 0
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
Notepad + + regular expression replace String
Yolov5, pychar, Anaconda environment installation
LeetCode 斐波那契序列