news 2026/4/4 8:57:43

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/1 21:11:21

【报价准确率提升80%】:Open-AutoGLM模型调优与数据闭环构建秘诀

第一章&#xff1a;Open-AutoGLM报价单生成系统概述Open-AutoGLM 是一个基于大语言模型的自动化报价单生成系统&#xff0c;专为提升企业销售流程效率而设计。该系统融合自然语言理解、结构化数据处理与模板引擎技术&#xff0c;能够根据用户输入的客户需求自动生成格式规范、内…

作者头像 李华
网站建设 2026/3/31 11:48:27

表单自动化效率提升80%,Open-AutoGLM真的比UiPath更简单吗?

第一章&#xff1a;表单自动化效率提升80%的行业背景与技术动因随着企业数字化转型加速&#xff0c;大量重复性表单处理任务成为制约运营效率的关键瓶颈。在金融、医疗、电商等行业中&#xff0c;每日需处理成千上万份客户申请、订单录入和审批流程&#xff0c;传统人工操作不仅…

作者头像 李华
网站建设 2026/4/3 3:02:43

自动化测试框架选型难题(Open-AutoGLM与Katalon Studio适配性全面解析)

第一章&#xff1a;自动化测试框架选型的核心挑战在构建高效、可维护的自动化测试体系时&#xff0c;框架选型是决定项目成败的关键环节。不同的项目背景、技术栈和团队能力都会对框架的选择产生深远影响&#xff0c;导致决策过程充满挑战。技术栈兼容性 自动化测试框架必须与被…

作者头像 李华
网站建设 2026/4/4 7:34:20

揭秘Open-AutoGLM与UiPath操作复杂度:5大维度实测对比,结果令人震惊

第一章&#xff1a;揭秘Open-AutoGLM与UiPath操作复杂度的背景与意义在自动化技术飞速发展的今天&#xff0c;企业对流程自动化的依赖日益加深。Open-AutoGLM 作为一种新兴的开源大语言模型驱动自动化框架&#xff0c;结合 UiPath 这类成熟的机器人流程自动化&#xff08;RPA&a…

作者头像 李华
网站建设 2026/4/3 11:33:08

【Open-AutoGLM vs UiPath深度对决】:谁才是低代码自动化王者?

第一章&#xff1a;Open-AutoGLM 与 UiPath 操作复杂度对比在自动化技术快速发展的背景下&#xff0c;Open-AutoGLM 和 UiPath 作为两类代表性的自动化工具&#xff0c;分别体现了基于大语言模型的智能自动化与传统流程驱动型 RPA 的设计哲学差异。两者在操作复杂度、开发门槛和…

作者头像 李华
网站建设 2026/3/31 0:28:52

学术写作新次元:书匠策AI——本科硕士论文的隐形智囊团

在学术的浩瀚宇宙中&#xff0c;每一位即将完成本科或硕士学业的学生&#xff0c;都像是手握星图的探险家&#xff0c;渴望在论文写作的星辰大海中&#xff0c;找到属于自己的那颗璀璨之星。然而&#xff0c;选题迷茫、文献梳理耗时、逻辑构建混乱、语言表达不专业……这些问题…

作者头像 李华