news 2026/4/23 17:13:52

OpenBLT 项目demo

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
OpenBLT 项目demo

在上一篇的OpenBLT学习记录后,我们完成了编译。实际上要离正常运行还需要再次的修改。

BootLoader在上个博客中,完成了编译,实际上没有调整对外设的设置,还需要启动相关的外设。

一、Boot的参数设置以及代码添加

我们查看通讯初始化的代码,可以发现其Bootloader的升级通讯外设有多种。

/************************************************************************************//** ** \brief Initializes the communication module including the hardware needed for ** the communication. ** \return none ** ****************************************************************************************/ void ComInit(void) { /* initialize the XCP communication protocol */ XcpInit(); #if (BOOT_COM_CAN_ENABLE > 0) /* initialize the CAN controller */ CanInit(); /* set it as active */ comActiveInterface = COM_IF_CAN; #endif #if (BOOT_COM_RS232_ENABLE > 0) /* initialize the RS232 interface */ Rs232Init(); /* set it as active */ comActiveInterface = COM_IF_RS232; #endif #if (BOOT_COM_MBRTU_ENABLE > 0) /* initialize the Modbus RTU interface */ MbRtuInit(); /* set it as active */ comActiveInterface = COM_IF_MBRTU; #endif #if (BOOT_COM_USB_ENABLE > 0) /* initialize the USB interface */ UsbInit(); /* set it as active */ comActiveInterface = COM_IF_USB; #endif #if (BOOT_COM_NET_ENABLE > 0) #if (BOOT_COM_NET_DEFERRED_INIT_ENABLE == 0) /* initialize the TCP/IP interface */ NetInit(); /* set it as active */ comActiveInterface = COM_IF_NET; #endif #endif } /*** end of ComInit ***/

我们初步选择MbRtu,modbus协议来作为升级的协议。

同时要注意我们开启了uart的外设,还需要使能他的中断。

/* USER CODE BEGIN USART1_Init 2 */ LL_USART_EnableIT_RXNE(USART1); /* USER CODE END USART1_Init 2 */

根据 官网的教程手册 ,我们添加以下的代码进入程序。manual:modbus_rtu_demo [OpenBLT Bootloader]https://www.feaser.com/openblt/doku.php?id=manual:modbus_rtu_demo代码如下:

/** \brief Enable/disable RS485 transport layer. */ #define BOOT_COM_MBRTU_ENABLE (1) /** \brief Configure the desired communication speed. */ #define BOOT_COM_MBRTU_BAUDRATE (57600) /** \brief Configure the desired number of stopbits (1 or 2). */ #define BOOT_COM_MBRTU_STOPBITS (1) /** \brief Configure the desired parity (0 for none, 1 for odd, 2 for even). */ #define BOOT_COM_MBRTU_PARITY (2) /** \brief Configure number of bytes in the target->host data packet. */ #define BOOT_COM_MBRTU_TX_MAX_DATA (129) /** \brief Configure number of bytes in the host->target data packet. */ #define BOOT_COM_MBRTU_RX_MAX_DATA (129) /** \brief Select the desired UART peripheral as a zero based index. */ #define BOOT_COM_MBRTU_CHANNEL_INDEX (1) /** \brief The 8-bit node identifier of this node. Should be between 1 and 247. */ #define BOOT_COM_MBRTU_NODE_ID (1) //用于定义MBRTU的初始化以及地址参数等信息。 /************************************************************************************//** ** \brief Controls the state of the DE/NRE GPIO pin on an RS485 transceiver. ** \param enable When enable is BLT_TRUE, the pin should go logic high to enable the ** driver output. When enable is BLT_FALSE, the pin should go logic low to ** enable the receiver input. ** \return none. ** ****************************************************************************************/ void MbRtuDriverOutputControlHook(blt_bool enable) { /* Should the driver output be enabled (transmit)? */ if (enable == BLT_TRUE) { /* TODO If needed, set DE and NRE pins to high to enable the driver output. */ } /* The receiver output should be enabled (receive). */ else { /* TODO If needed, set DE and NRE pins to low to enable the receiver input. */ } } /*** end of MbRtuDriverOutputControlHook ***/ //驱动输出控制钩子函数

根据自己的需要,更改初始化的宏定义。就完成了Boot程序的编写。

二、App的代码添加与程序设置

我们在设计OTA的时候,要先规划boot程序和app程序的分区地址定义。

我们初步设置boot占用的空间为0x4000,于是从地址为0x0800 0000开始到0x0800 3FFF为boot的存储地址,app则是从地址为0x0800 4000开始。

我们要同步设置boot和app的keil工程设置如图:

boot

app

同时修改 app的system.c文件中的中断向量表地址的偏移地址和我们的项目设置的启始地址一致。

#if 1 #define USER_VECT_TAB_ADDRESS #endif #if defined(USER_VECT_TAB_ADDRESS) /*!< Uncomment the following line if you need to relocate your vector Table in Sram else user remap will be done in Flash. */ /* #define VECT_TAB_SRAM */ #if defined(VECT_TAB_SRAM) #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. This value must be a multiple of 0x200. */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ #else #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. This value must be a multiple of 0x200. */ #define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ #endif /* VECT_TAB_SRAM */ #endif /* USER_VECT_TAB_ADDRESS */

再修改boot程序中的flash_layout.c中的存储地址分配数组:

static const tFlashSector flashLayout[] = { /* space is reserved for a bootloader configuration with all supported communication * interfaces enabled. when for example only UART is needed, than the space required * for the bootloader can be made a lot smaller here. */ /* { 0x08000000, 0x02000 }, flash sector 0 - reserved for bootloader */ //{ 0x08002000, 0x02000 }, /* flash sector 1 - 8kb */ { 0x08004000, 0x02000 }, /* flash sector 2 - 8kb */ { 0x08006000, 0x02000 }, /* flash sector 3 - 8kb */ { 0x08008000, 0x02000 }, /* flash sector 4 - 8kb */ { 0x0800A000, 0x02000 }, /* flash sector 5 - 8kb */ { 0x0800C000, 0x02000 }, /* flash sector 6 - 8kb */ { 0x0800E000, 0x02000 }, /* flash sector 7 - 8kb */ { 0x08010000, 0x02000 }, /* flash sector 8 - 8kb */ { 0x08012000, 0x02000 }, /* flash sector 9 - 8kb */ { 0x08014000, 0x02000 }, /* flash sector 10 - 8kb */ { 0x08016000, 0x02000 }, /* flash sector 11 - 8kb */ { 0x08018000, 0x02000 }, /* flash sector 12 - 8kb */ { 0x0801A000, 0x02000 }, /* flash sector 13 - 8kb */ { 0x0801C000, 0x02000 }, /* flash sector 14 - 8kb */ { 0x0801E000, 0x02000 }, /* flash sector 15 - 8kb */ };

就完成所有的操作,接下来就可以使用Host的上位机程序来烧录app的srec程序了。

要注意,app的代码调用这个函数即可,但是要注意该任务的运行频率,建议放在中断中,或者最高优先级。

BootComCheckActivationRequest();

三、总结

其实这些设置无非就是开启外设和设置地址分配的相关代码。总体来说,这个开源的OpenBLT还是很方便的,一致性也高。

个人的成功demo可见资源下载。仅供参考。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 11:35:48

自动化工具怎么选,Open-AutoGLM和WinAutomation哪款更适合你?

第一章&#xff1a;自动化工具性能对比概述在现代软件开发与运维实践中&#xff0c;自动化工具已成为提升效率、保障系统稳定性的核心组件。面对种类繁多的自动化解决方案&#xff0c;如何科学评估其性能表现成为技术选型的关键环节。本章聚焦于主流自动化工具在执行效率、资源…

作者头像 李华
网站建设 2026/4/23 11:29:43

MQ快速入门

目录 1.同步调用 2.异步调用 3.MQ技术选型 4.Java客户端 4.1简单发送 引入依赖​ 配置MQ服务端 发送消息 接收消息 4.2 WorkQueue 4.3 Fanouot交换机 4.4 Direct交换机 4.5 Topic交换机 4.6 声明队列和交换机 基于bean 基于注解 4.7 信息转换器 5.业务改造 1…

作者头像 李华
网站建设 2026/4/22 22:49:21

Open-AutoGLM与WinAutomation性能对决:5大关键指标全面解析

第一章&#xff1a;Open-AutoGLM与WinAutomation性能对比概述在自动化工具选型过程中&#xff0c;Open-AutoGLM 与 WinAutomation 是两类典型代表&#xff1a;前者基于开源大语言模型驱动&#xff0c;强调自然语言理解与跨平台脚本生成能力&#xff1b;后者作为商业级 Windows …

作者头像 李华
网站建设 2026/4/22 21:19:10

从零开始学昇腾Ascend C算子开发-第三篇:算子开发基础

3.1 算子开发流程 3.1.1 算子需求分析 注&#xff1a;运行前看好自己的版本&#xff1a; 明确算子功能 开发算子之前&#xff0c;先得搞清楚这个算子要干什么。比如要做一个Add算子&#xff0c;那就是两个输入相加得到输出。听起来简单&#xff0c;但实际要考虑的东西还挺…

作者头像 李华
网站建设 2026/4/23 14:41:27

Open-AutoGLM能否替代律师?:3分钟看懂智能合同审核的精准度与边界

第一章&#xff1a;Open-AutoGLM能否替代律师&#xff1f;&#xff1a;3分钟看懂智能合同审核的精准度与边界人工智能在法律科技领域的应用正迅速推进&#xff0c;Open-AutoGLM作为基于大规模语言模型的智能合同审核工具&#xff0c;展现出惊人的文本理解与条款识别能力。它能在…

作者头像 李华
网站建设 2026/4/23 14:49:45

学术迷航中的智能灯塔:书匠策AI如何重塑本科硕士论文写作范式

在学术探索的浩瀚星空中&#xff0c;每一位即将完成本科或硕士学业的学生&#xff0c;都像是手持罗盘的航海家&#xff0c;面临着论文写作这片未知海域的挑战。选题迷茫、文献梳理耗时、逻辑构建混乱、语言表述不专业……这些问题如同暗礁&#xff0c;随时可能让学术航船偏离方…

作者头像 李华