STM32WLE5 series #4 stm32wle5ccu6 porting LoRaWAN_AT_Slave project
Original from: STM32WLE5系列#4 stm32wle5ccu6移植LoRaWAN_AT_Slave工程_stm32wle5 微型-CSDN博客
Overview
The official only provides related application demos of STM32WL55JC and STM32WL55JC1. Due to the encapsulation, we cannot directly use the relevant programs and need to be transplanted before they can be used. This time we transplant the LoRaWAN_AT_Slave communication demo, configure LoRaWAN parameters, access the network, and send and receive data through AT commands.
Project transplantation
1. Open STM32CubeMX and select start My projext from MCU to start the project
2. Select STM32WLE5CCU6 at the MCU/MPU
3. Import the pingpong routine in File->import project,select the import project as C”\Users\用户\STM32Cube\Repository\STM32CuBE_FW_WLV1.2.0\Projects\NUCLEO-WL55JC\Applications\LoRaWAN\LoRaWAN_AT_Slave\LoRaWAN_AT_Slave.ioc
There will be some errors after importing, because the original WL55JC is a BGA package with more pins, while the stm32wle5ccu6 does not.
4. Set the project name and storage path in Project Manager->Project. Toolchain/IDE is set to MDK-ARM; Code Generator is set to Copy all used libraries into the project folder.
5. Clock input configuration, both HSE and LSE are configured as Crystal/Ceramic Resonator
6. RTC turns on Alarm A and enables interrupts
7. Configure the clock tree and configure the clocks of RTC and LPURAT to be LSE.
8. Enable low-power serial port
9. LORAWAN settings are as follows
Enable CN470 in LoRaWAN middleware, set the lorawan version to 1.0.3, and select BSP in the board level setting.
10. Set non-static DEVEUI to be configured externally, and configure the parameters DEVEUI, APPEUI, APPKEY, and NWKEY required for OTAA to access the network (note: DEVEUI must be unique in the same server)
11. Close Probes Lines in Platform Settings
12. Platform Setting setting as below
13. Click GENERATE CODE to generate code, open the keil project and then compile. The following error will be reported because we did not add the BSP package.
10. Copy the BSP package in the downloaded software package C:\Users\Users\STM32Cube\Repository\STM32Cube_FW_WL_V1.2.0\Drivers to the current project. Then add the file and directory index in keil.
11. Then compile the project, 0 error 0 warning
Application transplantation
1. First, the board-level file settings in the BSP package are consistent with those in Chapter 2: Transplanting Pingpong Communication. For convenience, you can also directly use the modified BSP package in the previous section.
Get Tara Qiu’s stories in your inbox
Join Medium for free to get updates from this writer.
2. After the project was transplanted, lora_app.c changed mainly and the application part became empty. So we need to make relevant modifications to lora_app.c in the corresponding software package
void LoRaWAN_Init(void)
{
/* USER CODE BEGIN LoRaWAN_Init_LV */
uint32_t feature_version = 0UL;
/* USER CODE END LoRaWAN_Init_LV */
CMD_Init(CmdProcessNotify);
/* USER CODE BEGIN LoRaWAN_Init_1 */
//添加打印入网参数和版本信息
/* Get LoRaWAN APP version*/
APP_LOG(TS_OFF, VLEVEL_M, "APPLICATION_VERSION: V%X.%X.%X\r\n",
(uint8_t)(APP_VERSION_MAIN),
(uint8_t)(APP_VERSION_SUB1),
(uint8_t)(APP_VERSION_SUB2));
/* Get MW LoRaWAN info */
APP_LOG(TS_OFF, VLEVEL_M, "MW_LORAWAN_VERSION: V%X.%X.%X\r\n",
(uint8_t)(LORAWAN_VERSION_MAIN),
(uint8_t)(LORAWAN_VERSION_SUB1),
(uint8_t)(LORAWAN_VERSION_SUB2));
/* Get MW SubGhz_Phy info */
APP_LOG(TS_OFF, VLEVEL_M, "MW_RADIO_VERSION: V%X.%X.%X\r\n",
(uint8_t)(SUBGHZ_PHY_VERSION_MAIN),
(uint8_t)(SUBGHZ_PHY_VERSION_SUB1),
(uint8_t)(SUBGHZ_PHY_VERSION_SUB2));
/* Get LoRaWAN Link Layer info */
LmHandlerGetVersion(LORAMAC_HANDLER_L2_VERSION, &feature_version);
APP_LOG(TS_OFF, VLEVEL_M, "L2_SPEC_VERSION: V%X.%X.%X\r\n",
(uint8_t)(feature_version >> 24),
(uint8_t)(feature_version >> 16),
(uint8_t)(feature_version >> 8));
/* Get LoRaWAN Regional Parameters info */
LmHandlerGetVersion(LORAMAC_HANDLER_REGION_VERSION, &feature_version);
APP_LOG(TS_OFF, VLEVEL_M, "RP_SPEC_VERSION: V%X-%X.%X.%X\r\n",
(uint8_t)(feature_version >> 24),
(uint8_t)(feature_version >> 16),
(uint8_t)(feature_version >> 8),
(uint8_t)(feature_version));
/* USER CODE END LoRaWAN_Init_1 */
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LmHandlerProcess), UTIL_SEQ_RFU, LmHandlerProcess);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_Vcom), UTIL_SEQ_RFU, CMD_Process);
/* Init Info table used by LmHandler*/
LoraInfo_Init();
/* Init the Lora Stack*/
LmHandlerInit(&LmHandlerCallbacks, APP_VERSION);
LmHandlerConfigure(&LmHandlerParams);
/* USER CODE BEGIN LoRaWAN_Init_Last */
/* USER CODE END LoRaWAN_Init_Last */
}
.
.
.
补充回调函数
static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
{
/* USER CODE BEGIN OnRxData_1 */
if ((appData != NULL) || (params != NULL))
{
AT_event_receive(appData, params);
}
/* USER CODE END OnRxData_1 */
}
/* USER CODE BEGIN PrFD_LedEvents */
/* USER CODE END PrFD_LedEvents */
static void OnTxData(LmHandlerTxParams_t *params)
{
/* USER CODE BEGIN OnTxData_1 */
if ((params != NULL))
{
AT_event_confirm(params);
}
/* USER CODE END OnTxData_1 */
}
static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
{
/* USER CODE BEGIN OnJoinRequest_1 */
if (joinParams != NULL)
{
AT_event_join(joinParams);
}
/* USER CODE END OnJoinRequest_1 */
}
static void OnBeaconStatusChange(LmHandlerBeaconParams_t *params)
{
/* USER CODE BEGIN OnBeaconStatusChange_1 */
if (params != NULL)
{
AT_event_Beacon(params);
}
/* USER CODE END OnBeaconStatusChange_1 */
}
static void OnClassChange(DeviceClass_t deviceClass)
{
/* USER CODE BEGIN OnClassChange_1 */
AT_event_ClassUpdate(deviceClass);
/* USER CODE END OnClassChange_1 */
}
3. Modify the number of network access channels of CN470. Because the official default is to open all 96 channels, and we generally use 8-channel gateways, we change the number of channels to 8 and use the first set of channels of CN470.
//#define CN470_MAX_NB_CHANNELS 96
#define CN470_MAX_NB_CHANNELS 8Result verification
We use TTN as the lorawan server. First, register the gateway to go online, and then register the node according to the configured parameters.
After burning the program, use AT commands to configure parameters and perform operations such as network access and data sending and receiving.
//入网
AT+DEUI=70:B3:D5:7E:D0:05:54:89
AT+APPEUI=00:00:00:00:00:00:00:00
AT+APPKEY=10:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01
AT+NWKKEY=10:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01
AT+JOIN=1Successfully accessed the network after sending the above command.
//发送数据
//发送端口号为8,confirmed类型,数据为112233445566778899AABBCCDDEE1122
AT+SEND=8:1:112233445566778899AABBCCDDEE1122The server receives network access and data
More information contact : 北世安-CSDN博客










