AnsweredAssumed Answered

flexio uart  driver for freertos

Question asked by michals on Jul 26, 2018

Here is my implementation of FreeRTOS driver for FLEXIO UART drvier. This is tested on MKL17Zxxx controller. It requires a patch to the fsl_flexio_uart.c to fix a bug in that driver (as shown on the previous post). If you use this code in your project please let me know if you find any bugs.

 

Here is a sample way to use the driver.

 

#define FLEXIO_UART_TX_PIN 6U // FLEXIO_D06
#define FLEXIO_UART_RX_PIN 7U // FLEXIO_D07
#define FLEXIO_CLOCK_FREQUENCY 4000000U // 4MHz to allow timer_div < 255

 

static flexio_uart_rtos_handle_t g_handle;
static flexio_uart_handle_t g_t_handle;

static uint8_t g_background_buffer[32]; // used by g_rtos_config struct

 

static struct _flexio_uart_rtos_config g_rtos_config = {
.flexio_uart.flexioBase = FLEXIO, /*!< FLEXIO UART base address */
.flexio_uart.TxPinIndex = FLEXIO_UART_TX_PIN,
.flexio_uart.RxPinIndex = FLEXIO_UART_RX_PIN,
.srcclk = FLEXIO_CLOCK_FREQUENCY, /*!< UART source clock in Hz*/
.baudrate = 9600U, /*!< Desired communication speed */
.bitCountPerChar = kFLEXIO_UART_8BitsPerChar, /*!< number of bits, 7/8/9 -bit */
.buffer = g_background_buffer, /*!< Buffer for background reception */
.buffer_size = sizeof(g_background_buffer) /*!< Size of buffer for background reception */
};

 

void task(void *pvParameters)

{

status_t result;

size_t size_not_used;

 

if ( (result=FLEXIO_UART_RTOS_Init(&g_handle, &g_t_handle, &g_rtos_config)) != kStatus_Success)
{
SEGGER_RTT_WriteString(0,"Task init failed.\n");

vTaskSuspend(NULL);

}

 

if ((result=FLEXIO_UART_RTOS_Send(&g_handle, g_tx_cmd_read_result, sizeof(g_tx_cmd_read_result))) != kStatus_Success)
{
SEGGER_RTT_WriteString(0, "Write cmd failed (send error %d).\r\n", result);
vTaskSuspend(NULL);
}

if ((result = FLEXIO_UART_RTOS_Receive(&g_handle, g_buffer, 2, &not_used)) != kStatus_Success) // get two bytes

{
SEGGER_RTT_WriteString(0, "Read cmd failed (receive error %d).\r\n", result);
vTaskSuspend(NULL);
}

Outcomes