Skip to main content
FBrin.1
Associate II
February 21, 2021
Question

STM32WL LoRa Code

  • February 21, 2021
  • 1 reply
  • 1596 views

Hi,

I am new to STM32.

I am trying to implement LoRa Receiver and Transmitter code in STM32WL. I have tried to modify the Rx and Tx code using the Ping-Pong application code (subghz_phy_app.c) .

I have added my Transmitter code below, can you please review the code and suggest changes.

Also, how can I change the time duration of messages sent by the transmitter end node?

Rgds,

Frank

/* Includes ------------------------------------------------------------------*/
#include "platform.h"
#include "stm32_timer.h"
#include "sys_app.h"
#include "subghz_phy_app.h"
#include "radio.h"
#include "stm32_seq.h"
#include "utilities_def.h"
#include "app_version.h"
 
uint16_t BufferSize = BUFFER_SIZE;
uint8_t Buffer[BUFFER_SIZE];
 
int8_t RssiValue = 0;
int8_t SnrValue = 0;
 
/* Led Timers objects*/
static UTIL_TIMER_Object_t timerLed;
 
/* Radio events function pointer */
static RadioEvents_t RadioEvents;
 
/* Private function prototypes -----------------------------------------------*/
/*!
 * @brief Function executed on when led timer elapses
 * @param LED context
 * @retval none
 */
static void OnledEvent(void *context);
 
/*!
 * @brief Function to be executed on Radio Tx Done event
 * @param none
 * @retval none
 */
static void OnTxDone(void);
 
/*!
 * @brief Function executed on Radio Tx Timeout event
 * @param none
 * @retval none
 */
static void OnTxTimeout(void);
 
/* Exported functions ---------------------------------------------------------*/
void SubghzApp_Init(void)
{
 
 /* Led Timers*/
 UTIL_TIMER_Create(&timerLed, 0xFFFFFFFFU, UTIL_TIMER_ONESHOT, OnledEvent, NULL);
 UTIL_TIMER_SetPeriod(&timerLed, LED_PERIOD_MS);
 
 UTIL_TIMER_Start(&timerLed);
 
 /* Radio initialization */
 RadioEvents.TxDone = OnTxDone;
 RadioEvents.TxTimeout = OnTxTimeout;
 
 Radio.Init(&RadioEvents);
 
 Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
 true, 0, 0, LORA_IQ_INVERSION_ON, TX_TIMEOUT_VALUE);
 
 Radio.SetMaxPayloadLength(MODEM_LORA, BUFFER_SIZE);
 
 Radio.SetChannel(RF_FREQUENCY);
 APP_LOG(TS_ON, VLEVEL_L, "Tx start\n\r");
 Radio.Send(Buffer, BufferSize);
 
#if defined(USE_BSP_DRIVER)
 BSP_LED_Init(LED_GREEN);
 BSP_LED_Init(LED_RED);
#elif defined(MX_BOARD_PSEUDODRIVER)
 SYS_LED_Init(SYS_LED_GREEN);
 SYS_LED_Init(SYS_LED_RED);
#else
#error user to provide its board code or to call his board driver functions
#endif /* USE_BSP_DRIVER || MX_NUCLEO_WL55JC*/
 
}
 
/* Private functions ---------------------------------------------------------*/
 
static void OnTxDone(void)
{
 /* USER CODE BEGIN OnTxDone_1 */
 
 /* USER CODE END OnTxDone_1 */
 APP_LOG(TS_ON, VLEVEL_L, "OnTxDone\n\r");
 
 Radio.Sleep();
 UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_PingPong_Process), CFG_SEQ_Prio_0);
 /* USER CODE BEGIN OnTxDone_2 */
 
 /* USER CODE END OnTxDone_2 */
}
 
static void OnTxTimeout(void)
{
 /* USER CODE BEGIN OnTxTimeout_1 */
 
 /* USER CODE END OnTxTimeout_1 */
 APP_LOG(TS_ON, VLEVEL_L, "OnTxTimeout\n\r");
 
 Radio.Sleep();
 State = TX_TIMEOUT;
 UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_PingPong_Process), CFG_SEQ_Prio_0);
 /* USER CODE BEGIN OnTxTimeout_2 */
 
 /* USER CODE END OnTxTimeout_2 */
}
 
static void OnledEvent(void *context)
{
 /* USER CODE BEGIN OnledEvent_1 */
 
 /* USER CODE END OnledEvent_1 */
#if defined(USE_BSP_DRIVER)
 BSP_LED_Toggle(LED_GREEN) ;
 BSP_LED_Toggle(LED_RED) ;
#elif defined(MX_BOARD_PSEUDODRIVER)
 SYS_LED_Toggle(SYS_LED_RED) ;
 SYS_LED_Toggle(SYS_LED_GREEN) ;
#endif /* USE_BSP_DRIVER || MX_BOARD_PSEUDODRIVER */
 
 UTIL_TIMER_Start(&timerLed);
 /* USER CODE BEGIN OnledEvent_2 */
 
 /* USER CODE END OnledEvent_2 */
}
 
/* USER CODE BEGIN PrFD */
 
/* USER CODE END PrFD */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

This topic has been closed for replies.

1 reply

YBOUV.1
ST Employee
May 17, 2021

Hi,

1/you need to register the task in SubghzApp_Init function

  /*register task to to be run in while(1) after Radio IT*/

  UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_SubGHz_Phy_App_Process), UTIL_SEQ_RFU, PingPong_Process);

2/

then you should implement the function PingPong_Process with what you want to do next. (start a timer to trigger the next Radio.Send?)

Best Regards,

SSaya.1
Associate III
August 16, 2021

hello, is it possible to send UART data by modifying the ping pong payload?