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

Purpose of app_timer in NRF CLI library/example

Hello,

I am experimenting with the NRF CLI example (brilliant feature). I would like to integrate it with my project, which uses FreeRTOS.
I've read a few threads that suggest that it is quite difficult to integrate the CLI library with FreeRTOS (mostly because of the timer implementations).

However I noticed in the CLI library documentation (https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_cli.html#) that no timer is used.

My question is, what is the purpose of the app_timer in the NRF CLI example? Can the CLI library be used without the timer?

Thanks.

Parents
  • Hi,

    app_timer is used for running a second counter. The timer can be started/stopped/reset through CLI commands. 

    The timer library is not used within the CLI library, if you implement different commands, you can leave out the timer.

    Best regards,
    Jørgen

  • I've spent a few days on this and realized that the CLI library does in fact use a timer. I finally managed to make the CLI work perfectly alongside FreeRTOS. I'd like to write a blog post to share my solution. Where/how can I do this?
    Thanks

  • Hi TimothyA,

        Could you please kindly share how you did it? 

    Thank you,

    Min-Ching

  • Hello Min-Ching,

    I assume you've played around with the CLI example.

    If so, follow these steps:

    1. Add the relevant CLI library files to your project:
      1. <SDK location>/components/libraries/cli
      2. <SDK location>/external/fnmatch
      3. <SDK location>/components/libraries/sortlist
      4. <SDK location>/cmponents/timer/experimental
    2. Depending on the CLI backend you wish you use (RTT or UART), you need to take appropriate steps (the CLI backend and logger backend cannot be the same):
      1. If you wish to use UART as your CLI backend, then your logger cannot use UART as well. Similarly if you wish to use RTT as your CLI backend, then your logger cannot use RTT. Let me know if you need more details here. Make sure you don't call NRF_LOG_DEFAULT_BACKENDS_INIT() or ensure the CLI and logger do not share the same backend.
      2. If you are using RTT as your CLI backend, you need one more extra step - if you are using Segger Embedded Studio, you need to disable output from being routed to the Debug Terminal. To do this, open the project options -> Choose the relevant configuration (Debug, Release, or Common) -> Look for the RTT Enable option and set to No.
    3. Add the relevant cli elements in the flash_placement.xml file (Look at the CLI example flash placement file. The CLI sections you need look something like this:
      //In the FLASH memory segment
      <ProgramSection alignment="4" keep="Yes" load="Yes" name=".cli_command" inputsections="*(.cli_command*)" address_symbol="__start_cli_command" end_symbol="__stop_cli_command" />
      
      //In the RAM memory segment
      <ProgramSection alignment="4" keep="Yes" load="No" name=".cli_sorted_cmd_ptrs_run" address_symbol="__start_cli_sorted_cmd_ptrs" end_symbol="__stop_cli_sorted_cmd_ptrs" />
    4. Add the relevant defines in the sdk_config.h file. Again look at the CLI example. Look at the CLI-related defines and add them to your project. Also remember to enable NRF_QUEUE_ENABLED if it's not there already.
    5. The CLI uses app_timer2.c, and FreeRTOS uses app_timer_freertos.c. Remove app_timer_freertos.c and include app_timer2.c. app_timer2.c uses RTC1 by default, which is also the same instance used by FreeRTOS. This needs to be changed. In that file, you should find this line:
      static drv_rtc_t m_rtc_inst = DRV_RTC_INSTANCE(1);
      Change 1 to 0.
    6. Then you need to add a preprocessor directive. Add FREERTOS;APP_TIMER_V2;APP_TIMER_V2_RTC0_ENABLED to your pre-processors definitions list.
    7. In your main file, wherever you enable logging, you need to have 
      NRF_LOG_INIT(app_timer_cnt_get);
      app_timer_cnt_get is defined in app_timer2.c
    8. Finally, you need to enable the app_timer. Call 
      app_timer_init();

    I'm using SDK 15.2.0 FYI.

    Keep me posted Slight smile

    Timothy

  • Thanks for sharing. I just saw this message. I'll try it now.

  • Just another data point. I tried TimothyA's steps. It was not working for me. Instead of this, I enabled NRF_CLI_USES_TASK_MANAGER and replaced all task manager APIs with FreeRTOS APIs. This method works for me. FYI.

Reply Children
No Data
Related