This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

softdevice_handler_init(...) Hangs with bad crystal

I'm using SDK 7.1, SD310 2.0.1, MCP 3.8.0.7

I have two versions of a board with the nRF51. Some of them have the 32kHz crystal and some don't. In my application I have a #define that tells the application to use either: NRF_CLOCK_LFCLKSRC_XTAL_20_PPM or NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION

I had to had the #define, because it seems the stack hangs, waiting for the crystal to start. If there's no crystal it won't start. Is there anyway to get the stack to return an error instead of hanging if there's no crystal?

The idea would be call softdevice_handler_init() with NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, if the crystal doesn't start, the stack returns an error, and then I call softdevice_handler_init() with NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION - and let nRF51run on the internal oscillator.

This would prevent me from having to to have two support separate versions of my app - one that uses the crystal and one that doesn't.

Parents
  • Before you get near the softdevice init, start the LFCLOCK yourself telling it to use a crystal. Wait a reasonable amount of time with any delay method you like, see if the LF clock has started. if it has, you have a crystal, if it hasn't, you don't have one. Then you stop it again, whether it's running or not, and now you know which parameter to call your softdevice start with.

    if you were feeling really efficient, you could write the answer into one of the customer pieces of UICR after you've tested this the first time, and then you can just use that value directly on all subsequent startups and never have to test it again.

Reply
  • Before you get near the softdevice init, start the LFCLOCK yourself telling it to use a crystal. Wait a reasonable amount of time with any delay method you like, see if the LF clock has started. if it has, you have a crystal, if it hasn't, you don't have one. Then you stop it again, whether it's running or not, and now you know which parameter to call your softdevice start with.

    if you were feeling really efficient, you could write the answer into one of the customer pieces of UICR after you've tested this the first time, and then you can just use that value directly on all subsequent startups and never have to test it again.

Children
No Data
Related