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: fix infinite loop on rco calibration error #2

Closed samuelsd1 closed 2 years ago

samuelsd1 commented 2 years ago

Modified the signiature of the S2LP_RcoCalibration method to return int32_t instead of void, at s2lp.h and s2lp.c.

Changed the do-while loop which waits for the RCCAL_OK bit to be set, so the loop body now checks the value of the ERROR_LOCK bit, and returns an error code if the bit is set. Accordingly, modified the function to return S2LP_OK when it is done and no error was detected.

In addition, to clean up the code, I changed the way of querying the MC_STATE register: Instead of using S2LP_ReadRegister to directly read the MC_STATE1 register, I used the S2LP_RefreshStatus to read the update into the global state variable g_xStatus, and then used it to get the value of ERROR_LOCK and RCCAL_OK bits. I believe this change makes the code cleaner.

At last, I fixed formatting in the function:

Fixes: https://github.com/STMicroelectronics/x-cube-subg2/issues/1

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