Microchip® Advanced Software Framework

Initializing the FreeRTOS UART

driver for standard operation

This example configures the FreeRTOS UART driver to:

  • Support simultaneous access from multiple RTOS tasks.
  • Wait in the FreeRTOS transmit function until all the data has been completely sent

Other FreeRTOS tasks will execute during any wait period.

If the driver is initialized with this configuration then only the freertos_uart_write_packet() API function can be used to transmit data. freertos_uart_write_packet_async() must not be used.

Refer to the FreeRTOS peripheral control projects in the Atmel ASF distribution for complete working examples, and the FreeRTOS web site for information on getting started with FreeRTOS.

// Declare the variables used as parameters to the
// freertos_uart_serial_init() function.
// Declare a buffer to be used as the UART receive DMA buffer. The FreeRTOS
// peripheral control drivers manage this buffer, and use it as a circular
// buffer.
uint8_t receive_buffer[BUFFER_SIZE];
// Handle used to access the initialized port by other FreeRTOS ASF functions.
freertos_uart_if freertos_uart;
// Configuration structure.
// This peripheral has full duplex asynchronous operation, so the
// receive_buffer value is set to a valid buffer location (declared
// above).
// receive_buffer_size is set to the size, in bytes, of the buffer
// pointed to by the receive_buffer value.
// The interrupt priority. The FreeRTOS driver provides the interrupt
// service routine, and handles all interrupt interactions. The
// application writer does not need to provide any interrupt handling
// code, but does need to specify the priority of the DMA interrupt here.
// IMPORTANT!!! see <a href="http://www.freertos.org/RTOS-Cortex-M3-M4.html">how to set interrupt priorities to work with FreeRTOS</a>
0x0e,
// The operation_mode value.
// Flags set to allow access from multiple tasks, and to wait in the
// transmit function until the transmit is complete. Note that other
// FreeRTOS tasks will execute during the wait period.
};
// The RS232 configuration. This structure, and the values used in its
// setting, are from the standard ASF UART driver.
const sam_uart_opt_t uart_settings =
{
UART_BAUD_RATE,
US_MR_CHRL_8_BIT,
US_MR_PAR_NO,
US_MR_NBSTOP_1_BIT,
US_MR_CHMODE_NORMAL,
0 // Only used in IrDA mode, so all values are ignored.
};
// Call the UART specific FreeRTOS ASF driver initialization function,
// storing the return value as the driver handle.
freertos_uart = freertos_uart_serial_init(uart_base, &uart_settings,
&driver_options);