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.
- It works in debugging mode, does not work in standalone mode
- LF clk source is external crystal
- changed line 10, while(!nrf_drv_clock_lfclk_is_running()) to while(NRF_CLOCK->LFCLKSTAT & 0x10000 == 0) --> It worked
- changed line 10, while(!nrf_drv_clock_lfclk_is_running()) to while((NRF_CLOCK->LFCLKSTAT & 0x10000) == 0) --> added braces, not working
- Problem exist in all optimization levels
- 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 ?