It took a lot of time for trying, testing, debugging, but finally I managed to create a plain and simple LoraWan LowPower Library for STM32. Especially for the STM32L051C8T6 microcontroller in an example project.
Based on the MiniPill LoRa board the sleep current is reduces to 1.4 uA and this current is also drawn during RX1_delay and RX2_delay and RX1_join_delay. So minimal power is used during lifetime.
The other feature is that the code does not use Real Time OS like the LMIC code. Just straight Arduino (OOP) code. And many comments are added to explain the working and functions of the code.
The code is now under long term testing with CR2032 and LR44 batteries. You will get this information as soon as it is available.
Due to the fact that there is no crystal used for both system clock and RTC, there is a slight problem on getting the timing correct in sleep mode. In this mode the RTC clock is used to wake up again. Due to the LoRa protocol you have to wake up after 1 or 5 seconds (RX1/RX2 window and RX1_Join and RX2_Join window) and this time must me quite precise.
To solve this problem I programmed a Wrapper for the STM32LowPower library called STM32LowPowerCal. This wrapper library allows you to calibrate the RTC timer with the higher speed internal system clock. I’ve tested this with 5 different MiniPill boards and it worked!. You have also the possibility to correct this calibration if it is not correct for your board.
With this new code and in this example board it is easy to debug. All output is send to the serial port uart2 at 9600 baud. You can enable low-level debugging so you can see LoRaWAN in action while you are testing. The Nordic Power Profiler Kit II was a great help in debugging and to check and set the timing parameters for this project.
You can receive downlink messages with this code, and simple ADR messages are replied. Not all ADR messages are implemented, but the most basic is.
Here I show the flow diagram of the example projects. Check out the calibration fase after booting this device.
Example Projects with PSLL
Here are the two example projects. The first one is plain without sensor, just sending static data. The second one is an example with BME280 sensor.
This is the repository for adding the STM32L051/STM32L151 MiniPill LoRa board and link to the MiniPill LoRa board article.