rtthread stm32通用bootloader使用,在線升級


芯片型號:STM32F103VET6(100個引腳),主頻 72MHz,512KB FLASH ,64KB RAM

仿真調試:J-LINK

rtthread官方文檔:https://www.rt-thread.org/document/site/application-note/system/rtboot/an0028-rtboot/#ota

bootloader

制作bootloader

rtthread的stm32通用bootloader在線生成網址:http://iot.rt-thread.com/

預定bootloader分區大小64kb,app為192KB,download為128kb,剩余128kb另做他用

bootloader設置見下表:

芯片系列 ROM RAM
stm32f1 512kb 64kb
串口輸出引腳 支持SPI flash 恢復出廠按鍵引腳
PC12(UART5) 不支持
app分區 download分區 factory分區
0x08010000,192kb 0x08040000,128k 暫無
加密key 加密iv 壓縮
暫無 暫無 fastlz

log訂制生成網址:http://www.network-science.de/ascii/ https://www.jianshu.com/p/fca56d635091

使用bootloader

軟件:J-flash

下載地址: https://www.segger.com/downloads/jlink/

軟件操作:

  • 新建STM32F103VE工程,配置仿真器模式(JTAG/SWD),配置芯片型號,配置芯片地址
  • 打開需要下載的文件,選擇下載地址
  • Target-Connect連接電路板,擦除並燒寫程序
  • 重啟電路板,可以看到打印出bootloader信息

附:rtthread官方提供的bootloader不開源,如果需要自定義添加一些功能可以參考使用這位大神提供的bootloader

https://www.rt-thread.org/qa/thread-422812-1-1.html

APP

制作帶有ymodem_ota功能的APP

使能Ymodem OTA功能(RT-Thread online packages → IoT - internet of things → ota_downloader)

添加BSP_Flash驅動(Kconfig文件添加下述配置,並且在menuconfig里面使能)

    config BSP_USING_ON_CHIP_FLASH
        bool "Enable on-chip FLASH"
        default n

配置FAL分區

  • 在使能Ymodem OTA功能的時候會自動選中FAL組件
  • 將/packages/fal-latest/samples/porting 目錄下的 fal_cfg.h 復制到/board/ports目錄下,在/boart/SConscript文件中加入/board/ports目錄,如已存在此目錄和文件則忽略
  • 修改/board/ports/ fal_cfg.h文件,修改后內容如下
#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_

#include <rtthread.h>
#include <board.h>

#define RT_APP_PART_ADDR 0x08010000		//程序啟動運行地址

extern const struct fal_flash_dev stm32_onchip_flash;

/* flash device table */
#define FAL_FLASH_DEV_TABLE                                          \
{                                                                    \
    &stm32_onchip_flash,                                             \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG

/* partition table */
#define FAL_PART_TABLE                                                                      \
{                                                                                           \
    {FAL_PART_MAGIC_WROD,        "bl",   "onchip_flash",   				0, 64 * 1024, 0}, \
    {FAL_PART_MAGIC_WROD,        "app",   "onchip_flash",   64*1024, 192 * 1024, 0}, \
    {FAL_PART_MAGIC_WORD,   "download",   "onchip_flash",  256*1024, 128 * 1024, 0}, \
    {FAL_PART_MAGIC_WROD,      "param",   "onchip_flash",  496*1024,  16 * 1024, 0},  \
}
#endif /* FAL_PART_HAS_TABLE_CFG */
#endif /* _FAL_CFG_H_ */

修改APP的鏈接腳本和中斷向量跳轉地址(此處直接參照官方文檔步驟即可)

下載APP程序

打包APP固件並執行OTA

修改程序版本號,只編譯而不下載

打開 packages/ota_downloader-latest/ tools/ota_packager/rt_ota_packaging_tool.exe軟件,將編譯后的程序打包成可被升級的rtthread.rbl文件,注意壓縮算法和加密算法,如果在bootloader中使能了,需與bootloader中配置相同

在msh命令行中輸入ymodem_ota指令,並用Ymodem發送rtthread.rbl文件,此處推薦使用XShell軟件,傳輸完成后會自動重啟並升級,並可以看到程序版本號已經更改

附:如果需要更改傳輸文件的串口,更改ymodem_ota文件的如下處即可,此處我用的是UART2,故將rt_console_get_device()函數改成了serial2設備(serial2設備已在uart初始化時打開)。

    if (!rym_recv_on_device(&rctx, serial2, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                            ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))

參考鏈接:https://blog.csdn.net/ylzmm/article/details/104234099


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM