STM32WLE5之LoRa# 系列2:易智联LM401 评估板PingPong例程移植
前言
记录基于STM32CubeMX构建STM32WLE5模块的PingPong收发例程的过程。硬件平台为易智联蓝色的LM401 LoraWan评估板,对应的MCU型号为STM32WLE5CBU6。PingPong例程具有完整的数据收发过程,并且配置了ST的基本任务调度、软定时、队列和日志输出,是我们开发Lora私有协议的基础工程。
一、开发环境
STM32CubeIDE 是 ST 公司基于 Eclipse/CDT 框架和 GUN GCC 工具链制作的免费 IDE,并集成了STM32CubeMX。 可以实现 STM32 系列芯片的外围设备配置、代码生成、代码编辑、代码编译、在线调试,并且支持数百个 Eclipse 现有插件。
1、STM32CubeMX与STM32CubeIDE软件安装
官网下载stm32cubemx、stm32cubeide stm32cubemx:https://www.st.com/en/development-tools/stm32cubemx.html stm32cubeide:https://www.st.com/en/development-tools/stm32cubeide.html 基本上一路确定即可。 虽然STM32CubeIDE集成了STM32CubeMX,不如单独的灵活STM32CubeMX。单独安装STM32CubeMX一方面方便导入应用例程,另一方面方便生成MDK、IAR的工程。
2、下载STM32WL固件库
运行STM32CubeMX,HELP–>Manage embedded software packages如下图所示   等待下载安装完成,默认的安装位置为C:\Users\用户\STM32Cube\Repository\STM32Cube_FW_WL_V1.1.0
二、硬件平台
LM401-LoraWAN 评估板板载基于STM32WLE5CB的LM401模块。提供了基本的硬件电路,并提供了板载USB转COM以及LDO。USB连接电脑既可以实现供电、打印输出、输入操作。  PingPong例程中Log输出端口为板载的USB转串口PA2、PA3,软件配置成UART2 波特率115200-8-N-1。
三、 PingPong例程的简介
1、PingPong例程位置
\STM32Cube\Repository\STM32Cube_FW_WL_V1.1.0\Projects\NUCLEO-WL55JC\Applications\SubGHz_Phy\SubGHz_Phy_PingPong 目录如下: 
2、PingPong例程功能
PingPong例程是两个评估板之间的一个简单收发例程。默认情况下,评估板作为主设备发送一个“Ping”消息然后等待回复。第一个收到“Ping”消息的评估板将自己设置成从设备,并回复“Pong”消息。当主设备收到“Pong”消息之后继续发送“Ping”消息。这样就建立了一个持续的PingPong收发对。 这个例程能够使我们快速的了解STM32WLE5的收发过程,方便LoRa私有协议的开发。
3、附加功能
在移植PingPong例程过程中,STM32CubeMX配置时我们增加一路ADC的采集,以便后续做采集上报例程。
四、 PingPong例程的移植
1、创建STM32CubeMX工程;
a、打开STM32CubeMX工具; b、新建工程Start My Project From MCU;  c、选择STM32WL系列,选择STM32WLE5CB双击  d、File菜单–>Import Project导入PingPong例程并点击OK,用户名为自己实际目录 C:\Users\用户\STM32Cube\Repository\STM32Cube_FW_WL_V1.1.0\Projects\NUCLEO-WL55JC\Applications\SubGHz_Phy\SubGHz_Phy_PingPong\SubGHz_Phy_PingPong.ioc  中间会有些错误,是因为原例程平台STM32WL55JC为BGA封装,有些引脚STM32WLE5CB没有。 e、配置时钟输入,HSE 32MHz晶体振荡器,LSE 32.768K晶体振荡器  f、RTC开启Alarm A,软件定时使用  g、启RTC中断  h、配置ADC  i、SUBGHZ_PHY按如下配置   
k、时钟配置 RTC配置32.768Khz,HSE 32Mhz,MCU时钟48Mhz使用内部MSI RC时钟 
2、生产STM32CubeIDE工程;
a、Project Manager配置   b、执行GENERATE CODE生成工程
五、工程编译
1、工程配置
将BSP文件夹放入\PingPong_csdn\STM32CubeIDE\Drivers目录, 打开\PingPong_csdn\STM32CubeIDE目录,双击.project打开工程。 右击工程名称,选择Properties,将BSP目录加载到Inclue paths  修改platform.h,将原来的
#if defined(USE_BSP_DRIVER)
#include "stm32wlxx_LM401.h"
#include "stm32wlxx_LM401_radio.h"
#endif

2、工程编译
执行Build All。  编译成功,生成二进制代码 
六、小结
至此PingPong例程的CubeMX工程和CubeIDE工程移植完成,打开app_subghz_phy.c如下所示,只有一个基本框架。后续需要完善没有定义的射频功能函数和PingPong例程的应用程序。
static RadioEvents_t RadioEvents;
static void OnTxDone(void);
static void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t LoraSnr_FskCfo);
static void OnTxTimeout(void);
static void OnRxTimeout(void);
static void OnRxError(void);
void SubghzApp_Init(void)
{
RadioEvents.TxDone = OnTxDone;
RadioEvents.RxDone = OnRxDone;
RadioEvents.TxTimeout = OnTxTimeout;
RadioEvents.RxTimeout = OnRxTimeout;
RadioEvents.RxError = OnRxError;
Radio.Init(&RadioEvents);
}
static void OnTxDone(void)
{
}
static void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t LoraSnr_FskCfo)
{
}
static void OnTxTimeout(void)
{
}
static void OnRxTimeout(void)
{
}
static void OnRxError(void)
{
}
|