X-CUBE-SUBG2 is an expansion software package for STM32Cube. The software runs on the STM32 and includes drivers that recognize the Sub-1 GHz RF communication for S2-LP.
BSP: S2868A2 (Reproduces more often on custom S2-LP boards)
IDE: STM32CubeIDE 1.7
The board is connected to the S2-LP devkit through jumper cables, as described:
Digital Interface:
A1 (PA1) -> SPI_CLK (CN9-4)
A5 (PA6) -> SPI_MISO (CN5-5)
A6 (PA7) -> SPI_MOSI (CN5-4)
D3 (PB0) -> S2LP_SPI_CSN (CN8-2)
A3 (PA4) -> SDN (CN9-8)
D6 (PB1) -> GPIO3 (CN8-6)
Additional connections
VCC (3v3) -> S2LP_VIN (CN6-4)
GND -> S2LP_GND (CN6-7, CN5-7)
[S2868A2 only] VCC (3v3) -> EEPROM_CSN (CN9-6).
_I do not use the EEPROM functionality, so EEPROMCSN has to be pulled up.
The bug
S2LP Driver code enters infinite loop when RcoCalibration fails.
The reason is the S2LP_RcoCalibration function, located in s2lp.c.
The function does not check the case of RCO calibration error.
According to the datasheet, when RcoCalibration fails, the ERROR_LOCK bit in MC_STATE1 register is set.
Currently, the S2LP_RcoCalibration function waits until the RC_CAL_OK bit is set, without checking the ERROR_LOCK bit.
Therefore, when the RCO calibration fails, the function does not exit the loop.
How To Reproduce the bug
The bug occurs in software, following a hardware error, so it is slightly tricky to reproduce.
From my experience, the hardware error occurs once in a while, so to reproduce it I reset the Nucleo devkit using reset button, until the hardware error occured - which was followed by the software getting stuck.
Additional context
Global behavior of my application project: simple P2P sender and receiver, used to develop high level driver for S2LP.
Modules that cause the problem: S2LP driver, in the S2LP_RcoCalibration function.
Use case that generates the problem: S2LP initialization using driver code.
In my implementation - I created a function in the high-level driver that replaces the S2LP_RcoCalibration function, which checks the case of RCO calibration failure, and returns an error code accordingly.
To make my high level driver stable - in case of failure, I started again the whole process of initialization (incluiding resetting S2LP using the SDN pin), for about 10 times.
From experimenting, I noticed the maximal amount of times the error has repeated itself was 4.
Therefore, my code tries to initialize S2LP in a for loop for 10 times until it has success, otherwise it returns failure - which should be dealt with by the driver user.
thank you very much for you detailed investigation!
We'll check your proposed fix (that seems actually ok at a first glance) with the driver team and provide a reply asap.
Setup
The board is connected to the S2-LP devkit through jumper cables, as described:
Digital Interface:
Additional connections
The bug
S2LP Driver code enters infinite loop when RcoCalibration fails. The reason is the
S2LP_RcoCalibration
function, located ins2lp.c
. The function does not check the case of RCO calibration error.According to the datasheet, when RcoCalibration fails, the
ERROR_LOCK
bit inMC_STATE1
register is set. Currently, theS2LP_RcoCalibration
function waits until theRC_CAL_OK
bit is set, without checking theERROR_LOCK
bit. Therefore, when the RCO calibration fails, the function does not exit the loop.How To Reproduce the bug The bug occurs in software, following a hardware error, so it is slightly tricky to reproduce. From my experience, the hardware error occurs once in a while, so to reproduce it I reset the Nucleo devkit using reset button, until the hardware error occured - which was followed by the software getting stuck.
Additional context
S2LP_RcoCalibration
function.In my implementation - I created a function in the high-level driver that replaces the
S2LP_RcoCalibration
function, which checks the case of RCO calibration failure, and returns an error code accordingly.To make my high level driver stable - in case of failure, I started again the whole process of initialization (incluiding resetting S2LP using the SDN pin), for about 10 times.
From experimenting, I noticed the maximal amount of times the error has repeated itself was 4. Therefore, my code tries to initialize S2LP in a for loop for 10 times until it has success, otherwise it returns failure - which should be dealt with by the driver user.
I will soon create a pull request with a patch.