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.

  • well you are, in that image, in the SWI interrupt handler, you've just chosen to show the code which sets the interrupt flag instead of the code you're actually running. Do you have an SWI interrupt handler?

  • I think this interrupt is being caused by the LFCLK. If I don't start LFCLK, it never gets to this interrupt handler. If I start the LFCLK and comment the timer it still gets to this interrupt handler. So it looks like everything is pointing to the LFCLK not being set up/started correctly. It might have something to do with calibration not being set-up and so the LFCLK stopping in short order. I can't seem to start the calibration with nrf_drv_clock_calibration_start(10 ,clock_handler), but nor can I use nrf_drv_clock_lfclk_request() either.

  • it won't be anything to do with calibration - either the LF clock is started or it isn't started. There's no 'half started' or 'not started correctly'. I did suggest you checked the registers to see what source has been selected and what source it claims is actually running. But this is the LF clock off the RC source, there's no way it can't run.

    If you had a priority inversion you'd be in the hardfault handler (the timer and SWI have to have the same priority or it doesn't work).

    The LF clock is running, calibration is a total red herring, you have a different problem which you just need to find.

  • You are right. So I copied over an sdk_config.h file from another project as the sdk_config.h for the Radio Test is an extremely pared down version, so I might not have added/activated all the correct modules. So now I can start the LFCLK and the app will continue to run without any issues UNTIL I go to start the timer and then I fall back into that interrupt handler so I still need to troubleshoot. Now Radio Test example has

    NVIC_EnableIRQ(TIMER0_IRQn);
    __enable_irq();
    

    Could this be interfering with the app_timers by any chance?

  • Mystery solved, hadn't removed Cortex_M_Startup.s from the SES project. Oh well, lesson for all SES users out there - double check you've set the project up correctly!

Related