当前位置:网站首页>MCU firmware packaging Script Software
MCU firmware packaging Script Software
2022-07-01 02:41:00 【Big orange madness】
1 Preface
To develop the MCU After software , Usually generated hex Documents or bin file , Used for firmware burning or upgrading , If used for product development , When it comes to the firmware version , Beginners usually use firmware file renaming to distinguish versions .
If you need to write the version to the firmware , It needs to be realized in a certain way , There are many ways to achieve it .
2 Introduce
The following describes a script software that automatically packs firmware , It mainly realizes the following functions :
- be based on Windows Single chip microcomputer of the platform MCU Firmware script packaging tool
- Support hex File clipping and hex Consolidation of documents
- It can be for hex Add firmware version information 、Git Commit Branch and submit records, etc
- Name according to version information hex The firmware , Generative bin Documents, etc.
- The above can be passed ini Configuration file setting parameter pair hex File operation
3 Implementation steps
Let's say MDK + STM32 Development as an example .
3.1 __attribute__ Mechanism
First of all, let's get to know __attribute__ Mechanism , It's a compiler directive , Tell the compiler about the declared features , Or let the compiler do more error checking and advanced optimization .
GUN C Can be used in __attribute__() To the variable 、 Functions and types set various properties , and __attribute__ Of section Option to change the properties of the segment ;
among __attribute__((section("section_name"))) Is used to put the defined function or data variable into the specified name ”section_name” In the paragraph .
Whether it's GNU still ARM The compiler , All support
__attribute__The specified compilation properties .
open keil Of options…, Uncheck... As shown in the following figure , And then click “Edit…”.

Automatic pop-up “*.sct” file ( Compile first and then operate ), The following is Keil in STM32 Link file for , The compiler will base on the linked file and __attribute__ Of section Options ( You can add a segment by yourself , Assign address and size ) The address of the assignment function and data variable in the program firmware .
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00010000 { ; load region size_region
ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x00005000 { ; RW data
.ANY (+RW +ZI)
}
} I won't give you too much introduction here , The methods described below do not need to be modified “*.sct” file , Or adopt __attribute__ Of section Options , But in section You can specify the position in the options .
__attribute__ ((section(".ARM.__at_0x08000020")))3.2 Code implementation
1. Define a structure , It defines some software version related information
typedef struct
{
char szVersion[32]; // Software version
char szBuildDate[32]; // Program compilation date
char szBuildTime[32]; // Program compilation time
char szCommitId[32]; // git commit id
}AppInfo_t;2. adopt __attribute__ Define a read-only structure variable ( Read only purpose : Prevent program changes 、 save RAM), Assign initial value to ( among __DATE_ and __TIME__ yes C Built in macros in languages , They are the current compilation date and compilation time ).
const AppInfo_t __attribute__ ((section(".ARM.__at_0x08002000"))) sg_tAppInfo =
{
"STM32_TEST",
__DATE__,
__TIME__,
""
};notes :STM32 The starting address of the code is from 0x08000000 At the beginning , And store interrupt vector table information , Therefore, when selecting the program address, you must avoid , Not too far back , Otherwise, it's generated bin The file exceeds the actual code firmware size , In the realization of bin File upgrade will take too long .
3. Print it out through the serial port
int main(void)
{
FML_USART_Init();
USART_Printf(0, "Version : %s\r\n", sg_tAppInfo.szVersion);
USART_Printf(0, "buildTime: %s\r\n", sg_tAppInfo.szBuildDate);
USART_Printf(0, "buildTime: %s\r\n", sg_tAppInfo.szBuildTime);
USART_Printf(0, "commitId: %s\r\n\r\n", sg_tAppInfo.szCommitId);
while(1);
}4. Submit git After compiling , You can see git commit id value ( adopt git commit You can quickly locate when the source code was compiled )

3.3 Firmware packaging
Download firmware packaging script , According to the configuration settings , double-click bat You can complete the firmware packaging , Then click download to verify .
Need to pass through J-LINK Kit or ST-Link The tool opens the generated firmware for burning ( adopt Keil It is useless to compile and download directly , What I use here is ST-Link Tools ).

4 Profile contents
Here are the options in the configuration file
; The paths in this paper can be absolute paths or relative paths ( Relative to firmware packaging bat In terms of documents )
; Version information Flash Initial address Reserved size Prefix string
[version]
addr=0x08002000
size=32
strPrefix=
; Git Information Flash Initial address Reserved size
[git_commit]
addr=0x08002060
size=32
[boot_file]
; Boot Hex File path File name
hexFilePath=.\
hexFileName=test_boot
[file]
; Hex File path File name
hexFilePath=.\
hexFileName=test
; Crop start address Keep the size
hexFileAddr=0x08000000
hexFileSize=0xFFFF
; The output path of the package file
outputPath=.\output
[option]
; Whether to merge boot The firmware
isMergeBootHexFile=0
; Whether to generate Bin file
isGenerateBin=1
; Crop or not Hex file , according to (hexFileAddr hexFileSize)
isCropHexFile=1
; Whether to add Git Commit Information
isAddGitCommit=0
; Whether to clear temporary files after successful packaging
isClearTmpFile=15 Download address
MCU Firmware packaging script
https://gitee.com/const-zpc/mcu-pack-script
边栏推荐
- 522. Longest special sequence II
- 股票开账户如何优惠开户?还有,在线开户安全么?
- 鼠标悬停效果九
- 在国内如何买港股的股?用什么平台安全一些?
- 园区运营效率提升,小程序容器技术加速应用平台化管理
- 鼠标悬停效果八
- Open source basic software companies, looking for you to create the future together (api7.ai)
- Pytoch -- foundation refers to the north_ II. What high school students can understand [back propagation and gradient descent]
- 鼠标悬停效果十
- robots.txt限制搜索引擎收录
猜你喜欢
![[2022] Jiangxi postgraduate mathematical modeling scheme and code](/img/f4/86b0dc2bd49c3a54c1e0538b31d458.png)
[2022] Jiangxi postgraduate mathematical modeling scheme and code

Sampling Area Lights

Dell server restart Idrac method

详解数据治理知识体系

Dell服务器重启iDRAC方法

如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?

What is PMP?

js中的图片预加载

Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
![[JS] [Nuggets] get people who are not followers](/img/cc/bc897cf3dc1dc57227dbcd8983cd06.png)
[JS] [Nuggets] get people who are not followers
随机推荐
Clickhouse eliminates the gap caused by group by
Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?
The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
Lenovo x86 server restart management controller (xclarity controller) or TSM method
鼠标悬停效果三
SAP ALV summary is inconsistent with exported excel summary data
CentOS installs multiple versions of PHP and switches
现在开户有优惠吗?另外,手机开户安全么?
7_ Openresty installation
查看 jvm 参数
旷世轻量化网络ShuffulNetV2学习笔记
Pytoch -- foundation refers to the north_ II. What high school students can understand [back propagation and gradient descent]
nacos配置中心使用教程
鼠标悬停效果九
[graduation season · advanced technology Er] - summary from graduation to work
Dell服务器重启iDRAC方法
5款主流智能音箱入门款测评:苹果小米华为天猫小度,谁的表现更胜一筹?
Mnasnet learning notes
[PR # 5 A] two way running (state pressure DP)
Optimal transport Series 1