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
  • Hello,

    Do you by any chance have watchdog enabled in your application? When using watchdog a soft reset through the debugger is not sufficient to clear the watchdog, and the watchdog will likely prevent any change to the LFCLK source.

    If that is not the problem I suggest to check out the following two errata's:

    https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev3/ERR/nRF52832/Rev3/latest/anomaly_832_132.html 
    https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev3/ERR/nRF52832/Rev3/latest/anomaly_832_36.html 

    Kenneth

  • Hello Kenneth, 

    In this specific test I already disabled the Watchdog. I run this right in the begin of my software

        int watchdog_is_running = 0;
        watchdog_is_running = NRF_WDT->RUNSTATUS;
        printf("WatchDog Status: %d\n", watchdog_is_running);
    
    ////EXT CLOCK
    
    
          if(nrf_clock_lf_is_running()){
            NRF_CLOCK->TASKS_LFCLKSTOP = 1; 
            while(nrf_clock_lf_is_running())
            {}
          }

    The watchdog_is_running returns 0 (so watchdog is not running) but the while(nrf_clock_lf_is_running()) never returns after the stop.

    This is somehting I see after reseting the firmware and I previously started the LFCLK as following. 

    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
    }

     Any other ideas? Would you be able to replicate it?

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

Reply Children
No Data
Related