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

nrf9160dk: using HFCLK with Zephyr SDK

I wanted to use HFCLK for the nrf9160 in nrf9160DK board. I am using the latest nrf SDK and tried the below Kconfig entries, but no luck,

CONFIG_NRF_RTC_TIMER=n
CONFIG_CORTEX_M_SYSTICK=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=64000000
CONFIG_SYS_CLOCK_TICKS_PER_SEC=64000000

Command for compilation: west build -b nrf9160dk_nrf9160ns

I am able to compile and run hello_world samples, but not other samples or custom application.

Console log:

*** Booting Zephyr OS build v2.4.0-ncs1-rc2-2-g98e1132f8ade  ***                                                                                              
Flash regions           Domain          Permissions                                                                                                           
00 00 0x00000 0x08000   Secure          rwxl                                                                                                                  
01 31 0x08000 0x100000  Non-Secure      rwxl                                                                                                                  
                                                                                                                                                              
Non-secure callable region 0 placed in flash region 0 with size 32.

SRAM region             Domain          Permissions
00 07 0x00000 0x10000   Secure          rwxl
08 31 0x10000 0x40000   Non-Secure      rwxl

Peripheral              Domain          Status
00 NRF_P0               Non-Secure      OK
01 NRF_CLOCK            Non-Secure      OK
02 NRF_RTC0             Non-Secure      OK
03 NRF_RTC1             Non-Secure      OK
04 NRF_NVMC             Non-Secure      OK
05 NRF_UARTE1           Non-Secure      OK
06 NRF_UARTE2           Secure          SKIP
07 NRF_TWIM2            Non-Secure      OK
08 NRF_SPIM3            Non-Secure      OK
09 NRF_TIMER0           Non-Secure      OK
10 NRF_TIMER1           Non-Secure      OK
11 NRF_TIMER2           Non-Secure      OK
12 NRF_SAADC            Non-Secure      OK
13 NRF_PWM0             Non-Secure      OK
14 NRF_PWM1             Non-Secure      OK
15 NRF_PWM2             Non-Secure      OK
16 NRF_PWM3             Non-Secure      OK
17 NRF_WDT              Non-Secure      OK
18 NRF_IPC              Non-Secure      OK
19 NRF_VMC              Non-Secure      OK
20 NRF_FPU              Non-Secure      OK
21 NRF_EGU1             Non-Secure      OK
22 NRF_EGU2             Non-Secure      OK
23 NRF_DPPIC            Non-Secure      OK
24 NRF_GPIOTE1          Non-Secure      OK
25 NRF_REGULATORS       Non-Secure      OK

SPM: NS image at 0xc000
SPM: NS MSP at 0x20027d60
SPM: NS reset vector at 0xfc15
SPM: prepare to jump to Non-Secure image.

Parents
  • Hi parthitce,

    I am going to focus on this first:

    I am able to compile and run hello_world samples, but not other samples or custom application.

    Did you use the nrf connect for desktop Toolchain Manager app to install NCS v1.4.0 or are you using git and west pulling from master?
    Is this statement related to Kconfig edits? 


    To clarify:
    Are you not able to build and run any other applications then hello_world when you edit the kconfig file?

    If you describe your end goal and use case then it might be easier to propose solutions

    Regards,
    Jonathan

  • I am using NRF Zephyr SDK and toolchain. I did clone and compile based on : https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html

    Use case:

    I have an application logic which needs multiple timers for managing various interface reading over modbus TCP. For example, I have 5 timers out of which 3 of them expires periodically every 10 seconds and remaining 2 at 20 seconds interval (implemented using https://docs.zephyrproject.org/latest/reference/kernel/timing/timers.html). I have a general timer (other than the 5) which runs at the lowest timer expiration value of all 5 and scans on all the 5 timers whether it's expired or not using k_timer_status_get. So I expect to see all 5 of them expires every 20 seconds.

    As timer callback is in ISR context and I have a work thread which offloads all the primary interface reading. So every time the timer expires, the work is submitted and scheduled to offload. In the specific example above, during the 20 second interval, I wanted to process all 5 of them. But what I observed is, not all of them aren't expiring at the exact same time (k_timer_status_get).

    So the idea is to process all the expired timers in work thread and read the interfaces.

    I did try to compile and flash the hello_world example and it works with 64MHz clock. But not any other sample, like multi thread or mqtt.

    static void reader_work(struct k_work *w)
    {
            SYS_SLIST_FOR_EACH_CONTAINER(&gt->aq, aq, node) {
                    if (k_timer_status_get(&aq->param.sec) > 0) {
                        /* application logic here */
                        
                        /* restart the timer */
                        k_timer_start(&aq->param.timer, K_SECONDS(aq->param.sec), K_NO_WAIT);
                    }
            }
    }
    
    K_WORK_DEFINE(reader, reader_work);
    static void periodic_reader(struct k_timer *t)
    {
            k_work_submit(&reader);
    }
    
    void main(void) {
            SYS_SLIST_FOR_EACH_CONTAINER(&x->aq, aq, node) {
                    if (period > aq->param.sec)
                            period = aq->param.sec;
    
                    k_timer_init(&aq->param.timer, NULL, NULL);
                    k_timer_start(&aq->param.timer, K_SECONDS(aq->param.sec), K_NO_WAIT);
            }
    
            k_timer_init(&reader, periodic_reader, NULL);
            k_timer_start(&reader, K_SECONDS(period), K_SECONDS(period));
    }

    I am expecting all the 5 timers to expire inside the worker thread. In reality there could be 100 timers in my use case.

    My observation with the above logic is that the resolution of the timer is based on RTC at 32KHz. I would like to check the same logic with 64MHz clock (HFCLK). But enabling it leaving the target not booting.

  • Hi,

    CONFIG_SYS_CLOCK_TICKS_PER_SEC is not able to go to 64MHz, maybe try  32768
    https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_SYS_CLOCK_TICKS_PER_SEC.html 


    Do you need Nano second accuracy?

    Regards,
    Jonathan

  • Good day , No I am not trying to get nano second resolution. As in the above example, if I set 10 timers expiring at the same time (eg. 20 seconds), I don't see all of them not expiring at 20 seconds.

    I have even tried with `k_timer_remaining_get` to filter within the margin of 100 mill seconds but no luck still. This means that I am not getting even millisecond resolution.

    > CONFIG_SYS_CLOCK_TICKS_PER_SEC is not able to go to 64MHz, maybe try  32768

    This means nrf9160 timer can't run at 64Mhz or in other words it can run only at 32868Hz?

Reply
  • Good day , No I am not trying to get nano second resolution. As in the above example, if I set 10 timers expiring at the same time (eg. 20 seconds), I don't see all of them not expiring at 20 seconds.

    I have even tried with `k_timer_remaining_get` to filter within the margin of 100 mill seconds but no luck still. This means that I am not getting even millisecond resolution.

    > CONFIG_SYS_CLOCK_TICKS_PER_SEC is not able to go to 64MHz, maybe try  32768

    This means nrf9160 timer can't run at 64Mhz or in other words it can run only at 32868Hz?

Children
Related