nRF5 SDK v15.0.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
UART driver - legacy layer

Layer providing compatibility with the former API. More...

Modules

 UART/UARTE peripheral driver - legacy layer configuration
 

Data Structures

struct  nrf_drv_uart_t
 Structure for the UART driver instance. More...
 
struct  nrf_drv_uart_config_t
 Structure for UART configuration. More...
 
struct  nrf_drv_uart_xfer_evt_t
 Structure for UART transfer completion event. More...
 
struct  nrf_drv_uart_error_evt_t
 Structure for UART error event. More...
 
struct  nrf_drv_uart_event_t
 Structure for UART event. More...
 

Macros

#define NRF_DRV_UART_INSTANCE(id)
 Macro for creating an UART driver instance. More...
 
#define NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA
 
#define NRF_DRV_UART_DEFAULT_CONFIG
 UART default configuration. More...
 

Typedefs

typedef void(* nrf_uart_event_handler_t )(nrf_drv_uart_event_t *p_event, void *p_context)
 UART interrupt event handler. More...
 

Enumerations

enum  nrf_drv_uart_evt_type_t {
  NRF_DRV_UART_EVT_TX_DONE,
  NRF_DRV_UART_EVT_RX_DONE,
  NRF_DRV_UART_EVT_ERROR
}
 Types of UART driver events. More...
 

Functions

ret_code_t nrf_drv_uart_init (nrf_drv_uart_t const *p_instance, nrf_drv_uart_config_t const *p_config, nrf_uart_event_handler_t event_handler)
 Function for initializing the UART driver. More...
 
__STATIC_INLINE void nrf_drv_uart_uninit (nrf_drv_uart_t const *p_instance)
 Function for uninitializing the UART driver. More...
 
__STATIC_INLINE uint32_t nrf_drv_uart_task_address_get (nrf_drv_uart_t const *p_instance, nrf_uart_task_t task)
 Function for getting the address of a specific UART task. More...
 
__STATIC_INLINE uint32_t nrf_drv_uart_event_address_get (nrf_drv_uart_t const *p_instance, nrf_uart_event_t event)
 Function for getting the address of a specific UART event. More...
 
__STATIC_INLINE ret_code_t nrf_drv_uart_tx (nrf_drv_uart_t const *p_instance, uint8_t const *const p_data, uint8_t length)
 Function for sending data over UART. More...
 
__STATIC_INLINE bool nrf_drv_uart_tx_in_progress (nrf_drv_uart_t const *p_instance)
 Function for checking if UART is currently transmitting. More...
 
__STATIC_INLINE void nrf_drv_uart_tx_abort (nrf_drv_uart_t const *p_instance)
 Function for aborting any ongoing transmission. More...
 
__STATIC_INLINE ret_code_t nrf_drv_uart_rx (nrf_drv_uart_t const *p_instance, uint8_t *p_data, uint8_t length)
 Function for receiving data over UART. More...
 
__STATIC_INLINE bool nrf_drv_uart_rx_ready (nrf_drv_uart_t const *p_instance)
 Function for testing the receiver state in blocking mode. More...
 
__STATIC_INLINE void nrf_drv_uart_rx_enable (nrf_drv_uart_t const *p_instance)
 Function for enabling the receiver. More...
 
__STATIC_INLINE void nrf_drv_uart_rx_disable (nrf_drv_uart_t const *p_instance)
 Function for disabling the receiver. More...
 
__STATIC_INLINE void nrf_drv_uart_rx_abort (nrf_drv_uart_t const *p_instance)
 Function for aborting any ongoing reception. More...
 
__STATIC_INLINE uint32_t nrf_drv_uart_errorsrc_get (nrf_drv_uart_t const *p_instance)
 Function for reading error source mask. Mask contains values from nrf_uart_error_mask_t. More...
 

Detailed Description

Layer providing compatibility with the former API.

Macro Definition Documentation

#define NRF_DRV_UART_DEFAULT_CONFIG
Value:
{ \
.pseltxd = NRF_UART_PSEL_DISCONNECTED, \
.pselrxd = NRF_UART_PSEL_DISCONNECTED, \
.pselcts = NRF_UART_PSEL_DISCONNECTED, \
.pselrts = NRF_UART_PSEL_DISCONNECTED, \
.p_context = NULL, \
.interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY, \
NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA \
}

UART default configuration.

#define NRF_DRV_UART_INSTANCE (   id)
Value:
{ \
.inst_idx = id, \
NRF_DRV_UART_CREATE_UARTE(id) \
NRF_DRV_UART_CREATE_UART(id) \
}

Macro for creating an UART driver instance.

Typedef Documentation

typedef void(* nrf_uart_event_handler_t)(nrf_drv_uart_event_t *p_event, void *p_context)

UART interrupt event handler.

Parameters
[in]p_eventPointer to event structure. Event is allocated on the stack so it is available only within the context of the event handler.
[in]p_contextContext passed to interrupt handler, set on initialization.

Enumeration Type Documentation

Types of UART driver events.

Enumerator
NRF_DRV_UART_EVT_TX_DONE 

Requested TX transfer completed.

NRF_DRV_UART_EVT_RX_DONE 

Requested RX transfer completed.

NRF_DRV_UART_EVT_ERROR 

Error reported by UART peripheral.

Function Documentation

__STATIC_INLINE uint32_t nrf_drv_uart_errorsrc_get ( nrf_drv_uart_t const *  p_instance)

Function for reading error source mask. Mask contains values from nrf_uart_error_mask_t.

Note
Function should be used in blocking mode only. In case of non-blocking mode, an error event is generated. Function clears error sources after reading.
Parameters
[in]p_instancePointer to the driver instance structure.
Return values
Maskof reported errors.
__STATIC_INLINE uint32_t nrf_drv_uart_event_address_get ( nrf_drv_uart_t const *  p_instance,
nrf_uart_event_t  event 
)

Function for getting the address of a specific UART event.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]eventEvent.
Returns
Event address.
ret_code_t nrf_drv_uart_init ( nrf_drv_uart_t const *  p_instance,
nrf_drv_uart_config_t const *  p_config,
nrf_uart_event_handler_t  event_handler 
)

Function for initializing the UART driver.

This function configures and enables UART. After this function GPIO pins are controlled by UART.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configInitial configuration.
[in]event_handlerEvent handler provided by the user. If not provided driver works in blocking mode.
Return values
NRFX_SUCCESSIf initialization was successful.
NRFX_ERROR_INVALID_STATEIf driver is already initialized.
__STATIC_INLINE ret_code_t nrf_drv_uart_rx ( nrf_drv_uart_t const *  p_instance,
uint8_t *  p_data,
uint8_t  length 
)

Function for receiving data over UART.

If an event handler was provided in the nrf_drv_uart_init() call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, i.e. this function returns when the transfer is finished. Blocking mode is not using interrupt so there is no context switching inside the function. The receive buffer pointer is double buffered in non-blocking mode. The secondary buffer can be set immediately after starting the transfer and will be filled when the primary buffer is full. The double buffering feature allows receiving data continuously.

Note
Peripherals using EasyDMA (i.e. UARTE) require that the transfer buffers are placed in the Data RAM region. If they are not and UARTE driver instance is used, this function will fail with error code NRFX_ERROR_INVALID_ADDR.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_dataPointer to data.
[in]lengthNumber of bytes to receive.
Return values
NRFX_SUCCESSIf initialization was successful.
NRFX_ERROR_BUSYIf the driver is already receiving (and the secondary buffer has already been set in non-blocking mode).
NRFX_ERROR_FORBIDDENIf the transfer was aborted from a different context (blocking mode only, also see nrf_drv_uart_rx_disable).
NRFX_ERROR_INTERNALIf UART peripheral reported an error.
NRFX_ERROR_INVALID_ADDRIf p_data does not point to RAM buffer (UARTE only).
__STATIC_INLINE void nrf_drv_uart_rx_abort ( nrf_drv_uart_t const *  p_instance)

Function for aborting any ongoing reception.

Note
NRF_DRV_UART_EVT_RX_DONE event will be generated in non-blocking mode. The event will contain the number of bytes received until abort was called. The event is called from UART interrupt context.
Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE void nrf_drv_uart_rx_disable ( nrf_drv_uart_t const *  p_instance)

Function for disabling the receiver.

This function must be called to close the receiver after it has been explicitly enabled by

See Also
nrf_drv_uart_rx_enable. The feature is supported only in UART mode (without Easy DMA). The function asserts if mode is wrong.
Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE void nrf_drv_uart_rx_enable ( nrf_drv_uart_t const *  p_instance)

Function for enabling the receiver.

UART has a 6-byte-long RX FIFO and it is used to store incoming data. If a user does not call the UART receive function before the FIFO is filled, an overrun error will appear. Enabling the receiver without specifying an RX buffer is supported only in UART mode (without Easy DMA). The receiver must be explicitly closed by the user

See Also
nrf_drv_uart_rx_disable. This function asserts if the mode is wrong.
Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE bool nrf_drv_uart_rx_ready ( nrf_drv_uart_t const *  p_instance)

Function for testing the receiver state in blocking mode.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueIf the receiver has at least one byte of data to get.
falseIf the receiver is empty.
__STATIC_INLINE uint32_t nrf_drv_uart_task_address_get ( nrf_drv_uart_t const *  p_instance,
nrf_uart_task_t  task 
)

Function for getting the address of a specific UART task.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]taskTask.
Returns
Task address.
__STATIC_INLINE ret_code_t nrf_drv_uart_tx ( nrf_drv_uart_t const *  p_instance,
uint8_t const *const  p_data,
uint8_t  length 
)

Function for sending data over UART.

If an event handler was provided in nrf_drv_uart_init() call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, i.e. this function returns when the transfer is finished. Blocking mode is not using interrupt so there is no context switching inside the function.

Note
Peripherals using EasyDMA (i.e. UARTE) require that the transfer buffers are placed in the Data RAM region. If they are not and UARTE instance is used, this function will fail with error code NRFX_ERROR_INVALID_ADDR.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_dataPointer to data.
[in]lengthNumber of bytes to send.
Return values
NRFX_SUCCESSIf initialization was successful.
NRFX_ERROR_BUSYIf driver is already transferring.
NRFX_ERROR_FORBIDDENIf the transfer was aborted from a different context (blocking mode only, also see nrf_drv_uart_rx_disable).
NRFX_ERROR_INVALID_ADDRIf p_data does not point to RAM buffer (UARTE only).
__STATIC_INLINE void nrf_drv_uart_tx_abort ( nrf_drv_uart_t const *  p_instance)

Function for aborting any ongoing transmission.

Note
NRF_DRV_UART_EVT_TX_DONE event will be generated in non-blocking mode. Event will contain number of bytes sent until abort was called. If Easy DMA is not used event will be called from the function context. If Easy DMA is used it will be called from UART interrupt context.
Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE bool nrf_drv_uart_tx_in_progress ( nrf_drv_uart_t const *  p_instance)

Function for checking if UART is currently transmitting.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueIf UART is transmitting.
falseIf UART is not transmitting.
__STATIC_INLINE void nrf_drv_uart_uninit ( nrf_drv_uart_t const *  p_instance)

Function for uninitializing the UART driver.

Parameters
[in]p_instancePointer to the driver instance structure.

Documentation feedback | Developer Zone | Subscribe | Updated