news 2026/6/10 2:22:10

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/6/9 16:45:34

你还在用TestComplete?Open-AutoGLM这7个压倒性优势必须了解

第一章&#xff1a;Open-AutoGLM与TestComplete的行业定位对比在自动化测试与智能代码生成领域&#xff0c;Open-AutoGLM 与 TestComplete 代表了两种截然不同的技术路径与市场定位。前者聚焦于利用大语言模型实现测试脚本的自动生成与优化&#xff0c;后者则是传统企业级自动化…

作者头像 李华
网站建设 2026/6/9 20:09:00

从启动速度到元素识别:Open-AutoGLM与Selenium在手机端的7项关键指标对比

第一章&#xff1a;从启动速度到元素识别——Open-AutoGLM与Selenium的对比背景在自动化网页交互领域&#xff0c;选择合适的工具直接影响开发效率与执行性能。Open-AutoGLM 作为新兴的基于大语言模型驱动的自动化框架&#xff0c;强调自然语言指令到操作动作的直接映射&#x…

作者头像 李华
网站建设 2026/6/8 2:56:07

【AI法律科技新突破】:Open-AutoGLM在合同审核中的7个关键应用场景

第一章&#xff1a;Open-AutoGLM在合同审核中的核心价值Open-AutoGLM作为一款基于开源大语言模型的智能推理引擎&#xff0c;在法律科技领域展现出卓越的应用潜力&#xff0c;尤其在合同审核场景中&#xff0c;其核心价值体现在自动化理解、风险识别与合规建议生成等方面。该模…

作者头像 李华
网站建设 2026/6/9 11:08:27

【Java毕设全套源码+文档】基于springboot的单位考勤系统的管理设计与实现(丰富项目+远程调试+讲解+定制)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/6/9 21:36:43

【Java毕设源码分享】基于springboot+vue的的大学生志愿者管理系统的设计与实现(程序+文档+代码讲解+一条龙定制)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华