Getting LoRaWAN working with STM32WL55 and Radiolib
Following project shows how to get LoRaWAN working on the STM32WL55 using Arduino and RadioLib
Requirements
- STM32WL55 Nucleo-64 board (https://www.st.com/en/microcontrollers-microprocessors/stm32wl55jc.html)
- Arduino Software (https://www.arduino.cc/en/software)
- stm32duino BSP (2.8.0 / https://github.com/stm32duino/Arduino_Core_STM32/)
- RadioLib Library (6.4.2 / https://github.com/jgromes/RadioLib/)
- A self-hosted LoRaWAN gateway or access to TTNv3
stm32duino (2.8.0)Looking at the STM32 Core for Arduino (https://github.com/stm32duino/Arduino_Core_STM32) one can easily find out that the STM32WL55/STM32WL55JC in form of the used Nucleo WL55JC1 board has been supported by this board support package since version 2.1.0. Nice, that means we can use this to get at least the microcontroller working already. Regarding the modem/radio however - there is a discouraging remark: "LoRa support not available". STM32 has its own LoRa support BSP available which can be added - however, as this seems not to support the modem in the WL55 (yet), this remarks makes sense. Time to look for support from other directions.
RadioLibRadioLib is an awesome library which aims to support as many radios available in the Arduino context and make them useable, no matter the context/protocol. Some months ago, there was finally the addition of LoRaWAN support ( https://github.com/jgromes/RadioLib/pull/867 ) - which is still improved upon each day. Actually so much that while I am writing this article, the RadioLib version 6.4.2 - which will be needed to get this working - is currently being tested by CI/CD and pushed to the RadioLib repo. The good thing about the universal LoRaWAN implementation is that it just additionally needs the support of the modem - and the knowledge of how to physically speak to it. The first one was taken care of by this issue ( https://github.com/jgromes/RadioLib/issues/588 ). The later one (how to enable and use them modem itself) - was described here ( https://github.com/jgromes/RadioLib/discussions/775 ).
Putting everything together
- Install the Arduino Environment
- Install the stm32duino BSP
- Install the RadioLib library
- Choose the correct hardware to be used:
- Tools, Board, STM32 board group, Nucleo-64
- Tools, Board part number, Nucleo WL55JC1
- Open the LoRaWAN reference example:
- File, Examples, RadioLib, LoRaWAN, LoRaWAN_End_Device_Reference
Now, all that is left to do is to change the example to match our hardware:
1.) Use the correct modem:
At the start, remove the SX1278 definition
SX1278 radio = new Module(10, 2, 9, 3);
and replace it with the one for the Lx series radio:
STM32WLx radio = new STM32WLx_Module();
2.) Set the correct area:
Just beneath that information is the region configuration:
LoRaWANNode node(&radio, &EU868);make sure it does reflect your LoRaWAN region - or customize it otherwise.
3.) Add the RFswitch definition: RadioLib needs to know how the different RFswitches are setup, e.g. which GPIO to pull where to get the radio to actually send or receive information. This information needs to be added below the STM32WLx_Module definition and looks like that:
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {
{STM32WLx::MODE_IDLE, {LOW, LOW, LOW}},
{STM32WLx::MODE_RX, {HIGH, HIGH, LOW}},
{STM32WLx::MODE_TX_LP, {HIGH, HIGH, HIGH}},
{STM32WLx::MODE_TX_HP, {HIGH, LOW, HIGH}},
END_OF_MODE_TABLE,
};4.) Use the RFswitch: Adding the definition is good, however RadioLib also needs to know that it shall actually use it. This is done by adding following after the Serial.begin(9600); in the setup area:
// set RF switch control configuration // this has to be done prior to calling begin() radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
5.) Activation / LoRaWAN connection: To actually use the LoRaWAN connection there are two options: Either just connect to a LoRaWAN endpoint using OTAA - or restore the last session from the virtual EEPROM of the STM32 and use that. To easily start the setup, just modify the joinEUI, devEUI, nwkKey and appKey to reflect the ones you created for your device. Afterwards you can store the changes, compile and upload the project to the board.
The result will be the board booting, joining the network, sending a Hello World every minute - and listens in for any downlinks sent towards your board.
You can find a full example including the useful addition to restore a previous LoRaWAN connection (e.g. after sleep or reboot) without the need to redo the OTAA in the links.
Thanks again to the overall community making it this easy to getting this board working.

Diskussion (1 Kommentar)