L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
lora_app.c File Reference

Application of the LRWAN Middleware. More...

#include "platform.h"
#include "sys_app.h"
#include "lora_app.h"
#include "stm32_seq.h"
#include "stm32_timer.h"
#include "utilities_def.h"
#include "app_version.h"
#include "lorawan_version.h"
#include "subghz_phy_version.h"
#include "lora_info.h"
#include "LmHandler.h"
#include "adc_if.h"
#include "CayenneLpp.h"
#include "sys_sensors.h"
#include "flash_if.h"
#include "secure-element.h"
#include "mylora_process.h"
#include "mysensors_base.h"
Include dependency graph for lora_app.c:

Go to the source code of this file.

Macros

#define LED_PERIOD_TIME   500
#define JOIN_TIME   2000
#define LORAWAN_NVM_BASE_ADDRESS   ((void *)0x0803F000UL)
 LoRaWAN NVM Flash address.

Enumerations

enum  TxEventType_t { TX_ON_TIMER , TX_ON_EVENT }
 LoRa State Machine states. More...

Functions

static void SendTxData (void)
 LoRa End Node send request.
static void OnTxTimerEvent (void *context)
 TX timer callback function.
static void OnJoinRequest (LmHandlerJoinParams_t *joinParams)
 join event callback function
static void OnTxData (LmHandlerTxParams_t *params)
 callback when LoRaWAN application has sent a frame
static void OnRxData (LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
 callback when LoRaWAN application has received a frame
static void OnBeaconStatusChange (LmHandlerBeaconParams_t *params)
 callback when LoRaWAN Beacon status is updated
static void OnSysTimeUpdate (void)
 callback when system time has been updated
static void OnClassChange (DeviceClass_t deviceClass)
 callback when LoRaWAN application Class is changed
static void StoreContext (void)
 LoRa store context in Non Volatile Memory.
static void StopJoin (void)
 stop current LoRa execution to switch into non default Activation mode
static void OnStopJoinTimerEvent (void *context)
 Join switch timer callback function.
static void OnNvmDataChange (LmHandlerNvmContextStates_t state)
 Notifies the upper layer that the NVM context has changed.
static void OnStoreContextRequest (void *nvm, uint32_t nvm_size)
 Store the NVM Data context to the Flash.
static void OnRestoreContextRequest (void *nvm, uint32_t nvm_size)
 Restore the NVM Data context from the Flash.
static void OnMacProcessNotify (void)
static void OnTxPeriodicityChanged (uint32_t periodicity)
 Change the periodicity of the uplink frames.
static void OnTxFrameCtrlChanged (LmHandlerMsgTypes_t isTxConfirmed)
 Change the confirmation control of the uplink frames.
static void OnPingSlotPeriodicityChanged (uint8_t pingSlotPeriodicity)
 Change the periodicity of the ping slot frames.
static void OnSystemReset (void)
 Will be called to reset the system.
void systemParams_SetLoRaWanParams ()
 
  • set the lorawan parameters from _systemParams before start of loraWan

void LoRaWAN_Init (void)
 Init Lora Application.

Variables

static ActivationType_t ActivationType = ACTIVATION_TYPE_OTAA
 LoRaWAN default activation type.
static bool ForceRejoin = false
 LoRaWAN force rejoin even if the NVM context is restored.
static LmHandlerCallbacks_t LmHandlerCallbacks
 LoRaWAN handler Callbacks.
static LmHandlerParams_t LmHandlerParams
 LoRaWAN handler parameters.
static TxEventType_t EventType = TX_ON_EVENT
 Type of Event to generate application Tx.
static UTIL_TIMER_Object_t TxTimer
 Timer to handle the application Tx.
static UTIL_TIMER_Time_t TxPeriodicity = 10000
 Tx Timer period.
static UTIL_TIMER_Object_t StopJoinTimer
 Join Timer period.

Detailed Description

Application of the LRWAN Middleware.

Author
MCD Application Team
Attention

Copyright (c) 2026 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

Definition in file lora_app.c.

Macro Definition Documentation

◆ JOIN_TIME

#define JOIN_TIME   2000

Join switch period value of the timer in ms

Definition at line 82 of file lora_app.c.

Referenced by LoRaWAN_Init().

◆ LED_PERIOD_TIME

#define LED_PERIOD_TIME   500

LEDs period value of the timer in ms

Definition at line 77 of file lora_app.c.

◆ LORAWAN_NVM_BASE_ADDRESS

#define LORAWAN_NVM_BASE_ADDRESS   ((void *)0x0803F000UL)

LoRaWAN NVM Flash address.

Note
last 2 sector of a 128kBytes device

Definition at line 91 of file lora_app.c.

Referenced by OnRestoreContextRequest(), and OnStoreContextRequest().

Enumeration Type Documentation

◆ TxEventType_t

LoRa State Machine states.

Enumerator
TX_ON_TIMER 

Appdata Transmission issue based on timer every TxDutyCycleTime.

TX_ON_EVENT 

Appdata Transmission external event plugged on OnSendEvent( ).

Definition at line 54 of file lora_app.c.

Function Documentation

◆ LoRaWAN_Init()

void LoRaWAN_Init ( void )

Init Lora Application.

< [31:24] main version

< main byte shift

< [23:16] sub1 version

< sub1 byte shift

< [15:8] sub2 version

< sub2 byte shift

< [7:0] release candidate

< release candidate byte shift

Definition at line 310 of file lora_app.c.

References ActivationType, APP_LOG, APP_VERSION, CFG_SEQ_Task_LmHandlerProcess, CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent, CFG_SEQ_Task_LoRaStopJoinEvent, CFG_SEQ_Task_LoRaStoreContextEvent, EventType, ForceRejoin, JOIN_TIME, LmHandlerCallbacks, LmHandlerParams, LoraInfo_Init(), OnStopJoinTimerEvent(), OnTxTimerEvent(), SendTxData(), StopJoin(), StopJoinTimer, StoreContext(), systemParams_getAppDevEUI(), systemParams_getAppEUI(), systemParams_getAppKey(), TS_OFF, TX_ON_TIMER, TxPeriodicity, TxTimer, and VLEVEL_M.

Referenced by main(), and MX_LoRaWAN_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnBeaconStatusChange()

void OnBeaconStatusChange ( LmHandlerBeaconParams_t * params)
static

callback when LoRaWAN Beacon status is updated

Parameters
paramsstatus of Last Beacon

Definition at line 453 of file lora_app.c.

◆ OnClassChange()

void OnClassChange ( DeviceClass_t deviceClass)
static

callback when LoRaWAN application Class is changed

Parameters
deviceClassnew class

Definition at line 466 of file lora_app.c.

◆ OnJoinRequest()

void OnJoinRequest ( LmHandlerJoinParams_t * joinParams)
static

join event callback function

Parameters
joinParamsstatus of join

Definition at line 442 of file lora_app.c.

References OnLoRaWanConnected().

Here is the call graph for this function:

◆ OnMacProcessNotify()

void OnMacProcessNotify ( void )
static

Will be called each time a Radio IRQ is handled by the MAC layer

Definition at line 472 of file lora_app.c.

References CFG_SEQ_Prio_0, and CFG_SEQ_Task_LmHandlerProcess.

◆ OnNvmDataChange()

void OnNvmDataChange ( LmHandlerNvmContextStates_t state)
static

Notifies the upper layer that the NVM context has changed.

Parameters
stateIndicates if we are storing (true) or restoring (false) the NVM context

Definition at line 613 of file lora_app.c.

References APP_LOG, TS_OFF, and VLEVEL_M.

◆ OnPingSlotPeriodicityChanged()

void OnPingSlotPeriodicityChanged ( uint8_t pingSlotPeriodicity)
static

Change the periodicity of the ping slot frames.

Parameters
pingSlotPeriodicityping slot frames period in ms
Note
Compliance test protocol callbacks

Definition at line 517 of file lora_app.c.

References LmHandlerParams.

◆ OnRestoreContextRequest()

void OnRestoreContextRequest ( void * nvm,
uint32_t nvm_size )
static

Restore the NVM Data context from the Flash.

Parameters
nvmptr on nvm structure
nvm_sizenumber of data bytes which were restored

Definition at line 643 of file lora_app.c.

References FLASH_IF_Read(), and LORAWAN_NVM_BASE_ADDRESS.

Here is the call graph for this function:

◆ OnRxData()

void OnRxData ( LmHandlerAppData_t * appData,
LmHandlerRxParams_t * params )
static

callback when LoRaWAN application has received a frame

Parameters
appDatadata received in the last Rx
paramsstatus of last Rx

Definition at line 401 of file lora_app.c.

References OnLoRaWANRxData().

Here is the call graph for this function:

◆ OnStopJoinTimerEvent()

void OnStopJoinTimerEvent ( void * context)
static

Join switch timer callback function.

Parameters
contextptr of Join switch context

Definition at line 577 of file lora_app.c.

References ActivationType, CFG_SEQ_Prio_0, CFG_SEQ_Task_LoRaStopJoinEvent, and LORAWAN_DEFAULT_ACTIVATION_TYPE.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ OnStoreContextRequest()

void OnStoreContextRequest ( void * nvm,
uint32_t nvm_size )
static

Store the NVM Data context to the Flash.

Parameters
nvmptr on nvm structure
nvm_sizenumber of data bytes which were stored

Definition at line 631 of file lora_app.c.

References FLASH_IF_Write(), and LORAWAN_NVM_BASE_ADDRESS.

Here is the call graph for this function:

◆ OnSystemReset()

void OnSystemReset ( void )
static

Will be called to reset the system.

Note
Compliance test protocol callbacks

Definition at line 528 of file lora_app.c.

◆ OnSysTimeUpdate()

void OnSysTimeUpdate ( void )
static

callback when system time has been updated

Definition at line 459 of file lora_app.c.

References OnTimeSynchronized().

Here is the call graph for this function:

◆ OnTxData()

void OnTxData ( LmHandlerTxParams_t * params)
static

callback when LoRaWAN application has sent a frame

tx event callback function

Parameters
paramsstatus of last Tx

Definition at line 434 of file lora_app.c.

References OnLoRaWANTxData().

Here is the call graph for this function:

◆ OnTxFrameCtrlChanged()

void OnTxFrameCtrlChanged ( LmHandlerMsgTypes_t isTxConfirmed)
static

Change the confirmation control of the uplink frames.

Parameters
isTxConfirmedIndicates if the uplink requires an acknowledgement
Note
Compliance test protocol callbacks

Definition at line 506 of file lora_app.c.

References LmHandlerParams.

◆ OnTxPeriodicityChanged()

void OnTxPeriodicityChanged ( uint32_t periodicity)
static

Change the periodicity of the uplink frames.

Parameters
periodicityuplink frames period in ms
Note
Compliance test protocol callbacks

Definition at line 484 of file lora_app.c.

References APP_TX_DUTYCYCLE, TxPeriodicity, and TxTimer.

◆ OnTxTimerEvent()

void OnTxTimerEvent ( void * context)
static

TX timer callback function.

Parameters
contextptr of timer context

Definition at line 416 of file lora_app.c.

References CFG_SEQ_Prio_0, CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent, and TxTimer.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ SendTxData()

void SendTxData ( void )
static

LoRa End Node send request.

Definition at line 409 of file lora_app.c.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ StopJoin()

void StopJoin ( void )
static

stop current LoRa execution to switch into non default Activation mode

Definition at line 542 of file lora_app.c.

References ActivationType, APP_LOG, LmHandlerParams, LORAWAN_DEFAULT_ACTIVATION_TYPE, StopJoinTimer, TS_OFF, TxTimer, and VLEVEL_M.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ StoreContext()

void StoreContext ( void )
static

LoRa store context in Non Volatile Memory.

Definition at line 591 of file lora_app.c.

References APP_LOG, TS_OFF, and VLEVEL_M.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ systemParams_SetLoRaWanParams()

void systemParams_SetLoRaWanParams ( )

  • set the lorawan parameters from _systemParams before start of loraWan

Definition at line 300 of file lora_app.c.

References _systemParams, and LmHandlerParams.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ ActivationType

ActivationType_t ActivationType = ACTIVATION_TYPE_OTAA
static

LoRaWAN default activation type.

Definition at line 228 of file lora_app.c.

Referenced by LoRaWAN_Init(), OnStopJoinTimerEvent(), and StopJoin().

◆ EventType

TxEventType_t EventType = TX_ON_EVENT
static

Type of Event to generate application Tx.

Definition at line 278 of file lora_app.c.

Referenced by LoRaWAN_Init().

◆ ForceRejoin

bool ForceRejoin = false
static

LoRaWAN force rejoin even if the NVM context is restored.

Definition at line 233 of file lora_app.c.

Referenced by LoRaWAN_Init().

◆ LmHandlerCallbacks

LmHandlerCallbacks_t LmHandlerCallbacks
static
Initial value:
=
{
.GetBatteryLevel = GetBatteryLevel,
.GetTemperature = GetTemperatureLevel,
.GetUniqueId = GetUniqueId,
.GetDevAddr = GetDevAddr,
.OnRestoreContextRequest = OnRestoreContextRequest,
.OnStoreContextRequest = OnStoreContextRequest,
.OnMacProcess = OnMacProcessNotify,
.OnNvmDataChange = OnNvmDataChange,
.OnJoinRequest = OnJoinRequest,
.OnTxData = OnTxData,
.OnRxData = OnRxData,
.OnBeaconStatusChange = OnBeaconStatusChange,
.OnSysTimeUpdate = OnSysTimeUpdate,
.OnClassChange = OnClassChange,
.OnTxPeriodicityChanged = OnTxPeriodicityChanged,
.OnTxFrameCtrlChanged = OnTxFrameCtrlChanged,
.OnPingSlotPeriodicityChanged = OnPingSlotPeriodicityChanged,
.OnSystemReset = OnSystemReset,
}
static void OnSysTimeUpdate(void)
callback when system time has been updated
Definition lora_app.c:459
static void OnTxData(LmHandlerTxParams_t *params)
callback when LoRaWAN application has sent a frame
Definition lora_app.c:434
static void OnSystemReset(void)
Will be called to reset the system.
Definition lora_app.c:528
static void OnTxFrameCtrlChanged(LmHandlerMsgTypes_t isTxConfirmed)
Change the confirmation control of the uplink frames.
Definition lora_app.c:506
static void OnStoreContextRequest(void *nvm, uint32_t nvm_size)
Store the NVM Data context to the Flash.
Definition lora_app.c:631
static void OnNvmDataChange(LmHandlerNvmContextStates_t state)
Notifies the upper layer that the NVM context has changed.
Definition lora_app.c:613
static void OnClassChange(DeviceClass_t deviceClass)
callback when LoRaWAN application Class is changed
Definition lora_app.c:466
static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
callback when LoRaWAN application has received a frame
Definition lora_app.c:401
static void OnMacProcessNotify(void)
Definition lora_app.c:472
static void OnTxPeriodicityChanged(uint32_t periodicity)
Change the periodicity of the uplink frames.
Definition lora_app.c:484
static void OnPingSlotPeriodicityChanged(uint8_t pingSlotPeriodicity)
Change the periodicity of the ping slot frames.
Definition lora_app.c:517
static void OnRestoreContextRequest(void *nvm, uint32_t nvm_size)
Restore the NVM Data context from the Flash.
Definition lora_app.c:643
static void OnBeaconStatusChange(LmHandlerBeaconParams_t *params)
callback when LoRaWAN Beacon status is updated
Definition lora_app.c:453
static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
join event callback function
Definition lora_app.c:442
void GetDevAddr(uint32_t *devAddr)
callback to get the board 32 bits unique ID (LSB)
Definition sys_app.c:239
int16_t GetTemperatureLevel(void)
callback to get the current temperature in the MCU
Definition sys_app.c:184
void GetUniqueId(uint8_t *id)
callback to get the board 64 bits unique ID
Definition sys_app.c:198
uint8_t GetBatteryLevel(void)
callback to get the battery level in % of full charge (254 full charge, 0 no charge)
Definition sys_app.c:152

LoRaWAN handler Callbacks.

Definition at line 238 of file lora_app.c.

Referenced by LoRaWAN_Init().

◆ LmHandlerParams

LmHandlerParams_t LmHandlerParams
static
Initial value:
=
{
.ActiveRegion = LORAMAC_REGION_EU868 ,
.DefaultClass = CLASS_A ,
.AdrEnable = LORAMAC_HANDLER_ADR_ON ,
.IsTxConfirmed = LORAMAC_HANDLER_CONFIRMED_MSG ,
.TxDatarate = DR_0 ,
.TxPower = TX_POWER_0 ,
.PingSlotPeriodicity = 4 ,
.RxBCTimeout = 8000
}

LoRaWAN handler parameters.

Definition at line 263 of file lora_app.c.

Referenced by LoRaWAN_Init(), OnPingSlotPeriodicityChanged(), OnTxFrameCtrlChanged(), StopJoin(), and systemParams_SetLoRaWanParams().

◆ StopJoinTimer

UTIL_TIMER_Object_t StopJoinTimer
static

Join Timer period.

Definition at line 293 of file lora_app.c.

Referenced by LoRaWAN_Init(), and StopJoin().

◆ TxPeriodicity

UTIL_TIMER_Time_t TxPeriodicity = 10000
static

Tx Timer period.

Definition at line 288 of file lora_app.c.

Referenced by LoRaWAN_Init(), and OnTxPeriodicityChanged().

◆ TxTimer

UTIL_TIMER_Object_t TxTimer
static

Timer to handle the application Tx.

Definition at line 283 of file lora_app.c.

Referenced by LoRaWAN_Init(), OnTxPeriodicityChanged(), OnTxTimerEvent(), and StopJoin().