Pico GPS Teseo I2C
Loading...
Searching...
No Matches
hardware_uart

Hardware UART API. More...

Macros

#define UART_NUM(uart)
 Returns the UART number for a UART instance.
 
#define UART_INSTANCE(num)
 Returns the UART instance with the given UART number.
 
#define UART_DREQ_NUM(uart, is_tx)
 Returns the dreq_num_t used for pacing DMA transfers to or from this UART instance. If is_tx is true, then it is for transfers to the UART else for transfers from the UART.
 
#define UART_CLOCK_NUM(uart)
 Returns clock_num_t of the clock for the given UART instance.
 
#define UART_FUNCSEL_NUM(uart, gpio)
 Returns gpio_function_t needed to select the UART function for the given UART instance on the given GPIO number.
 
#define UART_IRQ_NUM(uart)
 Returns the irq_num_t for processor interrupts from the given UART instance.
 
#define UART_RESET_NUM(uart)
 Returns the reset_num_t used to reset a given UART instance.
 

Enumerations

enum  uart_parity_t { UART_PARITY_NONE , UART_PARITY_EVEN , UART_PARITY_ODD }
 UART Parity enumeration. More...
 

Functions

uint uart_init (uart_inst_t *uart, uint baudrate)
 Initialise a UART.
 
void uart_deinit (uart_inst_t *uart)
 DeInitialise a UART.
 
uint uart_set_baudrate (uart_inst_t *uart, uint baudrate)
 Set UART baud rate.
 
void uart_set_format (uart_inst_t *uart, uint data_bits, uint stop_bits, uart_parity_t parity)
 Set UART data format.
 
void uart_set_fifo_enabled (uart_inst_t *uart, bool enabled)
 Enable/Disable the FIFOs on specified UART.
 
void uart_set_break (uart_inst_t *uart, bool en)
 Assert a break condition on the UART transmission.
 
void uart_set_translate_crlf (uart_inst_t *uart, bool translate)
 Set CR/LF conversion on UART.
 
bool uart_is_readable_within_us (uart_inst_t *uart, uint32_t us)
 Wait for up to a certain number of microseconds for the RX FIFO to be non empty.
 
#define uart0   ((uart_inst_t *)uart0_hw)
 Identifier for UART instance 0.
 
#define uart1   ((uart_inst_t *)uart1_hw)
 Identifier for UART instance 1.
 

Detailed Description

Hardware UART API.

RP-series microcontrollers have 2 identical instances of a UART peripheral, based on the ARM PL011. Each UART can be connected to a number of GPIO pins as defined in the GPIO muxing.

Only the TX, RX, RTS, and CTS signals are connected, meaning that the modem mode and IrDA mode of the PL011 are not supported.

Example

int main() {
// Set the GPIO pin mux to the UART - pin 0 is TX, 1 is RX; note use of UART_FUNCSEL_NUM for the general
// case where the func sel used for UART depends on the pin number
// Do this before calling uart_init to avoid losing data
// Initialise UART 0
uart_init(uart0, 115200);
uart_puts(uart0, "Hello world!");
}
int main()
#define uart0
Identifier for UART instance 0.
Definition uart.h:86
void uart_init(void)
void gpio_set_function(uint gpio, enum gpio_function fn)
Definition gpio.c:10
void uart_puts(uart_inst_t *uart, const char *s)
Definition uart.c:115
#define UART_FUNCSEL_NUM(uart, gpio)
Definition uart.h:94

Macro Definition Documentation

◆ uart0

#define uart0   ((uart_inst_t *)uart0_hw)

Identifier for UART instance 0.

The UART identifiers for use in UART functions.

e.g. uart_init(uart1, 48000)

Definition at line 86 of file uart.h.

◆ uart1

#define uart1   ((uart_inst_t *)uart1_hw)

Identifier for UART instance 1.

Definition at line 87 of file uart.h.

◆ UART_CLOCK_NUM

#define UART_CLOCK_NUM ( uart)

Returns clock_num_t of the clock for the given UART instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 166 of file uart.h.

◆ UART_DREQ_NUM

#define UART_DREQ_NUM ( uart,
is_tx )

Returns the dreq_num_t used for pacing DMA transfers to or from this UART instance. If is_tx is true, then it is for transfers to the UART else for transfers from the UART.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 152 of file uart.h.

◆ UART_FUNCSEL_NUM

#define UART_FUNCSEL_NUM ( uart,
gpio )

Returns gpio_function_t needed to select the UART function for the given UART instance on the given GPIO number.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 181 of file uart.h.

◆ UART_INSTANCE

#define UART_INSTANCE ( num)

Returns the UART instance with the given UART number.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 135 of file uart.h.

◆ UART_IRQ_NUM

#define UART_IRQ_NUM ( uart)

Returns the irq_num_t for processor interrupts from the given UART instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 196 of file uart.h.

◆ UART_NUM

#define UART_NUM ( uart)

Returns the UART number for a UART instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 122 of file uart.h.

◆ UART_RESET_NUM

#define UART_RESET_NUM ( uart)

Returns the reset_num_t used to reset a given UART instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

Definition at line 209 of file uart.h.

Enumeration Type Documentation

◆ uart_parity_t

UART Parity enumeration.

Enumerator
UART_PARITY_NONE 
UART_PARITY_EVEN 
UART_PARITY_ODD 

Definition at line 251 of file uart.h.

Function Documentation

◆ uart_deinit()

void uart_deinit ( uart_inst_t * uart)

DeInitialise a UART.

Disable the UART if it is no longer used. Must be reinitialised before being used again.

Parameters
uartUART instance. uart0 or uart1

DeInitialise a UART.

Definition at line 95 of file uart.c.

◆ uart_init()

uint uart_init ( uart_inst_t * uart,
uint baudrate )

Initialise a UART.

Put the UART into a known state, and enable it. Must be called before other functions.

This function always enables the FIFOs, and configures the UART for the following default line format:

  • 8 data bits
  • No parity bit
  • One stop bit
Note
There is no guarantee that the baudrate requested will be possible, the nearest will be chosen, and this function will return the configured baud rate.
Parameters
uartUART instance. uart0 or uart1
baudrateBaudrate of UART in Hz
Returns
Actual set baudrate

Initialise a UART.

\taguart_init[]

Definition at line 75 of file uart.c.

◆ uart_is_readable_within_us()

bool uart_is_readable_within_us ( uart_inst_t * uart,
uint32_t us )

Wait for up to a certain number of microseconds for the RX FIFO to be non empty.

Parameters
uartUART instance. uart0 or uart1
usthe number of microseconds to wait at most (may be 0 for an instantaneous check)
Returns
true if the RX FIFO became non empty before the timeout, false otherwise

Definition at line 229 of file uart.c.

◆ uart_set_baudrate()

uint uart_set_baudrate ( uart_inst_t * uart,
uint baudrate )

Set UART baud rate.

Set baud rate as close as possible to requested, and return actual rate selected.

The UART is paused for around two character periods whilst the settings are changed. Data received during this time may be dropped by the UART.

Any characters still in the transmit buffer will be sent using the new updated baud rate. uart_tx_wait_blocking() can be called before this function to ensure all characters at the old baud rate have been sent before the rate is changed.

This function should not be called from an interrupt context, and the UART interrupt should be disabled before calling this function.

Parameters
uartUART instance. uart0 or uart1
baudrateBaudrate in Hz
Returns
Actual set baudrate

Set UART baud rate.

Definition at line 155 of file uart.c.

◆ uart_set_break()

void uart_set_break ( uart_inst_t * uart,
bool en )

Assert a break condition on the UART transmission.

Parameters
uartUART instance. uart0 or uart1
enAssert break condition (TX held low) if true. Clear break condition if false.

Definition at line 210 of file uart.c.

◆ uart_set_fifo_enabled()

void uart_set_fifo_enabled ( uart_inst_t * uart,
bool enabled )

Enable/Disable the FIFOs on specified UART.

The UART is paused for around two character periods whilst the settings are changed. Data received during this time may be dropped by the UART.

Any characters still in the transmit FIFO will be lost if the FIFO is disabled. uart_tx_wait_blocking() can be called before this function to avoid this.

This function should not be called from an interrupt context, and the UART interrupt should be disabled when calling this function.

Parameters
uartUART instance. uart0 or uart1
enabledtrue to enable FIFO (default), false to disable

Definition at line 199 of file uart.c.

◆ uart_set_format()

void uart_set_format ( uart_inst_t * uart,
uint data_bits,
uint stop_bits,
uart_parity_t parity )

Set UART data format.

Configure the data format (bits etc) for the UART.

The UART is paused for around two character periods whilst the settings are changed. Data received during this time may be dropped by the UART.

Any characters still in the transmit buffer will be sent using the new updated data format. uart_tx_wait_blocking() can be called before this function to ensure all characters needing the old format have been sent before the format is changed.

This function should not be called from an interrupt context, and the UART interrupt should be disabled before calling this function.

Parameters
uartUART instance. uart0 or uart1
data_bitsNumber of bits of data. 5..8
stop_bitsNumber of stop bits 1..2
parityParity option.

Set UART data format.

Definition at line 183 of file uart.c.

◆ uart_set_translate_crlf()

void uart_set_translate_crlf ( uart_inst_t * uart,
bool translate )

Set CR/LF conversion on UART.

Parameters
uartUART instance. uart0 or uart1
translateIf true, convert line feeds to carriage return on transmissions

Definition at line 221 of file uart.c.