STMicroelectronics / x-cube-subg2

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.
https://www.st.com/en/embedded-software/x-cube-subg2.html
Other
5 stars 3 forks source link

S2LP Driver enters infinite loop when RcoCalibration fails #1

Closed samuelsd1 closed 2 years ago

samuelsd1 commented 2 years ago

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 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

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.

mgrella commented 2 years ago

Hi @samuelsd1 ,

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.

Best regards, Marco