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

nrf_serial_read() timeout never triggers when called from APP_TIMER callback

Hello,

While building a custom board, I need 52832 to communicate with a modem at regular intervals, send AT commands and read modem responses. nrf_serial library in IRQ mode seems like a good choice, since it can put CPU to sleep while waiting for the response, and also support Rx timeouts.

Although nrf_serial_read() works as expected when called from the main thread, calls from APP_TIMER never return. It seems that:
1. nrf_serial_read() busy-waits and never goes to sleep,
2. serial_timeout_handler() never fires so nrf_serial_read() keeps busy waiting.

Playing with priorities didn't help much.
I am using SDK 15.2 with softdevice enabled.
Below you can find how to reproduce the problem, can you please assist?

#include "nrf_serial.h"
#include "nrf_pwr_mgmt.h"
#include "app_timer.h"

void test_serial_evt_handler(struct nrf_serial_s const *p_serial, nrf_serial_event_t event);
void test_idle_state_handle(void);

NRF_SERIAL_DRV_UART_CONFIG_DEF(test_uart0_drv_config, 
    8, 6, 0, 0,
    NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
    NRF_UART_BAUDRATE_115200, 5/*UART_DEFAULT_CONFIG_IRQ_PRIORITY*/);

NRF_SERIAL_QUEUES_DEF(test_serial_queues, 128, 128);
NRF_SERIAL_BUFFERS_DEF(test_serial_buffs, 8, 1);

NRF_SERIAL_CONFIG_DEF(test_serial_config, NRF_SERIAL_MODE_IRQ,
    &test_serial_queues, &test_serial_buffs, test_serial_evt_handler, test_idle_state_handle);

NRF_SERIAL_UART_DEF(test_serial_uart, 0);

APP_TIMER_DEF(test_Tx_timer_id);

/*
*/
void test_idle_state_handle(void) {
  nrf_pwr_mgmt_run();
}

/*
*/
void test_serial_evt_handler(struct nrf_serial_s const *p_serial, nrf_serial_event_t event) {
  // do nothing
}

/*
*/
void onTestTxTimerTick(void *data) {
  // try to read 10 bytes in the next 1 second
  uint8_t inBuf[10];
  size_t bytes_read;
  nrf_serial_read(&test_serial_uart, inBuf, sizeof(inBuf), &bytes_read, 1000);
  
  // Rx pin is unconnected, so we should return with a timeout. 
  // Unfortunatelly, we never reach this point !
}

/*
*/
void test_main() {
  APP_ERROR_CHECK(nrf_serial_init(&test_serial_uart, &test_uart0_drv_config, &test_serial_config));

  // create a 10-sec repetitive timer
  APP_ERROR_CHECK(app_timer_create(&test_Tx_timer_id, APP_TIMER_MODE_REPEATED, onTestTxTimerTick));
  APP_ERROR_CHECK(app_timer_start(test_Tx_timer_id, APP_TIMER_TICKS(10000), NULL));

  // Enter main loop.
  for (;;) {
    test_idle_state_handle();
  }
}

Thanks,

Thanos

Parents Reply Children
No Data
Related