当前位置:网站首页>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 .
边栏推荐
- 详细页返回列表保留原来滚动条所在位置
- 剖面测量之提取剖面数据
- Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
- Notepad++ regular expression replacement string
- The relationship between FPGA internal hardware structure and code
- 小程序容器可以发挥的价值
- curlpost-php
- LeetCode 8. String conversion integer (ATOI)
- Keepalive component cache does not take effect
- [Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
猜你喜欢
AtCoder Beginner Contest 254【VP记录】
FFmpeg抓取RTSP图像进行图像分析
OS i/o devices and device controllers
Leetcode:20220213 week race (less bugs, top 10% 555)
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
免费的聊天机器人API
Calculate sha256 value of data or file based on crypto++
Leetcode 450 deleting nodes in a binary search tree
随机推荐
Opencv classic 100 questions
Search (DFS and BFS)
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
STM32 key chattering elimination - entry state machine thinking
Common API classes and exception systems
Arduino六足机器人
Pointer pointer array, array pointer
KDD 2022 | 脑电AI助力癫痫疾病诊断
LeetCode 6006. Take out the least number of magic beans
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
[groovy] compile time metaprogramming (compile time method interception | find the method to be intercepted in the myasttransformation visit method)
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
Spark SQL UDF function
devkit入门
curlpost-php
Hudi of data Lake (2): Hudi compilation
Yolov5、Pycharm、Anaconda环境安装
CTF daily question day44 rot