LFCLK init problem

Hi,

Out of testing large number of boards, observed one board is not working. When tried to debug, found this weird problem. Code is stuck in LFCLK init part.

main() {

lfclk_config();

}

void lfclk_config(void)
{
if (!nrf_drv_clock_init_check())
{
ret_code_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
}

if (!nrf_drv_clock_lfclk_is_running())
{
nrf_drv_clock_lfclk_request(NULL);
while(!nrf_drv_clock_lfclk_is_running())   // Line 10
{
idle_state_handle(); //Stuck here
}
}
}

Please find the following observations.

  1. It works in debugging mode, does not work in standalone mode
  2. LF clk source is external crystal
  3. changed line 10, while(!nrf_drv_clock_lfclk_is_running()) to  while(NRF_CLOCK->LFCLKSTAT & 0x10000 == 0)  --> It worked
  4. changed line 10, while(!nrf_drv_clock_lfclk_is_running()) to  while((NRF_CLOCK->LFCLKSTAT & 0x10000) == 0)  --> added braces, not working Sob 
  5. Problem exist in all optimization levels
  6. checked with the following code. It stops working when braces are added as mentioned in point 4.

    nrf_drv_clock_init();
    NRF_CLOCK->INTENSET = 2;
    NRF_CLOCK->LFCLKSRC = 1;
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;

    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while((NRF_CLOCK->LFCLKSTAT & 0x10000) == 0) //does not work with braces
    {
    idle_state_handle();
    }

Any suggestion how to find out the root cause for the issue ?

Parents Reply Children
No Data
Related