当前位置: 首页 > news >正文

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可见资源下载。仅供参考。

http://www.cnnetsun.cn/news/174042.html

相关文章:

  • 【测试工程师必看】Open-AutoGLM与Katalon Studio适配差异的5大关键点
  • 【自动化平台选型避坑指南】:Open-AutoGLM与Power Automate 6大场景实测对比
  • Vue3+TypeScript+Element-Plus确认对话框ElMessageBox.confirm
  • 企业流程自动化怎么选,Open-AutoGLM和Power Automate到底差在哪?
  • 为什么99%的人没发挥Open-AutoGLM全部潜力?,解锁隐藏的动态权重调优功能
  • 批量打印神器,太流批了
  • 【Java毕设全套源码+文档】基于springboot的大学生兼职平台设计与实现(丰富项目+远程调试+讲解+定制)
  • 从零开始学昇腾Ascend C算子开发-第四篇:常用算子实现
  • 学术迷航中的“智能罗盘”:书匠策AI如何重塑本科硕士论文写作新范式
  • 为什么90%的企业都在用Open-AutoGLM做客户信息归档?真相曝光
  • Open-AutoGLM实时跟进系统搭建全流程(含源码级避坑指南)
  • 【AI驱动销售革命】:Open-AutoGLM如何实现线索筛选效率提升10倍
  • 告别加班写年报!Open-AutoGLM自动写作系统实测效果曝光(附对比数据)
  • Open-AutoGLM数据同步实战指南(从配置到监控全链路拆解)
  • 【Open-AutoGLM邮件分类实战】:手把手教你构建企业级智能筛选系统
  • Java全栈工程师面试实录:从基础到实战的深度探讨
  • Open-AutoGLM核心原理深度解析:NLP+知识图谱如何重塑周报流程?
  • 【独家披露】某头部科技公司如何用Open-AutoGLM实现周报零人工干预
  • 揭秘Open-AutoGLM自动回邮系统:如何3步实现企业级智能响应?
  • Open-AutoGLM月报统计避坑指南:资深工程师总结的7大常见错误
  • 5步搞定Open-AutoGLM周报集成,让每周汇报不再加班到凌晨
  • Open-AutoGLM现场将发布什么?10位顶尖专家透露的惊人线索
  • 为什么顶尖团队都在用Open-AutoGLM做月报?背后的数据逻辑首次公开
  • Open-AutoGLM工作流监控实战指南(实时可视化监控体系搭建全解析)
  • 别让“小眼镜”挡住清晰世界!儿童近视防控,家长必知的科学指南
  • AI赋能会议管理,Open-AutoGLM预约系统深度解析
  • 打开Simulink工程时总得先泡杯咖啡——电池模型搭建这事儿,手动调参太费劲。不过这次咱们直接用二阶RC等效电路模型开搞,毕竟既要考虑极化效应又要平衡计算量
  • 读懂HikariCP一百行代码,多线程就是个孙子
  • SMP语言基础知识-应用系统,开发的痛点,开发者的痛点
  • 【Open-AutoGLM收益监控终极方案】:5分钟搭建实时收益提醒系统