Hi,
Using the nRF5 11.0.0 release SDK, I'm trying to set up one task to transmit to and one task to receive data from the UART. Nothing special.
The configuration block in nrf_drv_config.h
looks like:
/* UART */
#define UART0_ENABLED 1
#if (UART0_ENABLED == 1)
#define UART0_CONFIG_HWFC NRF_UART_HWFC_DISABLED
#define UART0_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED
#define UART0_CONFIG_BAUDRATE NRF_UART_BAUDRATE_115200
#define UART0_CONFIG_PSEL_TXD 26
#define UART0_CONFIG_PSEL_RXD 25
#define UART0_CONFIG_PSEL_CTS 30
#define UART0_CONFIG_PSEL_RTS 31
#define UART0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#ifdef NRF52
#define UART0_CONFIG_USE_EASY_DMA false
//Compile time flag
#define UART_EASY_DMA_SUPPORT 1
#define UART_LEGACY_SUPPORT 1
#endif //NRF52
#endif
The initialization in main() of /home/max/devsrc/minibrain/nRF5_SDK_11.0.0_89a8197/examples/ble_peripheral/ble_app_hrs_freertos/main.c
looks like:
m_uart_output_queue = xQueueCreate(10, sizeof (struct SerialPortOutput *));
if (m_uart_output_queue)
{
printf("Queue created successfully!\n");
}
else
{
printf("Queue could not be created!\n");
}
// Start execution.
if(pdPASS != xTaskCreate(ble_stack_thread, "BLE", 256, NULL, 1, &m_ble_stack_thread))
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;
if (NRF_SUCCESS == nrf_drv_uart_init(&uart_config, NULL))
{
printf("UART initialized properly.\n");
}
else
{
printf("UART failed to initialize properly.\n");
}
if (pdPASS != xTaskCreate(uart_input_task, "UART Input Task", 64, NULL, 1, &m_uart_input_thread))
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
if (pdPASS != xTaskCreate(uart_output_task, "UART Output Task", 64, NULL, 1, &m_uart_output_thread))
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
And the tasks themselves look like:
static void uart_input_task(void * arg)
{
uint8_t data[9] = {0};
nrf_drv_uart_rx_enable();
for (;;)
{
memset(data, 0, sizeof(data));
// Read UART input.
printf("Reading UART (should block until something arrives).\n");
nrf_drv_uart_rx(data, (sizeof(data) - 1));
// Second task should interrupt the blocked UART every now and then,
// since the Nordic doesn't have a UART read timeout by default.
printf("%s\n", (char *) data);
// Push UART data to input processing queue.
}
nrf_drv_uart_rx_disable();
}
struct SerialPortOutput
{
char output[32];
uint8_t length;
};
static void uart_output_task(void * arg)
{
for (;;)
{
struct SerialPortOutput * spo;
printf("uart_output_task: Waiting for data to send.\n");
// Block waiting on data in the queue.
if (xQueueReceive(m_uart_output_queue, &spo, portMAX_DELAY))
{
// Send data to UART.
// nrf_drv_uart_tx(data, length);
}
else
{
printf("uart_output_task: xQueueReceive had nothing to send.\n");
}
}
}
Unfortunately, when monitoring the debug output via RTT, I only see:
Queue created successfully!
UART initialized properly.
Hello SEGGER_RTT_WriteString().
Hello RTT-rerouted printf()
sd_ble_enable: RAM START at 0x20001FE8
Reading UART (should block until something arrives).
So it seems to be blocking after running nrf_drv_uart_rx()
in the RX task. It never preempts and runs the rest of main() or starts the TX task. I tried setting #define configUSE_TICKLESS_IDLE 0
in FreeRTOSConfig.h
but this did not help.
I also noticed some differences in port_cmsis.c
, which may have helped the nRF51 series, but may not have been ported to the nRF52? I'm unsure. (See: devzone.nordicsemi.com/.../)
Any help in solving this would be greatly appreciated.
Thanks, Max