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

RC LFCLK and App Timer without SoftDevice SDK13

I am taking the Radio Test example and introducing a button and LED for control over the various tests. However I have struck an issue in trying to call the LFCLK when it is RC and getting the timers to work.

The Radio Test uses the HFCLK as well. When this is started I then try to start the LFCLK but at this point the app freezes.

I define the CLOCK_CONFIG_LF_SRC as RC

#define CLOCK_CONFIG_LF_SRC  0;

My lfclk config is

static void lfclk_config(void)
{
   uint32_t err_code = nrf_drv_clock_init();
   APP_ERROR_CHECK(err_code);

   nrf_drv_clock_lfclk_request(NULL);
    
   nrf_drv_clock_calibration_start(10 ,clock_handler);
}

I added the clock module to the sdk_config.h as follows

// <e> CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver
//==========================================================
#ifndef CLOCK_ENABLED
#define CLOCK_ENABLED 1
#endif
#if  CLOCK_ENABLED
// <o> CLOCK_CONFIG_XTAL_FREQ  - HF XTAL Frequency
 
// <0=> Default (64 MHz) 

#ifndef CLOCK_CONFIG_XTAL_FREQ
#define CLOCK_CONFIG_XTAL_FREQ 0
#endif

// <o> CLOCK_CONFIG_LF_SRC  - LF Clock Source
 
// <0=> RC 
// <1=> XTAL 
// <2=> Synth 

#ifndef CLOCK_CONFIG_LF_SRC
#define CLOCK_CONFIG_LF_SRC 0
#endif

// <o> CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority
 

// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 

#ifndef CLOCK_CONFIG_IRQ_PRIORITY
#define CLOCK_CONFIG_IRQ_PRIORITY 7
#endif

In lfclk_config() the err_code on init is 0. However it is nrf_drv_clock_lfclk_request() where I think it becomes unstuck. The code will run the next line or two but will stop fairly quickly. If nrf_drv_clock_lfclk_request() is not called, then the code runs but of course my timers or the app_button does not work but everything else does. I took a look at the documentation and the RTC example in the SDK but this seems to be based on there being an XTAL which I don't have. Presumably I am not configuring the source correctly, but any help would be appreciated.

EDITED: Added call stack png

radiotest.png

UPDATE: LFCLK appears to run initially but app_timer does not start

Having started the LFCLK I am now having an issue with app_timer_start() so something is not quite right yet. Looking at app_timer.c it seems to be hanging on timer_list_handler_sched(). Here is an image. This may be caused by the LFCLK stopping (possibly due to calibration not running?).

radiotest2.png

I got success for both app_timer_init() and app_timer_create() for this particular timer. I have never seen this issue when the LFCLK is started through the Soft Device.

Parents
  • I scrapped the method above and used:

    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        // Do nothing.
    }
    

    which is kind of how the Radio Test example starts the HFCLK and this appears to work in that I now get a 1 for nrf_drv_clock_lfclk_is_running();. However now I appear to have an issue with the timers, I'll edit the question above.

Reply
  • I scrapped the method above and used:

    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        // Do nothing.
    }
    

    which is kind of how the Radio Test example starts the HFCLK and this appears to work in that I now get a 1 for nrf_drv_clock_lfclk_is_running();. However now I appear to have an issue with the timers, I'll edit the question above.

Children
No Data
Related