LoRa-E5-mini: Difference between revisions

From RevSpace
Jump to navigation Jump to search
 
(90 intermediate revisions by the same user not shown)
Line 2: Line 2:
   |Name=LoRa E5
   |Name=LoRa E5
   |Picture=
   |Picture=
   |Omschrijving=Arduino on the LoRa-E5 module
   |Omschrijving=Arduino on the LoRa-E5-mini devboard
   |Status=In progress
   |Status=In progress
   |Contact=bertrik
   |Contact=bertrik
Line 8: Line 8:


=== The plan ===
=== The plan ===
This page is about the LoRa-E5 module and getting it to work as a LoRaWAN node with Arduino and the BasicMac stack.
This page is about the Seeed Studios LoRa-E5 mini development board and getting to know its capabilities:
* replace the original "AT" firmware with Arduino based firmware
 
* use the BasicMac library for LoRaWAN
For example, make it work as a LoRaWAN node with Arduino and the BasicMac stack.
* use platformio as the build system
* Replace the original "AT" firmware with Arduino based firmware
* create some basic examples for use as a LoRaWAN node on TheThingsNetwork
* Use the BasicMac library for LoRaWAN / Use Sigfox library
* Use platformio as the build system
* Create some basic examples for use as a LoRaWAN node on TheThingsNetwork
* Use this chip/module for transmitting high-altitude balloon telemetry, possibly using 4FSK modulation (not using LoRa)


Interesting post about this module:
Interesting post about this module:
https://www.disk91.com/2021/technology/lora/lora-e5-the-seeed-studio-stm32-wl-module/
https://www.disk91.com/2021/technology/lora/lora-e5-the-seeed-studio-stm32-wl-module/
What currently works:
* Can run an Arduino program, compiling from the Arduino IDE
* Blinking the LED works
* Output over serial works
* Reading the button works
* Basic communication with the built-in SX1262 LoRa transceiver (getting the default value of the LoRaWAN syncword)
TODO, yet to figure out:
* Get some kind of Sigfox developer account and play with the Sigfox possibilities
* Get basicmac stack working with the "subghz" SPI port (it appears communication in the Arduino version of BasicMac is done using just "SPI", see https://github.com/LacunaSpace/basicmac/blob/master/target/arduino/hal/hal.cpp#L193). The problem is that the basicmac LoRaWAN stack expects to talk to a SPI port, while the STM32WL HAL provides higher-level functions to write commands and data, see https://github.com/bertrik/Arduino_Core_STM32/blob/seeed_lora_e5_mini/system/Drivers/STM32WLxx_HAL_Driver/Inc/stm32wlxx_hal_subghz.h#L355 . Internally the STM32 SUBGHZ HAL uses functions like [https://github.com/bertrik/Arduino_Core_STM32/blob/seeed_lora_e5_mini/system/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_subghz.c#L1573 SUBGHZSPI_Transmit] that would be a much better fit to the interface expected by the BasicMac stack.
** Implement/replace functions in https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c
*** writecmd: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L180
*** WriteRegs: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L193
*** WriteReg: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L207
*** WriteBuffer: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L211
*** readcmd: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L223
*** ReadRegs: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L236
*** ReadReg: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L250
*** ReadBuffer: https://github.com/LacunaSpace/basicmac/blob/master/lmic/radio-sx126x.c#L256
* Get compilation and upload working with platformio
=== Use cases / ideas ===
==== Sigfox migratory animal tracker ====
[[File:lora-e5-internal.jpg|right|LoRa-E5 internals]]
The idea is to use this thing in a migratory animal tracker, using Sigfox as a radio protocol.
Super important in this case is that it's lightweight, so it can be attached to a small migratory animal like a bat or bird.
Properties of Sigfox, in comparison to LoRaWAN:
* works in the same 868 MHz band
* is narrowband (100 or 600 Hz) instead of wideband (125 kHz for LoRaWAN)
* uses D-BPSK modulation (instead of LoRa modulation)
* sigfox is backed by a commercial entity, appears to have better coverage than TheThingsNetwork/Helium: https://www.sigfox.com/en/coverage
* will sigfox [https://www.eetimes.eu/with-sigfox-in-crisis-where-now-for-lora-and-the-lpwan-sector/ continue to exist]?
* D-BPSK modulation is supported in the STM32WLE5 chip, as presen in the Seeed LoRa-E5
It appears you need the following credentials for Sigfox:
* a 16-byte key
* a 4-byte id
* an 8-byte PAC (porting authorization code)
Next steps:
* find out where to apply for a developer account, to register devices, get access to the backend, etc., this perhaps: https://build.sigfox.com/technical-quickstart ?
-> https://buy.sigfox.com/ but you can only register using an existing device with device id and PAC ... :(
* buy one of these https://nl.rs-online.com/web/p/communication-wireless-development-tools/1365801
Interesting reading:
* https://www.disk91.com/2019/technology/sigfox/make-you-own-1-sigfox-iot-device/
* https://www.disk91.com/2019/news/sigfox-news/i-held-the-first-1-sigfox-iot-device/
* https://www.disk91.com/2018/technology/sigfox/create-a-5-autonomous-tracker-with-esp8266-and-sigfox/
==== LoRaWAN/4FSK tracker in high-altitude ballooning ====
People send up helium balloons and attach a location tracker. A radio transmitter sends telemetry with position, temperature, voltage etc down.
The frequencies are often in 70cm band (around 430 MHz), but people are also using LoRaWAN (868 MHz in EU).
Modulations used are RTTY (now not so often anymore), 4FSK (a more advanced narrow-band modulation with error correction) and LoRa (either as 'raw' LoRa or LoRaWAN).
Investigate if this module can be used in the 4FSK Mode:
* see https://github.com/projecthorus/horusbinary_radiolib . This in turn uses the [https://github.com/jgromes/RadioLib RadioLib] and uses the SX1262 in basic frequency synthesis mode
Callchain
* horusbinary -> fsk4_tone -> fsk4_transmitDirect -> phy.transmitDirect
* radiolib/sx1262: transmitDirect -> setRfFrequency -> SPIwriteCommand -> SPITransfer
* radiolib/...


=== Hardware ===
=== Hardware ===
The hardware is the LoRa-E5 module from seeed studio, contains the STM32WLE5JC:
The hardware is the LoRa-E5 mini from seeed studio, contains the [https://www.st.com/en/microcontrollers-microprocessors/stm32wle5jc.html STM32WLE5JC]:
* LoRa E5 module (just the chip): https://www.seeedstudio.com/LoRa-E5-Wireless-Module-p-4745.html
* LoRa E5 Seeed studio module (just the chip): https://www.seeedstudio.com/LoRa-E5-Wireless-Module-p-4745.html
* LoRa E5 mini dev board: https://www.seeedstudio.com/LoRa-E5-mini-STM32WLE5JC-p-4869.html
* LoRa E5 Seeed studio LoRa-E5 mini dev board: https://www.seeedstudio.com/LoRa-E5-mini-STM32WLE5JC-p-4869.html
* LoRa E5 wiki page: https://wiki.seeedstudio.com/LoRa-E5_STM32WLE5JC_Module/
* LoRa E5 Seeed studio wiki page: https://wiki.seeedstudio.com/LoRa-E5_STM32WLE5JC_Module/
* FCC information about the module: https://fccid.io/Z4T-LORA-E5/
* FCC information about the module: https://fccid.io/Z4T-LORA-E5/
* Weight?


Overview of pins used on this board (not completely standard):
Overview of pins used on this board (not completely standard):
https://wiki.seeedstudio.com/LoRa_E5_mini/#22-gpio-configuration-overview
https://wiki.seeedstudio.com/LoRa_E5_mini/#22-gpio-configuration-overview


=== Software ===
Pins:
https://github.com/bertrik/lora-e5
* PA4/PA5: radio rx/tx switch (internal, not available on the footprint of the E5 module)
 
* PB0: TCXO power?
There appears to be support for various kinds of WL55 boards:
* PB6/PB7: serial port
https://github.com/stm32duino/Arduino_Core_STM32/blob/main/boards.txt
* PB5: onboard LED
 
* PB13: onboard button ("BOOT")
Support for this board in this archive:
https://github.com/dolfandringa/Arduino_Core_STM32/blob/master/variants/STM32WLxx/WL54JCI_WL55JCI_WLE4J(8-B-C)I_WLE5J(8-B-C)I/boards_entry.txt#L62  ???


==== Development environment ====
==== LoRa modem ====
* Install Arduino IDE, from https://www.arduino.cc/en/software
It appears the LoRa functionality is exposed through an internal SPI bus, called SUBGHZSPI in the datasheet.
* Add a board URL: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
* Under menu Tools/Board/Boards manager, search for STM32 and install 'STM32 MCU based boards'
* Under menu Tools/Board/STM32 boards, choose 'Generic STM32WL series', then 'Generic STM32WL series'
* Under menu Tools/Board part number, choose Generic WLE5JCIx'


Load the .ino file.
Also, there are some pins to control the radio path.
Compile with ctrl-R.


==== Programming over SWD ====
==== Programming over SWD ====
Line 52: Line 114:
* GND to GND
* GND to GND


Hold BOOT, then press RST and execute:
You may need to upgrade the firmware of your STLINKv2, mine is currently at V2J38S7.
  openocd -s /usr/share/openocd/scripts -f interface/stlink.cfg -f target/stm32wlx.cfg
 
Result:
=== Software ===
<pre>
The software consists of an STM32 Arduino development environment with support for the Seeed LoRa E5 mini
Open On-Chip Debugger 0.11.0
plus a demonstration sketch.
Licensed under GNU GPL v2
 
For bug reports, read
Other projects with this chip:
http://openocd.org/doc/doxygen/bugs.html
* https://github.com/stm32duino/STM32LoRaWAN
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
 
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
==== Development environment ====
Info : Listening on port 6666 for tcl connections
This uses my own fork of the STM32 packages, which will include support for the Seeed LoRa E5 mini:
Info : Listening on port 4444 for telnet connections
https://github.com/bertrik/Arduino_Core_STM32/tree/seeed_lora_e5_mini
Info : clock speed 500 kHz
 
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
* Install Arduino IDE 1.8.16, from https://www.arduino.cc/en/software
Info : Target voltage: 3.258730
* Configure Arduino STM32 support:
Info : stm32wlx.cpu: hardware has 6 breakpoints, 4 watchpoints
** Add the following board URL (under File / Preferences / Additional board URLs):
Info : starting gdb server for stm32wlx.cpu on 3333
  https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Info : Listening on port 3333 for gdb connections
** Under menu Tools/Board/Boards manager, search for STM32 and install 'STM32 MCU based boards'
</pre>
* Install STM Cube for the upload tools:
** Download and install package en.stm32cubeprg-lin_v2-8-0_v2.8.0.zip
* Run STM Cube to remove read protection (and erase the device) from the STM32
** attach the STLink V2 and connect it to the STM32
** TODO: document, or see the Seeed page
** NOTE: this does not erase any sigfox credentials (which is a good thing)
* Clone my Arduino_Core_STM32 repo into ~/Arduino/hardware
  cd ~/Arduino/hardware
  mkdir -f stm32
  cd stm32
  git clone https://github.com/bertrik/Arduino_Core_STM32
  git checkout seeed_lora_e5_mini
* Restart the Arduino IDE and select the correct board:
** Under menu Tools/Board/STM32 boards .... <b>(sketchbook)</b>, choose 'Generic STM32WL series' from 'Generic STM32WL series'
** Under menu Tools/Board part number, choose 'Seeed Studios LoRa E5 mini'
 
==== Demonstration sketch ====
[[File:Flash-lora-e5-mini.png|thumb|right|programming from the Arduino IDE]]


Or program over serial?
A demonstration Arduino sketch is at https://github.com/bertrik/lora-e5 :
* blinky example, the most basic of all sketches which makes a LED blink demonstration of successful download of an Arduino program
* helloworld example, sends a text over the serial port


==== Getting it to work ====
Try the helloworld example:
Got a flashing LED sketch to work:
* Connect the LoRa E5 over serial and with an ST-Link v2 as described in https://revspace.nl/LoRa-E5-mini#Programming_over_SWD
* install Arduino IDE
* Load the helloworld.ino file into the Arduino IDE:
* install the STM32 support
** Compile and upload with ctrl-U
* choose the right board
** See the LED flash
* upgrade the firmware of my stlink2 (tool from ST)
** Open serial port with ctrl-shift-M and see that serial messages are coming in
* run the cubestm environment to use the stlink2 to disable the firmware protection
** Press the BOOT button and see the result on the serial console: it shows the result of reading the syncword registers, proving that we can communicate with the SX1262 LoRa transceiver
* flash a simple blinky sketch to the board


=== Node configuration in TheThingsNetwork ===
=== Node configuration in TheThingsNetwork ===

Latest revision as of 08:16, 22 March 2023

Project LoRa E5
Arduino on the LoRa-E5-mini devboard
Status In progress
Contact bertrik
Last Update 2023-03-22

The plan

This page is about the Seeed Studios LoRa-E5 mini development board and getting to know its capabilities:

For example, make it work as a LoRaWAN node with Arduino and the BasicMac stack.

  • Replace the original "AT" firmware with Arduino based firmware
  • Use the BasicMac library for LoRaWAN / Use Sigfox library
  • Use platformio as the build system
  • Create some basic examples for use as a LoRaWAN node on TheThingsNetwork
  • Use this chip/module for transmitting high-altitude balloon telemetry, possibly using 4FSK modulation (not using LoRa)

Interesting post about this module: https://www.disk91.com/2021/technology/lora/lora-e5-the-seeed-studio-stm32-wl-module/

What currently works:

  • Can run an Arduino program, compiling from the Arduino IDE
  • Blinking the LED works
  • Output over serial works
  • Reading the button works
  • Basic communication with the built-in SX1262 LoRa transceiver (getting the default value of the LoRaWAN syncword)

TODO, yet to figure out:

Use cases / ideas

Sigfox migratory animal tracker

LoRa-E5 internals

The idea is to use this thing in a migratory animal tracker, using Sigfox as a radio protocol.

Super important in this case is that it's lightweight, so it can be attached to a small migratory animal like a bat or bird.

Properties of Sigfox, in comparison to LoRaWAN:

  • works in the same 868 MHz band
  • is narrowband (100 or 600 Hz) instead of wideband (125 kHz for LoRaWAN)
  • uses D-BPSK modulation (instead of LoRa modulation)
  • sigfox is backed by a commercial entity, appears to have better coverage than TheThingsNetwork/Helium: https://www.sigfox.com/en/coverage
  • will sigfox continue to exist?
  • D-BPSK modulation is supported in the STM32WLE5 chip, as presen in the Seeed LoRa-E5

It appears you need the following credentials for Sigfox:

  • a 16-byte key
  • a 4-byte id
  • an 8-byte PAC (porting authorization code)

Next steps:

-> https://buy.sigfox.com/ but you can only register using an existing device with device id and PAC ... :(

Interesting reading:

LoRaWAN/4FSK tracker in high-altitude ballooning

People send up helium balloons and attach a location tracker. A radio transmitter sends telemetry with position, temperature, voltage etc down. The frequencies are often in 70cm band (around 430 MHz), but people are also using LoRaWAN (868 MHz in EU). Modulations used are RTTY (now not so often anymore), 4FSK (a more advanced narrow-band modulation with error correction) and LoRa (either as 'raw' LoRa or LoRaWAN).

Investigate if this module can be used in the 4FSK Mode:

Callchain

  • horusbinary -> fsk4_tone -> fsk4_transmitDirect -> phy.transmitDirect
  • radiolib/sx1262: transmitDirect -> setRfFrequency -> SPIwriteCommand -> SPITransfer
  • radiolib/...

Hardware

The hardware is the LoRa-E5 mini from seeed studio, contains the STM32WLE5JC:

Overview of pins used on this board (not completely standard): https://wiki.seeedstudio.com/LoRa_E5_mini/#22-gpio-configuration-overview

Pins:

  • PA4/PA5: radio rx/tx switch (internal, not available on the footprint of the E5 module)
  • PB0: TCXO power?
  • PB6/PB7: serial port
  • PB5: onboard LED
  • PB13: onboard button ("BOOT")

LoRa modem

It appears the LoRa functionality is exposed through an internal SPI bus, called SUBGHZSPI in the datasheet.

Also, there are some pins to control the radio path.

Programming over SWD

Connect an ST-LINKv2 as follows:

  • SWDIO to PA13
  • SWCLK to PA14
  • GND to GND

You may need to upgrade the firmware of your STLINKv2, mine is currently at V2J38S7.

Software

The software consists of an STM32 Arduino development environment with support for the Seeed LoRa E5 mini plus a demonstration sketch.

Other projects with this chip:

Development environment

This uses my own fork of the STM32 packages, which will include support for the Seeed LoRa E5 mini: https://github.com/bertrik/Arduino_Core_STM32/tree/seeed_lora_e5_mini

  • Install Arduino IDE 1.8.16, from https://www.arduino.cc/en/software
  • Configure Arduino STM32 support:
    • Add the following board URL (under File / Preferences / Additional board URLs):
 https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
    • Under menu Tools/Board/Boards manager, search for STM32 and install 'STM32 MCU based boards'
  • Install STM Cube for the upload tools:
    • Download and install package en.stm32cubeprg-lin_v2-8-0_v2.8.0.zip
  • Run STM Cube to remove read protection (and erase the device) from the STM32
    • attach the STLink V2 and connect it to the STM32
    • TODO: document, or see the Seeed page
    • NOTE: this does not erase any sigfox credentials (which is a good thing)
  • Clone my Arduino_Core_STM32 repo into ~/Arduino/hardware
 cd ~/Arduino/hardware
 mkdir -f stm32
 cd stm32
 git clone https://github.com/bertrik/Arduino_Core_STM32
 git checkout seeed_lora_e5_mini
  • Restart the Arduino IDE and select the correct board:
    • Under menu Tools/Board/STM32 boards .... (sketchbook), choose 'Generic STM32WL series' from 'Generic STM32WL series'
    • Under menu Tools/Board part number, choose 'Seeed Studios LoRa E5 mini'

Demonstration sketch

programming from the Arduino IDE

A demonstration Arduino sketch is at https://github.com/bertrik/lora-e5 :

  • blinky example, the most basic of all sketches which makes a LED blink demonstration of successful download of an Arduino program
  • helloworld example, sends a text over the serial port

Try the helloworld example:

  • Connect the LoRa E5 over serial and with an ST-Link v2 as described in https://revspace.nl/LoRa-E5-mini#Programming_over_SWD
  • Load the helloworld.ino file into the Arduino IDE:
    • Compile and upload with ctrl-U
    • See the LED flash
    • Open serial port with ctrl-shift-M and see that serial messages are coming in
    • Press the BOOT button and see the result on the serial console: it shows the result of reading the syncword registers, proving that we can communicate with the SX1262 LoRa transceiver

Node configuration in TheThingsNetwork

The information on the website of Seeed studios is outdated. It refers to the "v2" version of TheThingsNetwork, which is being phased out. It is already impossible to add new nodes on TTNv2, since it was set to read-only.

Nodes should be configured for TheThingsNetwork v3 instead.