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

Possible bug in nrf52832 LFCLK

[Bug Report] Possible bug in nRF52832 engineering release B. When LF XTAL oscillator is started, no event is generated.

NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)   { };      // STUCK HERE FOREVER!!

The oscillator is actually started but no event is generated.

  • I had to look that up and check that DSB (and DMB) explicitly wait for the Cortex M4 internal write buffer to clear before returning and yes they do, so that should be equivalent, yes. It might be good to put that into the 'functional changes' document for the nRF52, I think that's a better, more generic way of ensuring write synchronisation than the write-then-read method listed there and is better to learn in general.

    If you really want to test if it is due to the write buffer causing the issue, and whether DMB() fixes it, it would be better to move the EVENTS_LFCLKSTARTED = 0 before the LFCLKSRC set as that one extra write may hide the issue all on its own.

    I still don't know if it is the write buffer or not, it's just a suspicion.

  • I agree that EVENT_LFCLKSTARTED = 0 should be moved to up to test if this a buffer issue. I have not seen the funtional change document for nRF52, should be in the infocenter, i will read it and see if it needs any improvements. Thanks for pointing that out.

  • Should have linked to it, it's this one. It's a great redux of the major differences between the nRF51 and nRF52 processors.

    Hopefully now the original poster can test out a few of these solutions and see if it points to the issue, which is quite odd.

  • Thanks for valuable comments. I got it working by using the following code:

    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    __DSB();
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
    }
    

    Weird thing is that now I can't get it to non-functional any more. At the moment I only have one specimen to test. I will use the code above because don't want to get burned with this.

  • Then RK got it right, it was for sure a write buffer issue. Good that it worked. I have created an internal ticket to update the functional changes document to use memory barriers. Hopefully infocenter will be updated soon.

    If there is nothing else to do in this thread then can you please accept my updated answer by clicking ✓ on the left side of it so other see this thread as Green.

Related