RadioHead
RH_STM32WLx.h
1// RH_STM32WLx.h
2//
3// Definitions for the ST Microelectronics STM32WLE5JC chip which contains
4// a SX1261/1262 LoRa capable radio.
5// https://wiki.seeedstudio.com/LoRa_E5_mini/
6// https://www.rfsolutions.co.uk/downloads/1537522406DS_SX1261-2_V1.1_SEMTECH.pdf
7// https://cdn.sparkfun.com/assets/6/b/5/1/4/SX1262_datasheet.pdf
8// https://files.seeedstudio.com/products/317990687/res/LoRa-E5+module+datasheet_V1.0.pdf
9// https://forum.seeedstudio.com/t/lora-e5-register-settings-for-oscillators/262635
10// file:///home/mikem/Downloads/es0506-stm32wle5xx-stm32wle4xx-device-errata-stmicroelectronics.pdf
11// Author: Mike McCauley (mikem@airspayce.com)
12// Copyright (C) 2023 Mike McCauley
13//
14
15#ifndef RH_STM32WLx_h
16#define RH_STM32WLx_h
17
18#include <RH_SX126x.h>
19
20/////////////////////////////////////////////////////////////////////
21/*! \class RH_STM32WLx RH_STM32WLx.h <RH_STM32WLx.h>
22\brief Driver to send and receive unaddressed, unreliable datagrams via a
23SX1261 LoRa capable radio transceiver embedded in a ST Microelectronics STM32WLE5xx and
24STM32WLE4xx processors.
25
26\par Overview
27
28The ST Microelectronics STM32WLE5xx and STM32WLE4xx Arm Cortex
29processors contain a SX1261 radio with 2 power amplifiers (PAs), a bit
30like a combination of a SX1261 and SX1262. There is a dedicated SPI
31interface (called the SubGhzSPI that is used only to communicate with
32the radio.
33
34The Seeed LoRa-E5-HF and LoRa-E5-LF modules encapsulate a STM32WLE5JC
35processor, along with an antenna switch, Temperature Controlled
36Crystal Oscillator (TCXO) and some support components. The Seeed
37Wio-E5 mini developement board (described below) has a LoRa-E5-HF
38along with voltage regulator, USB interface, antenna connector etc.
39
40This class is a subclass of RH_SX126x. See the documentation for that
41class for more details about configuring and using this class.
42
43The stmx32wl_* examples provided should compile out of the box on Arduino 2.1 or later
44and run with either modules equipped with
45LoRa-E4 or on the NUCLEO_WL55JC1. Make sure you select the appropriate board in Arduino.
46
47\par The Seeed Wio-E5 mini
48
49One example of a development board that includes a STM32WLE5xx and
50SX1261 radio is the Wio-E5 mini.
51
52The Wio-E5 mini is powered by the ST Microelectronics STM32WLE5JC,
53which contains an ARM Cortex-M4 core and Semtech SX126X LoRa capable
54radio. The core and radio are enclosed in a sealed Seeed LoRa-E5-HF
55module, and which includes an antenna switch.
56
57https://wiki.seeedstudio.com/LoRa_E5_mini/
58https://files.seeedstudio.com/products/317990687/res/LoRa-E5+module+datasheet_V1.0.pdf
59
60It comes with a 868 to 915MHz compatible antenna and USB-C cable.
61
62As shipped, the Wio-E5 mini contains firmware that provides a serial AT
63command set that allows the device to connect to join a LoRaWAN
64network (via a LoRaWAN gateway) using LoRA radio modulation.
65https://files.seeedstudio.com/products/317990687/res/LoRa-E5+AT+Command+Specification_V1.0+.pdf
66
67You can plug the WiO E5 into a USB port, and use a serial port
68program (gtkterm, putty, Hyperterm or whatever) to communicate (using
69AT commands) with the Wio-E5, configure it and then use it to send
70LoRaWAN messages to a LoRaWAN server.
71
72However, what we want to do is to upload RadioHead based firmware into
73the Wio-E5 and use the built in SX126X radio to communicate via LoRa
74radio modulation with other similar LoRA radio nodes.
75
76Note: LoRa is NOT the same thing as LoRaWAN. LoRaWAN is a complete
77networking system that uses LoRa radio modulation as the transport
78layer. If you want to work with a LoRaWAN network, you should be using
79LoRaWAN software and libraries, not RadioHead. LoRa is a much simpler
80and lower level transport layer that can he used to send short
81messages over significant distances withglow power.
82
83So, we want to upload RadioHead based software (containing the
84RadioHead SX126X driver) to the STM32WLE5JC on the Wio-E5. Before we
85can do that we have to disable the firmware write protection on the
86STM32WLE5JC.
87
88The Wio-E5 (as shipped) AT command firmware is protected by the ARM
89processor's Read Out Protection (RDP) byte, meaning you cant read out
90the AT command set firmware, nor can you upload new firmware, The RDP
91byte has to be reset first.
92
93But CAUTION: resetting the RDP byte will permanently ERASE the
94as-shipped AT command firmware, and THERE IS NO WAY TO GET IT BACK. So
95make sure thats what you want to do.
96
97In order to be able to upload our own firmware we must reset the RDP
98byte from the as-shipped value of 0xBB (Level 1 read protection) to
990xAA (Level 0, no protection). In order to do this you will need:
100
101- Wio-E5 mini as shipped
102- STLink/V2 or STLink/V2 emulator (we used the Adafruit 2548
103 https://www.adafruit.com/product/2548). Its an emulator (a red cased USB dongle)
104- Host computer with USB ports (Linux, Mac or Windows)
105- STM32CubeProgrammer software
106 https://www.st.com/en/development-tools/stm32cubeprog.html
107 2.15.0 or later for Linux Mac or Windows. Registration required.
108
1091. Install STM32CubeProgrammer
1102. Wire the STLink/V2 to the Wio-E5 pins with the jumper wires
111 provided. This will provide both power and
112 communications with the STM32WLE5JC:
113 Wio-E5 STLink/V2 (writing on the end shows the pinout)
114 3.3V 3.3V
115 GND GND
116 DIO SWDIO
117 CLK SWCLK
1183. Plug the STLink/V2 into a USB port. Red light should appear on the STLink/V2.
1194. Run STM32CubeProgrammer (appears in Ubuntu Applications menu if installed on Linux with wine)
1205. At the top right you should see ST-LINK selected, and below that,
121in the ST-LINK Configuration box, the Serial number of your STLink/V2.
1226a. If this is the first time you have used the STLink/V2, you will need
123 to upgrade its firmware. Click on 'Firmware upgrade' in the ST-LINK
124 Configuration box, get the Upgrade dialog.
1256b. Click on 'Open in update mode'. If it complains the STlink is not
126in DFU mode, unplug and replug the STlink, click on 'Refresh device
127list', then 'Open in update mode'
1286c Click on Upgrade. Wait 20 seconds. See success.
1296d Close the dialog.
1307a Press RST reset pin on the Wio-E5 and then immediately:
1317b Click on 'Connect' top right of STM32CubeProgrammer. You should see
132 some blue progress lines in the Log, maybe finally a red 'Data read
133 failed'. Thats OK, because the RDP byte is still set.
1348. Click on the 'OB' icon, 3rd from the top in the far left margin.
1359. Select Read Out Protection item, see RDP value set to 'BB'. Change to
136 'AA', click Apply. See pop-up 'Option Bytes successfully
137 programmed'.
138
139Good! The STM32WLE5JC firmware can now be written and read as we need (note
140that the factory supplied LoRaWan firmware has now been erased), by
141either STM32CubeProgrammer or Arduino IDE (2.1.1 or later) via the
142STLink/V2, so leave it connected
143
144In order to use the Arduino IDE to program the Wio-E5, you must
145install the stm32duino package using these instructions:
146 https://community.st.com/t5/stm32-mcus/stm32-arduino-stm32duino-tutorial/ta-p/49649
147
148Leave STLink/V2 connected but close STM32CubeProgrammer
149In Arduino IDE: select the following menu options:
150Tools -> Board -> STM32 MCU based boards -> LoRa boards
151Tools -> Board part number -> LoRa-E5 mini
152Tools -> U(S)ART support -> Enabled (generic Serial)
153You will then be able to edit and upload directly from Arduino IDE through the STLink/V2
154You can connect the Wio-E5 USB-C to your hosts USB port and use
155Arduino IDE to monitor the serial output to Serial
156(Note: programming does not occur over the USB connection).
157
158There are other options for programming the STM32WLE5JC,
159including STM32CubeIDE from ST. We did not test them.
160
161https://www.rfsolutions.co.uk/downloads/1537522406DS_SX1261-2_V1.1_SEMTECH.pdf
162
163Lora-net software:
164https://github.com/Lora-net/SWL2001/releases/tag/v3.3.0
165
166\par Interrupts
167
168This driver uses the SubGhzClass class (part of the Arduino stm32duino
169board support) to interface with the internal SX1261/2 radio. That
170class implements the dedicated radio SPI interface. The radio also has a
171dedicated internal pin for the radio interrupt and the SPI device select
172pin and the radio reset pin. The SubGhzClass class includes methods
173for using all those pins.
174
175Nevertheless it should be possible to use this processor with the
176normal external SPI interfaces to also interface with another SPI
177based RadioHEad supported radio, in oprder to make a radio gateway
178etc.
179
180*/
181class RH_STM32WLx : public RH_SX126x
182{
183public:
184 // Contructor
185 RH_STM32WLx();
186
187 // Override the init() function becaue we need to adjust some things afterwards to suit this radio module
188 virtual bool init();
189
190protected:
191 // Override this because waiting is built in to the SUBGhz driver
192 virtual bool waitUntilNotBusy() { return true;};
193
194 /// Do whatever is necesary to establish the interrupt handler.
195 /// This device has special requirements for setting up the interupt handler
196 /// through the SUBGHZSPI interface so we override
198};
199
200
201#endif
202
Driver to send and receive unaddressed, unreliable datagrams via a SX1261 LoRa capable radio transcei...
Definition: RH_STM32WLx.h:182
virtual bool waitUntilNotBusy()
Definition: RH_STM32WLx.h:192
virtual bool init()
bool setupInterruptHandler()
Driver to send and receive unaddressed, unreliable datagrams via a Semtech SX126X family LoRa capable...
Definition: RH_SX126x.h:757