Basic UART Example
Echo characters received on a UART
- SDK directory:
API Features Demonstrated
This app works on:
Requirements and Prerequisites
Requires a Gecko OS evaluation board, such as a WGM160P_eval.
Other Gecko OS hardware can also be used by changing the source of the logged data to suit your device.
The app configures the UART and echoes characters received on the UART. Keys typed into a Gecko OS terminal are echoed back to the terminal.
Connect a serial terminal application to the Gecko OS device UART.
The terminal application should be set to match the Gecko OS app configuration:
- Baud: 115200
- Data bits: 8
- Parity: None
- Stop bits: 1
- Flow control: Disabled
On running the app displays on the Gecko OS terminal:
>UART App Ready. Type something ...
Each character you type appears on the terminal.
- Sets up a UART configuration and a UART buffer.
- Calls gos_event_enable_irq_events to enable IRQ events
- Configures the UART with a call to gos_uart_configure
- note that this example uses a UART IRQ callback, which executes in the hardware IRQ context. This has high priority and must contain simple code that does not block. See main.c, uart_rx_callback. The function
uart_rx_callbackissues the event
uart_rx_event_handlerto shift more complex processing into the App thread context, as follows:
gos_event_issue(uart_rx_event_handler, NULL, GOS_EVENT_FLAGS1(FROM_IRQ))
See also: Execution Context, Hardware IRQ.
- calls gos_uart_peek_bytes to determine the bytes available.
- calls gos_uart_receive_bytes to buffer received bytes in
- calls gos_uart_transmit_bytes to transmit the contents of
- calls gos_uart_set_rx_callback with a
NULLcallback function to deregister the callback and clean up.