Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to use libuarte+app_timer on FreeRTOS

Currently in FreeRTOS environment app_timer cannot be used for libuarte timeout.
Alternatively, it is possible to use RTC or TIMER.

I want to use UARTE0/UARTE1.
Then,  libuarte use RTC x 1, TIMER x 3.
SoftDevice use RTC x 1, TIMER x 1
FreeRTOS use RTC x 1
for a total of RTC x 3/ TIMER x 4 is required.
Only TIMER x 1 remains.

If libuarte can use app_timer for timeout, the rest is TIMER x 3.

How to use app_timer for libuarte timeout in FreeRTOS environment?

Parents
  • you need to remove app_timer.c from your project and add app_timer_freertos.c so that the app_timer API is available to your application. App_timer_freeertos.c still uses Freertos timer API so it should work ok.

  • I think there was some incompatibility issue with libuarte and app_timer_freertos.c file in the struct xLibUarteCOM0_app_timer_data but the author of the post provided a workaround for it.

  • Hi Susheel and original poster loquat,

    I came across the same issue just a few days ago. The thread which Susheel linked may not work for you. It probably works in the case where you use FreeRTOS, but still compile app_timer.c instead of app_timer_freertos.c.

    I was able to get libuarte to work with FreeRTOS and app_timer, and I think there are two approaches:

    1) If you compile your FreeRTOS project with app_timer_freertos.c, then you will need to follow this thread, look at ogulcan's reply at the bottom. This worked well for me, and I validated both TX and RX. It's a very easy workaround to keep the compiler happy.

    2) If you compile your FreeRTOS project with app_timer.c, although I'm not sure why you would do that, you can follow the thread which Susheel linked. I couldn't compile his code changes as posted, but it may be a simple fix to address that. I didn't test if this actually works.

    For either of the approaches above, make sure you have NRF_LIBUARTE_ASYNC_WITH_APP_TIMER and NRF_LIBUARTE_DRV_UARTE0 (and/or UARTE1) defined (set to 1) in your code.

    Another solution to getting libuarte to work with FreeRTOS, if you don't don't mind "wasting" another hardware RTC timer, is to use RTC2 (since RTC0 and RTC1 are taken by softdevice and FreeRTOS respectively). And finally, you can also choose to use a hardware (non-RTC) timer as well.

Reply
  • Hi Susheel and original poster loquat,

    I came across the same issue just a few days ago. The thread which Susheel linked may not work for you. It probably works in the case where you use FreeRTOS, but still compile app_timer.c instead of app_timer_freertos.c.

    I was able to get libuarte to work with FreeRTOS and app_timer, and I think there are two approaches:

    1) If you compile your FreeRTOS project with app_timer_freertos.c, then you will need to follow this thread, look at ogulcan's reply at the bottom. This worked well for me, and I validated both TX and RX. It's a very easy workaround to keep the compiler happy.

    2) If you compile your FreeRTOS project with app_timer.c, although I'm not sure why you would do that, you can follow the thread which Susheel linked. I couldn't compile his code changes as posted, but it may be a simple fix to address that. I didn't test if this actually works.

    For either of the approaches above, make sure you have NRF_LIBUARTE_ASYNC_WITH_APP_TIMER and NRF_LIBUARTE_DRV_UARTE0 (and/or UARTE1) defined (set to 1) in your code.

    Another solution to getting libuarte to work with FreeRTOS, if you don't don't mind "wasting" another hardware RTC timer, is to use RTC2 (since RTC0 and RTC1 are taken by softdevice and FreeRTOS respectively). And finally, you can also choose to use a hardware (non-RTC) timer as well.

Children
Related