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

Configure System Clock Faster than 32768Hz in NCS/Zephyr

It looks to me that in NCS/Zephyr it is only possible to configure the system clock to operate off of the LFCLK. I haven't been able to find any Kconfig options that would make the HFCLK the source of the clock. It is very important to our application that we be able to meet tight timing requirements, especially in some proprietary wired protocols. There must be a way to increase the system clock frequency. Help!

I've tried:

1) CONFIG_TICKLESS_KERNEL=y (only decreases frequency)

2) CONFIG_SYS_CLOCK_TICKS_PER_SEC=16000000 (anything above 32768 results in a fault)

3) CONFIG_CLOCK_CONTROL=y
    CONFIG_CLOCK_CONTROL_NRF=y
    And enabling the HFCLK, but this did not improve the situation. How do I even use it?

4) CLOCK_CONTROL_NRF_SOURCE only has options that select different versions of the LFCLK. ie.
        4.1) CLOCK_CONTROL_NRF_K32SRC_XTAL
        4.2) CLOCK_CONTROL_NRF_K32SRC_RC etc.

My code:

#include <zephyr.h>
#include <sys/printk.h>

void main()
{
    uint32_t times[10] = {0};
    for (int i = 0; i < 10; i++)
    {
        times[i] = k_cyc_to_us_floor32(k_cycle_get_32());
        k_usleep(1);
    }
    for (int i = 1; i < 10; i++)
    {
        printk("%luus\n", times[i] - times[i-1]);
    }
}


Output:

122us

92us

91us

92us

91us

92us

91us

92us

91us

(These are all multiples of 30.5us, which is a single clock tick of the LFCLK)

  • Hi,

     

    Timing in zephyr rtos kernel runs off the 32.768 kHz RTC, as you have already found out. There is no backend for NRF_TIMERx, so in order to get a better resolution, you have to create a module using nrfx_timer driver for instance. Note that this will raise the base current from sub 10 uA to ~800 uA (HFXO, see these specifications), as the high-speed NRF_TIMER peripheral will require the peripheral clock tree to run in sleep mode.

     

    Kind regards,

    Håkon

Related