Bug-Fixed version of STM32WLxx SubGHz/LoRa middleware / radio_driver & HAL
Hi,
not a question but a hint for anyone working with the STM32WLE4 / STM32WLE5 / STM32WL54 / STM32WL55:
The STM32Cube libraries (both the SubGHz middleware + HAL driver) are known to have several bugs, some of which make the library unusable for some use cases, so many developers probably use fixed in-house versions.
I have attempted to fix the bugs that I know of while impacting the general structure & API as little as possible. I opened several pull requests on GitHub to get these modifications upstream, but until those are accepted, I have published fixed versions of the libraries for anyone interested.
STM32WLxx HAL Driver: https://github.com/Erlkoenig90/stm32wlxx-hal-driver
STM32WLxx SubGHz-Phy middleware: https://github.com/Erlkoenig90/stm32-mw-subghz-phy
Using in a STM32CubeMX-generated project
First, remove the two library directories generated by STM32CubeMX:
rm -r Drivers/STM32WLxx_HAL_Driver Middlewares/Third_Party/SubGHz_PhyAdd libraries as git submodules
git submodule add --branch fixes-merged https://github.com/Erlkoenig90/stm32wlxx-hal-driver.git Drivers/STM32WLxx_HAL_Driver
git submodule add --branch fixes-merged https://github.com/Erlkoenig90/stm32-mw-subghz-phy.git Middlewares/Third_Party/SubGHz_PhyEach time after re-generating the project code with STM32CubeMX, reset the submodules to un-do STM32CubeMX overwriting the fixes:
git submodule foreach bash -c "git restore :/ && git clean -fd :/"Clone libraries directly
Alternatively, clone directly without using git submodules (e.g. if you’re not using git for your project):
git clone --branch fixes-merged https://github.com/Erlkoenig90/stm32wlxx-hal-driver.git Drivers/STM32WLxx_HAL_Driver
git clone --branch fixes-merged https://github.com/Erlkoenig90/stm32-mw-subghz-phy.git Middlewares/Third_Party/SubGHz_PhyEach time after re-generating the project code with STM32CubeMX, reset the library repositories to un-do STM32CubeMX overwriting the fixes:
( cd Drivers/STM32WLxx_HAL_Driver && git restore :/ && git clean -fd :/ ) && ( cd Middlewares/Third_Party/SubGHz_Phy && git restore :/ && git clean -fd :/ )API changes
There are a few breaking changes to the API that may require modifying the application code to match:
CRC/Reception error callback & constant
The API error flag HAL_SUBGHZ_ERROR_CRC_MISMATCH is gone, as it was IMO never really useful. The callback HAL_SUBGHZ_CRCErrorCallback stays - in LoRa case it indicates CRC error, in the other modems it can indicate one of several errors, which can be checked through Get_PacketStatus()/SUBGRF_GetPacketStatus() . After the error callback, the modem driver now stays functional, so abort reception if necessary. Continuous reception will automatically resume on reception error, the next packet can be received properly. No re-start of the driver/modem necessary to clear the error.
Therefore replace checks for HAL_SUBGHZ_ERROR_CRC_MISMATCH with SUBGRF_GetPacketStatus() inside HAL_SUBGHZ_CRCErrorCallback.
constant buffers for long packet transmission in RFW
The buffer parameter to the TxLongPacketGetNextChunkCb callback (passed to Radio.TransmitLongPacket) is now const, so adjust the callback’s function definition accordingly.
You can also now pass constant buffers to Radio.Send(), i.e. also pointers into flash memory, even when the RFW module is used (when long packets and/or IBM whitening is used). The RFW module doesn’t write into the transmission buffer anymore.
Payload length API
The modem parameter to the SetMaxPayloadLength() function is gone, the function applies to the currently active modem.
For RadioSetRx[Generic]Config, the payloadLen/MaxPayloadLength parameter now actually has an effect for variable-length packets, i.e. pass the actual maximum expected length here. Longer packets will be rejected (previously all packets would be accepted if variable length was used).
The generic_param_rx_lora_t.MaxPayloadLength field is renamed to PayloadLength as it is only used for the actual length of fixed-length LoRa packets.
As the internal payload length handling has been fixed/cleaned, some workarounds in the user code can now be removed.
Optional: Use SetTxPower
Use the new Radio.SetTxPower function instead of re-configuring the modem entirely to change the transmission power “on-the-fly”.
Optional: Error callback
Define RADIO_ERROR_CB to a custom error callback for the radio_driver.
In general, if your code still compiles fine it should continue to work, otherwise check the compiler errors to find the lines to modify. Apart from the API changes, various other things should now “work better” as internal handling was improved. Check the git history for details.
