Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Incorrect use of app_timer_create in nrf_serial.c when used with FreeRTOS

The file components/libraries/serial/nrf_serial.c in nRF5 SDK is used for UART serial tx/rx and has support for timeouts.  There appears to be a bug with use of timeouts.

When the nrf_serial_write() function is called with a non-zero timeout, app_timer_create() is called for each write.  While this is not an issue for a non-FreeRTOS system (since it's possible to call app_timer_create multiple times for the one timer), this results in a failure when compiled with FreeRTOS.  app_timer_create should only be called once during initialisation of the nrf_serial module, not repeatedly for every write.

The attached patch makes the following modifications:

  • Create UART timer once only when nrf_serial is initialised.  All calls to nrf_serial_write() will reuse the time created during initialisation.
  • Use correct #defines when choosing whether to use easyDMA.  #define values modified to match the #defines used by the nrfxxx_peripherals.h headers.

These bugs exist in nRF5 SDK 15.0.0.  The UART timer bug also exists in at least nRF5 SDK 14.2.0 and possibly in earlier releases.

nrf_serial.c.patch

Related