Cannot stop LFCLKSTAT from BYPASS EXTERNAL XTAL

Hello, i am having a weird behaviour at a NRF52832 device. 

To explain. Basically I am using an external RTC chip to source the clock of the LFCLK. 

During the initialization I call:

      NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)|(CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos ) |
       (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos);

      NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; 
      NRF_CLOCK->TASKS_LFCLKSTART = 1;
      while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
      {//do nothing
      }

However, during an investigation of a problem explained here I realized that after a Reset from byt J-LInk during a debug session the LFCLKSTAT start already with SRC as Xtal and State as Running. If I call NRF_CLOCK->TASKS_LFCLKSTOP = 1 it will stay as running and wont stop. Also If I try to change the source of the LFCLK to RC it wont change as the LFCLKSTAT State is running. 

I could not find any ERRATA explaining about this. 

Is there any solution? Am I doing anything wrong?

Parents Reply Children
  • Hello Kenneth, 

    I tryed to disable the external clock, and still I could not stop it. 

    Any sugestions? 

    Best

  • You might have found an unknown issue then, and you can confirm this only occurs when using CLOCK_LFCLKSRC_BYPASS_Enabled? 

    Does the problem only occur when in debug session and/or when you reset from debug session?

    Does it happen for instance if you reset from watchdog or soft reset (after a power cycle, not when debug mode)?

    What happens if you allways start it with bypass enabled (even when you only want to stop it), so you first (always) start it, and then try to stop it?

    Kenneth

  • I only have checked with EXT/BYPASS enabled (i only have a full square wave ext clocK) and with internal RC. Internal RC has no problem. For now It happens evvertime even when not in a debug session. It will happen with a Soft Reset and a Debug Reset but not a Watchdog reset.

    I tryed to start with bypass enabled and stop after that and it also didn't work. 


  • Unfortunately I don't have an external clock to test with, at least not right away.

    Can you just confirm that the following code then will fail?

    Luis said:
    I tryed to start with bypass enabled and stop after that and it also didn't work. 

    int main(void)
    {
        NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)|(CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos ) |
        (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos);
    
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {//do nothing
        }
    
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    
        if(nrf_clock_lf_is_running()){
            NRF_CLOCK->TASKS_LFCLKSTOP = 1; 
            while(nrf_clock_lf_is_running())
            {}
        }
        
        while(1); // It will never reach here?
    }

    Kenneth

  • I just tested your code and it does indeed works. I don't know what I was doing wrong before. 

    So I am able to disable the external clock now with that code. 

Related