Um2073 User Manual: Stm32 Lora Software Expansion For Stm32Cube
Um2073 User Manual: Stm32 Lora Software Expansion For Stm32Cube
Um2073 User Manual: Stm32 Lora Software Expansion For Stm32Cube
User manual
STM32 LoRa® software expansion for STM32Cube
Introduction
This user manual describes the LoRa® embedded expansion software implementation on
the STM32Lx Series; this software is called I-CUBE-LRWAN. This document also explains
how to interface with the LoRaWAN™ to manage the LoRa® wireless link.
LoRa® is a type of wireless telecommunication network designed to allow long range
communications at a very low bit-rate and enabling long-life battery operated sensors.
LoRaWAN™ defines the communication and security protocol that ensures the
interoperability with the LoRa® network.
The LoRa® software expansion is compliant with the LoRa Alliance™ specification protocol
named LoRaWAN™.
The I-CUBE-LRWAN main features are the following:
• Application integration ready
• Easy add-on of the low-power LoRa® solution
• Extremely low CPU load
• No latency requirements
• Small STM32 memory footprint
• Low-power timing services provided
The I-CUBE-LRWAN software is based on the STM32Cube HAL drivers (see Section 2).
This user manual provides customer application examples on NUCLEO-L053R8,
NUCLEO-L152RE and NUCLEOL476RG using Semtech expansion boards
SX1276MB1MAS, SX1276MB1LAS and SX1272MB2DAS.
This document targets the following tools:
• P-NUCLEO-LRWAN1, STM32 Nucleo pack for LoRa® technology
• B-L072Z-LRWAN1, STM32 Discovery kit embedding the CMWX1ZZABZ-091 LoRa®
module (Murata)
• I-NUCLEO-LRWAN1, LoRa® expansion board for STM32 Nucleo, based on the
WM-SG-SM-42 LPWAN module (USI®).
Contents
1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5 Example description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.1 Single MCU end-device hardware description . . . . . . . . . . . . . . . . . . . . . 29
5.2 Split end-device hardware description (two-MCUs solution) . . . . . . . . . . 30
5.3 Package description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.4 End_Node application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.4.1 Activation methods and keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.4.2 Debug switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.4.3 Sensor switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.5 PingPong application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.6 AT_Slave application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.7 AT_Master application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6 System performances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1 Memory footprints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.2 Real-time constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.3 Power consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
7 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
List of tables
List of figures
1 Overview
1.2 References
• LoRa Alliance specification protocol named LoRaWAN version V1.0 - 2015, January -
Released
• IEEE Std 802.15.4TM - 2011. Low-Rate Wireless Personal Area Networks (LR-
WPANs)
2.1 Overview
This section provides a general overview of the LoRa and LoRaWAN recommendations,
focusing in particular on the LoRa end-device which is the core subject of this user manual.
LoRa is a type of wireless telecommunication network designed to allow long range
communication at a very low bit-rate and enabling long-life battery operated sensors.
LoRaWAN defines the communication and security protocol ensuring the interoperability
with the LoRa network.
The LoRa software expansion is compliant with the LoRa Alliance specification protocol
named LoRaWAN.
Table 2 shows the LoRa classes usage definition. Refer to Section 2.2.2 for further details
on these classes.
Note: While the physical layer of LoRa is proprietary, the rest of the protocol stack (LoRaWAN) is
kept open and its development is carried out by the LoRa Alliance.
3HWWUDFNLQJ
6PRNH
DODUP
:DWHUPHWHU
7UDVK
FRQWDLQHU
9HQGLQJPDFKLQH
*DV
PRQLWRULQJ
06Y9
7[ 5[ 5[
5['HOD\
5['HOD\
06Y9
3LQJ6ORW 5['HOD\
%HDFRQ3HULRG
06Y9
5['HOD\
5['HOD\
([WHQGV5[XQWLOQH[W7[
06Y9
8SSHUOD\HU
0$&
3+<
3K\VLFDOPHGLXPDLULQWHUIDFH
06Y9
0/0(5HT
MRLQUHTXHVW
-RLQUHTXHVW 0/0(,QG
MRLQUHTXHVW
0$&:DLW7LPHU
0/0(5HVS
MRLQDFFHSW
-RLQUHVSRQVHDVN
0/0(&RQI
MRLQDFFHSW
0/0(,QG
MRLQDFFHSW
(QGGHYLFH $SSVHUYHU
06Y9
0&365HT
GDWDUHTXHVW
'DWD$FNUHT
$FN:DLW'XUDWLRQ
$FNQRZOHGJPHQWIUDPH
0&36,QGGDWD
0&36&RQI
(QGGHYLFH $SS6HUYHU
06Y9
0&36&RQI
(QGGHYLFH $SSVHUYHU
06Y9
1ZN6.H\SD\ORDGRI0$&GDWD
$SS6.H\SD\ORDGRIDSSOLFDWLRQPHVVDJH
06Y9
The NwkSKey is shared between the end-device and the network server. The NwkSKey
provides message integrity for the communication and provides security for the end-device
towards the network server communication.
The AppSKey is shared between the end-device and the application server. The AppSKey
is used to encrypt/decrypt the application data. In other words, the AppSKey provides
security for the application’s payload. In this way, the application data sent by an end-device
can not be interpreted by the network server.
3.1 Overview
This I-CUBE-LRWAN package offers a LoRa stack middleware for STM32 microcontrollers.
This middleware is split into several modules:
• LoRaMac layer module
• LoRa utilities module
• LoRa crypto module
• LoRa core module
The LoRa core module implements a LoRa state machine coming on top of the LoRaMac
layer. The LoRa stack module interfaces with the BSP Semtech radio driver module.
This middleware is provided in source-code format and is compliant which the STM32Cube
Hal driver.
Refer to Figure 10 for the structure of the project files.
%63GULYHUV/R5DIRU
'LVFRYHU\ERDUG
%63GULYHUVIRU,18&/(2
/5:$1PRGHPERDUG
%63GULYHUVIRU
&0:;==$%=PRGXOH
%63GULYHUVIRU1XFOHRERDUGV
%63GULYHUVIRU6HPWHFK5DGLR
ERDUGV
%63GULYHUVIRU6HQVRUERDUG
0LGGOHZDUH/R5DVWDWHPDFKLQH
0LGGOHZDUH/R5DFU\SWRHQJLQH
0LGGOHZDUH/R5D0$&OD\HU
0LGGOHZDUH/R5D5DGLRLQWHUIDFH
/R5DDSSOLFDWLRQV
06Y9
3.2 Features
• Compliant with the specification for the LoRa Alliance protocol named LoRaWAN
• On-board LoRaWAN class A and class C protocol stack
• EU 868MHz ISM band ETSI compliant
• EU 433MHz ISM band ETSI compliant
• US 915MHz ISM band FCC compliant
• End-device activation either through over-the-air activation (OTAA) or through
activation-by-personalization (ABP)
• Adaptive data rate support
• LoRaWAN test application for certification tests included
• Low-power optimized
3.3 Architecture
Figure 11 describes the main design of the firmware for the I-CUBE-LRWAN application.
$SSOLFDWLRQXVHU
676(07(&+
67
/R5D0LGGOHZDUH
0$&ORZHUOD\HU 8WLOLWLHV
7LPHUVHUYHU 6HQVRU
/RZSRZHU GULYHU
5DQGJHQ
5DGLRGULYHU WH[W
6;[GULYHU
+$/
06Y9
The HAL uses Cube APIs to drive the MCU hardware required by the application. Only
specific hardware is included in the LoRa middleware as it is mandatory to run a LoRa
application.
The RTC provides a centralized time unit which continues to run even in Low-power mode
(Stop mode). The RTC alarm is used to wake up the system at specific timings managed by
the timer server.
The radio driver uses the SPI and the GPIO hardware to control the radio (see Figure 11).
The radio driver also provides a set of APIs to be used by higher level software.
The LoRa radio is provided by Semtech, though the APIs have been slightly modified to
interface with the STM32Cube HAL.
The radio driver is split in two parts:
• The sx1276.c (or sx1272.c) contains all functions which are radio dependent only.
• The sx1276mb1mas.c, sx1276mb1las and sx1272mb2das contain all the radio board
dependent functions.
The MAC controls the PHY using 802.15.4 model. The MAC interfaces with the PHY driver
and uses the timer server to add or remove timed tasks and to take care of the
'Tx time on air'. This action ensures that the duty-cycle limitation mandated by the ETSI is
respected and also carries out AES encryption/decryption algorithm to cypher the MAC
header and the payload.
Since the state machine, that controls the LoRa class A, is sensitive, an intermediate level
of software has been inserted (lora.c) between the MAC and the application
(refer to MAC’s “upper layer” on Figure 11). With a set of APIs limited as of now, the user is
free to implement the class A state machine at application level.
The application, built around an infinite loop, manages the low-power, runs the interrupt
handlers (alarm or GPIO) and calls the LoRa class A if any task has to be done. This
application also implements the sensor read access.
3.4.2 SPI
The sx127x radio registers are accessed through the SPI bus at 1 Mbit/s (refer to Table 25
and to Section 5.1).
3.4.3 RTC
The RTC calendar is used as a timer engine running in all power modes from the 32 kHz
external oscillator. By default, the RTC is programed to provide 1024 ticks (sub-seconds)
per second. The RTC is programed once at initialization of the hardware when the MCU
starts for the first time. The RTC output is limited to a 32-bit timer that is around a 48 days
period.
If the user needs to change the tick duration, note that the tick duration should remain below
1 ms.
This section gives a description of the LoRaMac layer APIs. The PHY layer being
proprietary (see Section 2.1: Overview) is out of the scope of this user manual and has to be
viewed as a black box.
LoRaMacStatus_t LoRaMacMcpsRequest
Requests to send Tx data
(McpsReq_t *mcpsRequest)
LoRaMacStatus_t LoRaMacMibSetRequestConfirm
To set attributes of the LoRaMac layer
(MibRequestConfirm_t *mibSet)
LoRaMacStatus_t LoRaMacMibGetRequestConfirm
To get attributes of the LoRaMac layer
(MibRequestConfirm_t *mibGet)
4.3.1 MCPS
In general, the LoRaMAC layer uses the MCPS services for data transmission and data
reception (see Table 8).
4.3.2 MLME
The LoRaMAC layer uses the MLME services to manage the LoRaWAN network
(see Table 9).
4.3.3 MIB
N/A
Standard mode
In standard mode, an interface file (see MAC upper layer in Figure 11) is provided to let the
user start without worrying about the LoRa state machine. The interface file is located in
Middlewares\Third_Party\Lora\Core\lora.c.
The interface file implements:
• an example of finite state machine managing the LoRaMAC
• the LoRa certification test cases that are not visible to the application layer
Advanced mode
In this mode, the user accesses directly the MAC layer by including the MAC in the user file.
Operation model
The model of operation proposed for this LoRa class A (see Figure 12) is based on finite
state machine (FSM) running in the main thread of the application. LoRa FSM transition is
triggered either by a timer event or by a radio event.
5HVHW
+$/LQLWLDOL]DWLRQ
,SVLQLWLDOL]DWLRQ
/R5DVWDFNLQLWLDOL]DWLRQ
,54H[HFXWHGKHUH /R5DILQLWHVWDWH
ZKHQZDNLQJXS PDFKLQHPJW
IURPORZSRZHU
(1$%/(B,54 ',6$%/(B,54
1R ,V
VOHHS
VWDWH
<HV
/RZSRZHUPRGH
06Y9
From “DEVICE_STATE_SLEEP”, if the end-device has not joined the network when a
“TimerEvent” or “OnSendEvent” occurs, the LoRa FSM goes into DEVICE_STATE_JOIN. In
this case the LoRa FSM requests a new join network request.
From “DEVICE_STATE_SEND”, the LoRa FSM prepares and sends Tx packets (if any).
Then the LoRa FSM goes into “DEVICE_STATE_SLEEP”.
On “OnSendEvent”, the LoRa FSM goes back to the “DEVICE_STATE_SEND” to send next
scheduled packet.
6OHHS
1:.B-2,1('7LPHU(YHQW
5HVHW
1:.B-2,1('7LPHU(YHQW
-RLQHG ,QLW
7[1H[W7[1H[W3DFNHW 27$$-RLQ7LPHU
7UXHSULQWI 'XW\&\FOH(QDEOH
1:.B-2,1('2Q6HQG(YHQW
-RLQ
6HQG
$%39RLG
06Y9
5 Example description
The I-CUBE-LRWAN software expansion package can easily be tailored to any other
supported device and development board.
The main characteristics of the LoRa radio expansion board are described in Table 25.
SX1276MB1MAS 868 MHz (HF) at 14 dBm and 433 MHz (LF) at 14 dBm
SX1276MB1LAS 915 MHz (HF) at 20 dBm and 433 MHz (LF) at 14 dBm
SX1272MB2DAS 915 MHz and 868 MHz at 14 dBm
Interrupts
Table 26 shows the interrupt priorities level applicable for the Cortex system processor
exception and for the STM32L0 Series LoRa application-specific interrupt (IRQ).
RTC 0 NA
EXTI2_3 0 NA
EXTI4_15 0 NA
18&/(2/5 /RUDH[SDQVLRQERDUG
,18&/(2/5:$1
$7B0$67(5 /RUD0RGHP
DSSOLFDWLRQ $7FRPPDQG
/RUD:DQ 6WDFN
70
LQFOXGHGLQ RYHU8$57
5DGLR
,&8%(/5:$1
06Y9
The interface between the LoRa modem and the LoRa host is a UART running AT
commands.
LoRa REGION_EU433
stack REGION_US915
REGION_AS923
REGION_AU915 Enable the EU band selection Compiler option setting
REGION_CN470
REGION_CN779
REGION_IN865
REGION_KR920
DEBUG Enable "Led on/off" hw_conf.h
TRACE Enable "printf". hw_conf.h
Sensor
Enable the call to the sensor
SENSOR_ENABLED hw_conf.h
board
Note: The maximum payload length allowed depends on both the region and the selected data
rate, so the payload format must be carefully designed according to these parameters.
/R5DHQGGHYLFH /R5DHQGGHYLFH
&RP3RUW &RP3RUW
67018&/(25DGLR 67018&/(25DGLR
H[SDQVLRQERDUG H[SDQVLRQERDUG
06Y9
Note: The NUCLEO board communicates with expansion board via UART (PA2,PA3). The
following modifications shall be applied: (cf. chapter 5.8 of UM1724).
• SB62 and SB63 should be closed
• SB13 and SB14 should be opened to disconnect STM32 UART from STLINK
6 System performances
0&8
',2
7['RQH 5['RQH
06Y9
Measurements setup:
• No DEBUG
• No TRACE
• No SENSOR_ENABLED
Measurements results:
• Typical consumption in stop mode: 1.3 µA
• Typical consumption in run mode: 8.0 mA
Measurements figures:
• Instantaneous consumption over 30 seconds
The Figure 17 shows an example of the current consumption against time on a
microcontroller of the STM32L0 Series.
7 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.