libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
UART Defines

Defined Constants and Types for the NRF52xx UART More...

Collaboration diagram for UART Defines:

Modules

 UART instance
 
 UART interrupt sources
 

Macros

#define UART_TASK_STARTRX(uart)   MMIO32((uart) + 0x000)
 
#define UART_TASK_STOPRX(uart)   MMIO32((uart) + 0x004)
 
#define UART_TASK_STARTTX(uart)   MMIO32((uart) + 0x008)
 
#define UART_TASK_STOPTX(uart)   MMIO32((uart) + 0x00C)
 
#define UART_TASK_SUSPEND(uart)   MMIO32((uart) + 0x01C)
 
#define UART_EVENT_CTS(uart)   MMIO32((uart) + 0x100)
 
#define UART_EVENT_NCTS(uart)   MMIO32((uart) + 0x104)
 
#define UART_EVENT_RXDRDY(uart)   MMIO32((uart) + 0x108)
 
#define UART_EVENT_TXDRDY(uart)   MMIO32((uart) + 0x11C)
 
#define UART_EVENT_ERROR(uart)   MMIO32((uart) + 0x124)
 
#define UART_EVENT_RXTO(uart)   MMIO32((uart) + 0x144)
 
#define UART_INTEN(uart)   _PERIPH_INTEN(uart)
 
#define UART_INTENSET(uart)   _PERIPH_INTENSET(uart)
 
#define UART_INTENCLR(uart)   _PERIPH_INTENCLR(uart)
 
#define UART_ERRORSRC(uart)   MMIO32((uart) + 0x480)
 
#define UART_ENABLE(uart)   MMIO32((uart) + 0x500)
 
#define UART_PSELRTS(uart)   MMIO32((uart) + 0x508)
 
#define UART_PSELTXD(uart)   MMIO32((uart) + 0x50C)
 
#define UART_PSELCTS(uart)   MMIO32((uart) + 0x510)
 
#define UART_PSELRXD(uart)   MMIO32((uart) + 0x514)
 
#define UART_RXD(uart)   MMIO32((uart) + 0x518)
 
#define UART_TXD(uart)   MMIO32((uart) + 0x51C)
 
#define UART_BAUDRATE(uart)   MMIO32((uart) + 0x524)
 
#define UART_CONFIG(uart)   MMIO32((uart) + 0x56C)
 
#define UART_ERRORSRC_OVERRUN   (1 << 0)
 
#define UART_ERRORSRC_PARITY   (1 << 1)
 
#define UART_ERRORSRC_FRAMING   (1 << 2)
 
#define UART_ERRORSRC_BREAK   (1 << 3)
 
#define UART_ENABLE_ENABLED   (4)
 
#define UART_ENABLE_DISABLED   (0)
 
#define UART_CONFIG_HWFC   (1)
 
#define UART_CONFIG_PARITY   (7 << 1)
 
#define UART_PSEL_OFF   (0xff)
 
#define UART_MAX_PIN   (31)
 
#define UART_PSEL_VAL(p)   (p <= UART_MAX_PIN ? (uint32_t) p : 0xffffffff)
 

Enumerations

enum  uart_baud {
  UART_BAUD_1200 = 0x0004F000 , UART_BAUD_2400 = 0x0009D000 , UART_BAUD_4800 = 0x0013B000 , UART_BAUD_9600 = 0x00275000 ,
  UART_BAUD_14400 = 0x003B0000 , UART_BAUD_19200 = 0x004EA000 , UART_BAUD_28800 = 0x0075F000 , UART_BAUD_38400 = 0x009D5000 ,
  UART_BAUD_57600 = 0x00EBF000 , UART_BAUD_76800 = 0x013A9000 , UART_BAUD_115200 = 0x01D7E000 , UART_BAUD_230400 = 0x03AFB000 ,
  UART_BAUD_250000 = 0x04000000 , UART_BAUD_460800 = 0x075F7000 , UART_BAUD_921600 = 0x0EBEDFA4 , UART_BAUD_1M = 0x10000000
}
 

Functions

void uart_enable (uint32_t uart)
 Enable the peripheral. More...
 
void uart_disable (uint32_t uart)
 Disable the peripheral. More...
 
void uart_configure (uint32_t uart, uint32_t txd, uint32_t rxd, uint32_t rts, uint32_t cts, enum uart_baud br, bool enable_parity)
 Configure UART parameters in single call. More...
 
void uart_set_baudrate (uint32_t uart, enum uart_baud br)
 
void uart_set_parity (uint32_t uart, int parity)
 
void uart_set_flow_control (uint32_t uart, int flow)
 
void uart_send_stop (uint32_t uart)
 
void uart_start_tx (uint32_t uart)
 
void uart_stop_tx (uint32_t uart)
 
void uart_send (uint32_t uart, uint16_t byte)
 
void uart_start_rx (uint32_t uart)
 
void uart_stop_rx (uint32_t uart)
 
uint16_t uart_recv (uint32_t uart)
 
void uart_set_pins (uint32_t uart, uint32_t rx, uint32_t tx, uint32_t cts, uint32_t rts)
 Select GPIO pins to be used by this peripheral. More...
 

Detailed Description

Defined Constants and Types for the NRF52xx UART

Version
1.0.0
Date
Nov 2021

LGPL License Terms libopencm3 License

Author
© 2016 Maxim Sloyko maxim.nosp@m.s@go.nosp@m.ogle..nosp@m.com
© 2021 Eduard Drusa <ventyl86 at netkosice dot sk>

Macro Definition Documentation

◆ UART_BAUDRATE

#define UART_BAUDRATE (   uart)    MMIO32((uart) + 0x524)

Definition at line 75 of file common/uart.h.

◆ UART_CONFIG

#define UART_CONFIG (   uart)    MMIO32((uart) + 0x56C)

Definition at line 76 of file common/uart.h.

◆ UART_CONFIG_HWFC

#define UART_CONFIG_HWFC   (1)

Definition at line 99 of file common/uart.h.

◆ UART_CONFIG_PARITY

#define UART_CONFIG_PARITY   (7 << 1)

Definition at line 100 of file common/uart.h.

◆ UART_ENABLE

#define UART_ENABLE (   uart)    MMIO32((uart) + 0x500)

Definition at line 68 of file common/uart.h.

◆ UART_ENABLE_DISABLED

#define UART_ENABLE_DISABLED   (0)

Definition at line 98 of file common/uart.h.

◆ UART_ENABLE_ENABLED

#define UART_ENABLE_ENABLED   (4)

Definition at line 97 of file common/uart.h.

◆ UART_ERRORSRC

#define UART_ERRORSRC (   uart)    MMIO32((uart) + 0x480)

Definition at line 67 of file common/uart.h.

◆ UART_ERRORSRC_BREAK

#define UART_ERRORSRC_BREAK   (1 << 3)

Definition at line 95 of file common/uart.h.

◆ UART_ERRORSRC_FRAMING

#define UART_ERRORSRC_FRAMING   (1 << 2)

Definition at line 94 of file common/uart.h.

◆ UART_ERRORSRC_OVERRUN

#define UART_ERRORSRC_OVERRUN   (1 << 0)

Definition at line 92 of file common/uart.h.

◆ UART_ERRORSRC_PARITY

#define UART_ERRORSRC_PARITY   (1 << 1)

Definition at line 93 of file common/uart.h.

◆ UART_EVENT_CTS

#define UART_EVENT_CTS (   uart)    MMIO32((uart) + 0x100)

Definition at line 55 of file common/uart.h.

◆ UART_EVENT_ERROR

#define UART_EVENT_ERROR (   uart)    MMIO32((uart) + 0x124)

Definition at line 59 of file common/uart.h.

◆ UART_EVENT_NCTS

#define UART_EVENT_NCTS (   uart)    MMIO32((uart) + 0x104)

Definition at line 56 of file common/uart.h.

◆ UART_EVENT_RXDRDY

#define UART_EVENT_RXDRDY (   uart)    MMIO32((uart) + 0x108)

Definition at line 57 of file common/uart.h.

◆ UART_EVENT_RXTO

#define UART_EVENT_RXTO (   uart)    MMIO32((uart) + 0x144)

Definition at line 60 of file common/uart.h.

◆ UART_EVENT_TXDRDY

#define UART_EVENT_TXDRDY (   uart)    MMIO32((uart) + 0x11C)

Definition at line 58 of file common/uart.h.

◆ UART_INTEN

#define UART_INTEN (   uart)    _PERIPH_INTEN(uart)

Definition at line 64 of file common/uart.h.

◆ UART_INTENCLR

#define UART_INTENCLR (   uart)    _PERIPH_INTENCLR(uart)

Definition at line 66 of file common/uart.h.

◆ UART_INTENSET

#define UART_INTENSET (   uart)    _PERIPH_INTENSET(uart)

Definition at line 65 of file common/uart.h.

◆ UART_MAX_PIN

#define UART_MAX_PIN   (31)

Definition at line 103 of file common/uart.h.

◆ UART_PSEL_OFF

#define UART_PSEL_OFF   (0xff)

Definition at line 102 of file common/uart.h.

◆ UART_PSEL_VAL

#define UART_PSEL_VAL (   p)    (p <= UART_MAX_PIN ? (uint32_t) p : 0xffffffff)

Definition at line 104 of file common/uart.h.

◆ UART_PSELCTS

#define UART_PSELCTS (   uart)    MMIO32((uart) + 0x510)

Definition at line 71 of file common/uart.h.

◆ UART_PSELRTS

#define UART_PSELRTS (   uart)    MMIO32((uart) + 0x508)

Definition at line 69 of file common/uart.h.

◆ UART_PSELRXD

#define UART_PSELRXD (   uart)    MMIO32((uart) + 0x514)

Definition at line 72 of file common/uart.h.

◆ UART_PSELTXD

#define UART_PSELTXD (   uart)    MMIO32((uart) + 0x50C)

Definition at line 70 of file common/uart.h.

◆ UART_RXD

#define UART_RXD (   uart)    MMIO32((uart) + 0x518)

Definition at line 73 of file common/uart.h.

◆ UART_TASK_STARTRX

#define UART_TASK_STARTRX (   uart)    MMIO32((uart) + 0x000)

Definition at line 47 of file common/uart.h.

◆ UART_TASK_STARTTX

#define UART_TASK_STARTTX (   uart)    MMIO32((uart) + 0x008)

Definition at line 49 of file common/uart.h.

◆ UART_TASK_STOPRX

#define UART_TASK_STOPRX (   uart)    MMIO32((uart) + 0x004)

Definition at line 48 of file common/uart.h.

◆ UART_TASK_STOPTX

#define UART_TASK_STOPTX (   uart)    MMIO32((uart) + 0x00C)

Definition at line 50 of file common/uart.h.

◆ UART_TASK_SUSPEND

#define UART_TASK_SUSPEND (   uart)    MMIO32((uart) + 0x01C)

Definition at line 51 of file common/uart.h.

◆ UART_TXD

#define UART_TXD (   uart)    MMIO32((uart) + 0x51C)

Definition at line 74 of file common/uart.h.

Enumeration Type Documentation

◆ uart_baud

enum uart_baud
Enumerator
UART_BAUD_1200 
UART_BAUD_2400 
UART_BAUD_4800 
UART_BAUD_9600 
UART_BAUD_14400 
UART_BAUD_19200 
UART_BAUD_28800 
UART_BAUD_38400 
UART_BAUD_57600 
UART_BAUD_76800 
UART_BAUD_115200 
UART_BAUD_230400 
UART_BAUD_250000 
UART_BAUD_460800 
UART_BAUD_921600 
UART_BAUD_1M 

Definition at line 107 of file common/uart.h.

Function Documentation

◆ uart_configure()

void uart_configure ( uint32_t  uart,
uint32_t  tx_pin,
uint32_t  rx_pin,
uint32_t  rts_pin,
uint32_t  cts_pin,
enum uart_baud  br,
bool  enable_parity 
)

Configure UART parameters in single call.

Any pin number can be set to 0xff (or any number larger than UART_MAX_PIN) to disconnect that pin.

Parameters
[in]uartuint32_t uart base
[in]tx_pinuint8_t TX pin number
[in]rx_pinuint8_t RX pin number
[in]rts_pinuint8_t RTS pin number
[in]cts_pinuint8_t CTS pin number
[in]brenum uart_baud baud rate
[in]enable_paritybool If true, enable parity bit

Definition at line 67 of file uart.c.

References UART_CONFIG, UART_CONFIG_HWFC, UART_CONFIG_PARITY, UART_MAX_PIN, uart_set_baudrate(), and uart_set_pins().

Here is the call graph for this function:

◆ uart_disable()

void uart_disable ( uint32_t  uart)

Disable the peripheral.

Parameters
[in]uartuint32_t uart base

Definition at line 49 of file uart.c.

References UART_ENABLE, and UART_ENABLE_DISABLED.

◆ uart_enable()

void uart_enable ( uint32_t  uart)

Enable the peripheral.

Parameters
[in]uartuint32_t uart base

Definition at line 40 of file uart.c.

References UART_ENABLE, and UART_ENABLE_ENABLED.

◆ uart_recv()

uint16_t uart_recv ( uint32_t  uart)

Definition at line 161 of file uart.c.

References UART_RXD.

◆ uart_send()

void uart_send ( uint32_t  uart,
uint16_t  byte 
)

Definition at line 146 of file uart.c.

References UART_TXD.

◆ uart_send_stop()

void uart_send_stop ( uint32_t  uart)

◆ uart_set_baudrate()

void uart_set_baudrate ( uint32_t  uart,
enum uart_baud  br 
)

Definition at line 126 of file uart.c.

References UART_BAUDRATE.

Referenced by uart_configure().

Here is the caller graph for this function:

◆ uart_set_flow_control()

void uart_set_flow_control ( uint32_t  uart,
int  flow 
)

Definition at line 136 of file uart.c.

References UART_CONFIG, and UART_CONFIG_HWFC.

◆ uart_set_parity()

void uart_set_parity ( uint32_t  uart,
int  parity 
)

Definition at line 131 of file uart.c.

References UART_CONFIG, and UART_CONFIG_PARITY.

◆ uart_set_pins()

void uart_set_pins ( uint32_t  uart,
uint32_t  rx,
uint32_t  tx,
uint32_t  cts,
uint32_t  rts 
)

Select GPIO pins to be used by this peripheral.

This needs to be configured while UART peripheral is disabled.

Parameters
[in]uartuart peripheral base.
[in]rxRX pin. Use GPIO defines in GPIO Pin Identifiers or GPIO_UNCONNECTED if signal shall not be connected to any pin.
[in]txTX pin. Use GPIO defines in GPIO Pin Identifiers or GPIO_UNCONNECTED if signal shall not be connected to any pin.
[in]ctsCTS pin. Use GPIO defines in GPIO Pin Identifiers or GPIO_UNCONNECTED if signal shall not be connected to any pin.
[in]rtsRTS pin. Use GPIO defines in GPIO Pin Identifiers or GPIO_UNCONNECTED if signal shall not be connected to any pin.

Definition at line 97 of file uart.c.

References __GPIO2PIN, GPIO_UNCONNECTED, UART_PSELCTS, UART_PSELRTS, UART_PSELRXD, and UART_PSELTXD.

Referenced by uart_configure().

Here is the caller graph for this function:

◆ uart_start_rx()

void uart_start_rx ( uint32_t  uart)

Definition at line 156 of file uart.c.

References PERIPH_TRIGGER_TASK, and UART_TASK_STARTRX.

◆ uart_start_tx()

void uart_start_tx ( uint32_t  uart)

Definition at line 141 of file uart.c.

References PERIPH_TRIGGER_TASK, and UART_TASK_STARTTX.

◆ uart_stop_rx()

void uart_stop_rx ( uint32_t  uart)

Definition at line 166 of file uart.c.

References PERIPH_TRIGGER_TASK, and UART_TASK_STOPRX.

◆ uart_stop_tx()

void uart_stop_tx ( uint32_t  uart)

Definition at line 151 of file uart.c.

References PERIPH_TRIGGER_TASK, and UART_TASK_STOPTX.