Microchip® Advanced Software Framework

Initializing the FreeRTOS USART

driver for asynchronous operation

This example configures the FreeRTOS USART driver to:

  • Support simultaneous access from multiple RTOS tasks.
  • Exit the FreeRTOS transmit function as soon as the transmission is started.

If the driver is initialized with this configuration then only the freertos_usart_write_packet_async() API function can be used to transmit data. freertos_usart_write_packet() 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_usart_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.
// 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. Note in this case the
// WAIT_TX_COMPLETE flag is *not* used.
};
// The RS232 configuration. This structure, and the values used in its
// setting, are from the standard ASF USART driver.
const sam_usart_opt_t usart_settings =
{
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 USART specific FreeRTOS ASF driver initialization function,
// storing the return value as the driver handle.
freertos_usart = freertos_usart_serial_init(usart_base, &usart_settings,
&driver_options);