当前位置:网站首页>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 .
边栏推荐
- Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
- Model analysis of establishment time and holding time
- XML配置文件
- Room cannot create an SQLite connection to verify the queries
- Date类中日期转成指定字符串出现的问题及解决方法
- notepad++正則錶達式替換字符串
- LeetCode 6005. The minimum operand to make an array an alternating array
- 如何制作自己的機器人
- [groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
- Promise
猜你喜欢

从 1.5 开始搭建一个微服务框架——调用链追踪 traceId

About the slmgr command

Date类中日期转成指定字符串出现的问题及解决方法

Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)

Notepad++ regular expression replacement string

State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.

Starting from 1.5, build a micro Service Framework - call chain tracking traceid

《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network

Arduino hexapod robot

Data analysis thinking analysis methods and business knowledge - analysis methods (III)
随机推荐
云导DNS和知识科普以及课堂笔记
2022-02-13 work record -- PHP parsing rich text
Leetcode:20220213 week race (less bugs, top 10% 555)
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
How spark gets columns in dataframe --column, $, column, apply
Set data real-time update during MDK debug
Classical concurrency problem: the dining problem of philosophers
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
OpenCV经典100题
How to solve the problems caused by the import process of ecology9.0
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
Common API classes and exception systems
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
数据分析思维分析方法和业务知识——分析方法(二)
For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
Curlpost PHP
【线上小工具】开发过程中会用到的线上小工具合集
[simple implementation of file IO]