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
23
SX1261 LoRa capable radio transceiver embedded in a ST Microelectronics STM32WLE5xx and
24
STM32WLE4xx processors.
25
26
\par Overview
27
28
The ST Microelectronics STM32WLE5xx and STM32WLE4xx Arm Cortex
29
processors contain a SX1261 radio with 2 power amplifiers (PAs), a bit
30
like a combination of a SX1261 and SX1262. There is a dedicated SPI
31
interface (called the SubGhzSPI that is used only to communicate with
32
the radio.
33
34
The Seeed LoRa-E5-HF and LoRa-E5-LF modules encapsulate a STM32WLE5JC
35
processor, along with an antenna switch, Temperature Controlled
36
Crystal Oscillator (TCXO) and some support components. The Seeed
37
Wio-E5 mini developement board (described below) has a LoRa-E5-HF
38
along with voltage regulator, USB interface, antenna connector etc.
39
40
This class is a subclass of RH_SX126x. See the documentation for that
41
class for more details about configuring and using this class.
42
43
The stmx32wl_* examples provided should compile out of the box on Arduino 2.1 or later
44
and run with either modules equipped with
45
LoRa-E4 or on the NUCLEO_WL55JC1. Make sure you select the appropriate board in Arduino.
46
47
\par The Seeed Wio-E5 mini
48
49
One example of a development board that includes a STM32WLE5xx and
50
SX1261 radio is the Wio-E5 mini.
51
52
The Wio-E5 mini is powered by the ST Microelectronics STM32WLE5JC,
53
which contains an ARM Cortex-M4 core and Semtech SX126X LoRa capable
54
radio. The core and radio are enclosed in a sealed Seeed LoRa-E5-HF
55
module, and which includes an antenna switch.
56
57
https://wiki.seeedstudio.com/LoRa_E5_mini/
58
https://files.seeedstudio.com/products/317990687/res/LoRa-E5+module+datasheet_V1.0.pdf
59
60
It comes with a 868 to 915MHz compatible antenna and USB-C cable.
61
62
As shipped, the Wio-E5 mini contains firmware that provides a serial AT
63
command set that allows the device to connect to join a LoRaWAN
64
network (via a LoRaWAN gateway) using LoRA radio modulation.
65
https://files.seeedstudio.com/products/317990687/res/LoRa-E5+AT+Command+Specification_V1.0+.pdf
66
67
You can plug the WiO E5 into a USB port, and use a serial port
68
program (gtkterm, putty, Hyperterm or whatever) to communicate (using
69
AT commands) with the Wio-E5, configure it and then use it to send
70
LoRaWAN messages to a LoRaWAN server.
71
72
However, what we want to do is to upload RadioHead based firmware into
73
the Wio-E5 and use the built in SX126X radio to communicate via LoRa
74
radio modulation with other similar LoRA radio nodes.
75
76
Note: LoRa is NOT the same thing as LoRaWAN. LoRaWAN is a complete
77
networking system that uses LoRa radio modulation as the transport
78
layer. If you want to work with a LoRaWAN network, you should be using
79
LoRaWAN software and libraries, not RadioHead. LoRa is a much simpler
80
and lower level transport layer that can he used to send short
81
messages over significant distances withglow power.
82
83
So, we want to upload RadioHead based software (containing the
84
RadioHead SX126X driver) to the STM32WLE5JC on the Wio-E5. Before we
85
can do that we have to disable the firmware write protection on the
86
STM32WLE5JC.
87
88
The Wio-E5 (as shipped) AT command firmware is protected by the ARM
89
processor's Read Out Protection (RDP) byte, meaning you cant read out
90
the AT command set firmware, nor can you upload new firmware, The RDP
91
byte has to be reset first.
92
93
But CAUTION: resetting the RDP byte will permanently ERASE the
94
as-shipped AT command firmware, and THERE IS NO WAY TO GET IT BACK. So
95
make sure thats what you want to do.
96
97
In order to be able to upload our own firmware we must reset the RDP
98
byte from the as-shipped value of 0xBB (Level 1 read protection) to
99
0xAA (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
109
1. Install STM32CubeProgrammer
110
2. 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
118
3. Plug the STLink/V2 into a USB port. Red light should appear on the STLink/V2.
119
4. Run STM32CubeProgrammer (appears in Ubuntu Applications menu if installed on Linux with wine)
120
5. At the top right you should see ST-LINK selected, and below that,
121
in the ST-LINK Configuration box, the Serial number of your STLink/V2.
122
6a. 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.
125
6b. Click on 'Open in update mode'. If it complains the STlink is not
126
in DFU mode, unplug and replug the STlink, click on 'Refresh device
127
list', then 'Open in update mode'
128
6c Click on Upgrade. Wait 20 seconds. See success.
129
6d Close the dialog.
130
7a Press RST reset pin on the Wio-E5 and then immediately:
131
7b 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.
134
8. Click on the 'OB' icon, 3rd from the top in the far left margin.
135
9. 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
139
Good! The STM32WLE5JC firmware can now be written and read as we need (note
140
that the factory supplied LoRaWan firmware has now been erased), by
141
either STM32CubeProgrammer or Arduino IDE (2.1.1 or later) via the
142
STLink/V2, so leave it connected, but you can close STM32CubeProgrammer.
143
144
In order to use the Arduino IDE to program the Wio-E5, you must
145
install the stm32duino package using these instructions:
146
https://community.st.com/t5/stm32-mcus/stm32-arduino-stm32duino-tutorial/ta-p/49649
147
We installed and tested with 2.7.1
148
149
Leave STLink/V2 connected but close STM32CubeProgrammer
150
In Arduino IDE: select the following menu options:
151
Tools -> Board -> STM32 MCU based boards -> LoRa boards
152
Tools -> Board part number -> LoRa-E5 mini
153
Tools -> U(S)ART support -> Enabled (generic Serial)
154
You will then be able to edit and upload directly from Arduino IDE through the STLink/V2
155
You can use a cable to connect the Wio-E5 USB-C to your hosts USB port and use
156
Arduino IDE to monitor the serial output to Serial
157
(Note: programming does not occur over the USB connection).
158
159
There are other options for programming the STM32WLE5JC,
160
including STM32CubeIDE from ST. We did not test them.
161
162
https://www.rfsolutions.co.uk/downloads/1537522406DS_SX1261-2_V1.1_SEMTECH.pdf
163
164
Lora-net software:
165
https://github.com/Lora-net/SWL2001/releases/tag/v3.3.0
166
167
\par Interrupts
168
169
This driver uses the SubGhzClass class (part of the Arduino stm32duino
170
board support) to interface with the internal SX1261/2 radio. That
171
class implements the dedicated radio SPI interface. The radio also has a
172
dedicated internal pin for the radio interrupt and the SPI device select
173
pin and the radio reset pin. The SubGhzClass class includes methods
174
for using all those pins.
175
176
Nevertheless it should be possible to use this processor with the
177
normal external SPI interfaces to also interface with another SPI
178
based RadioHEad supported radio, in oprder to make a radio gateway
179
etc.
180
181
*/
182
class
RH_STM32WLx :
public
RH_SX126x
183
{
184
public
:
185
// Contructor
186
RH_STM32WLx();
187
188
// Override the init() function becaue we need to adjust some things afterwards to suit this radio module
189
virtual
bool
init
();
190
191
protected
:
192
// Override this because waiting is built in to the SUBGhz driver
193
virtual
bool
waitUntilNotBusy
() {
return
true
;};
194
195
/// Do whatever is necessary to establish the interrupt handler.
196
/// This device has special requirements for setting up the interupt handler
197
/// through the SUBGHZSPI interface so we override
198
bool
setupInterruptHandler
();
199
};
200
201
202
#endif
203
RH_STM32WLx::waitUntilNotBusy
virtual bool waitUntilNotBusy()
Definition
RH_STM32WLx.h:193
RH_STM32WLx::init
virtual bool init()
RH_STM32WLx::setupInterruptHandler
bool setupInterruptHandler()
RH_SX126x::RH_SX126x
RH_SX126x(uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, uint8_t busyPin=RH_INVALID_PIN, uint8_t resetPin=RH_INVALID_PIN, RHGenericSPI &spi=hardware_spi, RadioPinConfig *radioPinConfig=NULL)
Definition
RH_SX126x.cpp:43
Generated by
1.15.0