主控:STM32F407VET6
环境:RT-Thread Studio ,STM32CubeMX, ENV,RT-Thread v.4.0.2
概述:通过Studio创建芯片对应的内核工程,添加软件包,修改配置文件,在线生成对应的RT-Boot,实现OTA固件升级
一. 创建RT-Thread内核工程
根据自己的芯片和外设创建RTT内核工程
进入工程后,查看RT-Thread Setting ,可以发现串口功能已经配置好,
修改main函数,看看系统是否能跑起来
????编译,下载到板子,STM32F4系列默认下载地址0x08000000
(LOG_D打印日志,可以i打印指定内容并输出文件位置与系统时钟的信息)
二、制作Bootloader
官方在线制作网址:http://iot.rt-thread.com/#/addBootloader
制作好之后将RT-Boot.bin烧写到片内flash的首地址0x0800 0000
三、制作app固件
本小节介绍如何使用 stm32 系列的 BSP 制作一个可以用于 OTA 升级的,包含 OTA 下载器功能 app 固件。
制作该 app 固件有如下三个步骤:
- 为 BSP 添加下载器功能,下载需要的软件包并修改 FAL 分区表
- 修改 stm32 BSP 中断向量表跳转地址
- 修改 BSP 链接脚本
1、添加下载器功能
本小节介绍如何将下载器功能添加到 app 固件中。
添加该功能需要使用 env 工具
下载 ota_downloader 软件包,选中 Ymodem 功能与下载调试功能,保存后,fal分区功能自动添加到软件包
也可以通过studio的软件包图形界面配置软件包
2. 配置 FAL 分区
本小节将讲述如何初始化 FAL 组件,并修改 FAL 分区表。
本次制作的 app 固件将附带下载器功能,下载器会将固件下载到 download 分区
download 分区的地址为 0x8020000,而 app 分区的地址为 0x8040000。
3. 初始化 FAL
由于 FAL 组件会被 ota_downloader 软件包自动选中,因此直接添加 FAL 组件的初始化代码即可。
1) 在main函数中添加fal初始化代码,添加版本打印,修改中断向量表的跳转基地址
1 /* 2 * Copyright (c) 2006-2019, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2019-09-09 RT-Thread first version 9 */ 10 11 #include <rtthread.h> 12 #include <board.h> 13 #include <rtdevice.h> 14 15 16 #define DBG_TAG "main" 17 #define DBG_LVL DBG_LOG 18 #include <rtdbg.h> 19 20 #include "fal.h" 21 22 #define APP_VERSION "1.0.0" 23 24 /* PLEASE DEFINE the LED0 pin for your board, such as: PA5 */ 25 #define LED0_PIN GET_PIN(E, 3) 26 27 int main(void) 28 { 29 int count = 1; 30 /* set LED0 pin mode to output */ 31 rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT); 32 33 fal_init(); 34 35 rt_kprintf("The current version of APP firmware is %s\n", APP_VERSION); 36 37 while (count++) 38 { 39 /* set LED0 pin level to high or low */ 40 rt_pin_write(LED0_PIN, count % 2); 41 //LOG_D("Hello RT-Thread!"); 42 rt_thread_mdelay(1000); 43 } 44 45 return RT_EOK; 46 } 47 48 /** 49 * Function ota_app_vtor_reconfig 50 * Description Set Vector Table base location to the start addr of app(RT_APP_PART_ADDR). 51 */ 52 static int ota_app_vtor_reconfig(void) 53 { 54 #define NVIC_VTOR_MASK 0x3FFFFF80 55 /* Set the Vector Table base location by user application firmware definition */ 56 SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK; 57 58 return 0; 59 } 60 INIT_BOARD_EXPORT(ota_app_vtor_reconfig);