UARTE driver
- group nrfx_uarte
UARTE peripheral driver.
Defines
-
NRFX_UARTE_INSTANCE(id)
Macro for creating a UARTE driver instance.
-
NRFX_UARTE_DEFAULT_CONFIG(_pin_tx, _pin_rx)
UARTE driver default configuration.
This configuration sets up UARTE with the following options:
hardware flow control disabled
no parity bit
one stop bit
baudrate: 115200
- Parameters:
_pin_tx – [in] TX pin.
_pin_rx – [in] RX pin.
-
NRFX_UARTE_INST_HANDLER_GET(idx)
Macro returning UARTE interrupt handler.
param[in] idx UARTE index.
- Returns:
Interrupt handler.
Typedefs
-
typedef void (*nrfx_uarte_event_handler_t)(nrfx_uarte_event_t const *p_event, void *p_context)
UARTE interrupt event handler.
- Param p_event:
[in] Pointer to event structure. Event is allocated on the stack so it is available only within the context of the event handler.
- Param p_context:
[in] Context passed to the interrupt handler, set on initialization.
Enums
Functions
-
nrfx_err_t nrfx_uarte_init(nrfx_uarte_t const *p_instance, nrfx_uarte_config_t const *p_config, nrfx_uarte_event_handler_t event_handler)
Function for initializing the UARTE driver.
This function configures and enables UARTE. After this function GPIO pins are controlled by UARTE.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_config – [in] Pointer to the structure with the initial configuration.
event_handler – [in] Event handler provided by the user. If not provided driver works in blocking mode.
- Return values:
NRFX_SUCCESS – Initialization was successful.
NRFX_ERROR_INVALID_STATE – Driver is already initialized.
NRFX_ERROR_BUSY – Some other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.
-
nrfx_err_t nrfx_uarte_reconfigure(nrfx_uarte_t const *p_instance, nrfx_uarte_config_t const *p_config)
Function for reconfiguring the UARTE driver.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_config – [in] Pointer to the structure with the configuration.
- Return values:
NRFX_SUCCESS – Reconfiguration was successful.
NRFX_ERROR_BUSY – The driver is during transfer.
NRFX_ERROR_INVALID_STATE – The driver is uninitialized.
-
void nrfx_uarte_uninit(nrfx_uarte_t const *p_instance)
Function for uninitializing the UARTE driver.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
-
NRFX_STATIC_INLINE uint32_t nrfx_uarte_task_address_get(nrfx_uarte_t const *p_instance, nrf_uarte_task_t task)
Function for getting the address of the specified UARTE task.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
task – [in] Task.
- Returns:
Task address.
-
NRFX_STATIC_INLINE uint32_t nrfx_uarte_event_address_get(nrfx_uarte_t const *p_instance, nrf_uarte_event_t event)
Function for getting the address of the specified UARTE event.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
event – [in] Event.
- Returns:
Event address.
-
nrfx_err_t nrfx_uarte_tx(nrfx_uarte_t const *p_instance, uint8_t const *p_data, size_t length, uint32_t flags)
Function for sending data over UARTE.
If an event handler is provided in nrfx_uarte_init() call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, that is 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 (including UARTE) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code NRFX_ERROR_INVALID_ADDR.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_data – [in] Pointer to data.
length – [in] Number of bytes to send. Maximum possible length is dependent on the used SoC (see the MAXCNT register description in the Product Specification). The driver checks it with assertion.
flags – [in] Transfer options (0 for default settings).
- Return values:
NRFX_SUCCESS – Initialization was successful.
NRFX_ERROR_BUSY – Driver is already transferring.
NRFX_ERROR_FORBIDDEN – The transfer was aborted from a different context (blocking mode only).
NRFX_ERROR_INVALID_ADDR – p_data does not point to RAM buffer.
-
bool nrfx_uarte_tx_in_progress(nrfx_uarte_t const *p_instance)
Function for checking if UARTE is currently transmitting.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
- Return values:
true – The UARTE is transmitting.
false – The UARTE is not transmitting.
-
nrfx_err_t nrfx_uarte_tx_abort(nrfx_uarte_t const *p_instance, bool sync)
Function for aborting any ongoing transmission.
Note
NRFX_UARTE_EVT_TX_DONE event will be generated in non-blocking mode. It will contain number of bytes sent until the abort was called. The event handler will be called from the UARTE interrupt context.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
sync – [in] For future use.
- Return values:
NRFX_SUCCESS – Successfully initiated abort.
-
nrfx_err_t nrfx_uarte_rx(nrfx_uarte_t const *p_instance, uint8_t *p_data, size_t length)
Function for receiving data over UARTE.
If an event handler is provided in the nrfx_uarte_init() call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, that is 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 (including UARTE) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function fails with the error code NRFX_ERROR_INVALID_ADDR.
Warning
When the double-buffering feature is used and the UARTE interrupt is processed with a delay (for example, due to a higher priority interrupt) long enough for both buffers to get filled completely, the event handler will be invoked only once, to notify that the first buffer has been filled. This is because from hardware perspective it is impossible to deduce in such case if the second buffer was also filled completely or not. To prevent this from happening, keep the UARTE interrupt latency low or use large enough reception buffers.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_data – [in] Pointer to data.
length – [in] Number of bytes to receive. Maximum possible length is dependent on the used SoC (see the MAXCNT register description in the Product Specification). The driver checks it with assertion.
- Return values:
NRFX_SUCCESS – Initialization is successful.
NRFX_ERROR_BUSY – The driver is already receiving (and the secondary buffer has already been set in non-blocking mode).
NRFX_ERROR_FORBIDDEN – The transfer is aborted from a different context (blocking mode only).
NRFX_ERROR_INTERNAL – The UARTE peripheral reports an error.
NRFX_ERROR_INVALID_ADDR – p_data does not point to RAM buffer.
-
nrfx_err_t nrfx_uarte_rx_ready(nrfx_uarte_t const *p_instance, size_t *p_rx_amount)
Function for testing the receiver state in blocking mode.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_rx_amount – [out] For future use.
- Return values:
NRFX_SUCCESS – The receiving operation is completed.
NRFX_ERROR_BUSY – The receiver did not complete the operation.
-
nrfx_err_t nrfx_uarte_rx_abort(nrfx_uarte_t const *p_instance, bool disable_all, bool sync)
Function for aborting any ongoing reception.
Note
NRFX_UARTE_EVT_RX_DONE event will be generated in non-blocking mode. It will contain number of bytes received until the abort was called. The event handler will be called from the UARTE interrupt context.
Warning
When the double-buffering feature is used and the UARTE interrupt is processed with a delay (for example, due to a higher priority interrupt) long enough for the first buffer to be filled completely, the event handler will be supplied with the pointer to the first buffer and the number of bytes received in the second buffer. This is because from hardware perspective it is impossible to deduce the reception of which buffer has been aborted. To prevent this from happening, keep the UARTE interrupt latency low or use large enough reception buffers.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
disable_all – [in] For future use.
sync – [in] For future use.
- Return values:
NRFX_SUCCESS – Successfully initiated abort.
-
uint32_t nrfx_uarte_errorsrc_get(nrfx_uarte_t const *p_instance)
Function for reading error source mask. Mask contains values from nrf_uarte_error_mask_t.
Note
Function must be used in the blocking mode only. In case of non-blocking mode, an error event is generated. Function clears error sources after reading.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
- Returns:
Mask of reported errors.
-
struct nrfx_uarte_t
- #include <nrfx_uarte.h>
Structure for the UARTE driver instance.
-
struct nrfx_uarte_config_t
- #include <nrfx_uarte.h>
Structure for the UARTE configuration.
Public Members
-
uint32_t txd_pin
TXD pin number.
-
uint32_t rxd_pin
RXD pin number.
-
uint32_t rts_pin
RTS pin number.
-
uint32_t cts_pin
CTS pin number.
-
void *p_context
Context passed to interrupt handler.
-
nrf_uarte_baudrate_t baudrate
Baud rate.
-
uint8_t interrupt_priority
Interrupt priority.
-
nrf_uarte_config_t config
Peripheral configuration.
-
bool skip_gpio_cfg
Skip GPIO configuration of pins.
When set to true, the driver does not modify any GPIO parameters of the used pins. Those parameters are supposed to be configured externally before the driver is initialized.
-
bool skip_psel_cfg
Skip pin selection configuration.
When set to true, the driver does not modify pin select registers in the peripheral. Those registers are supposed to be set up externally before the driver is initialized.
Note
When both GPIO configuration and pin selection are to be skipped, the structure fields that specify pins can be omitted, as they are ignored anyway.
-
uint32_t txd_pin
-
struct nrfx_uarte_xfer_evt_t
- #include <nrfx_uarte.h>
Structure for the UARTE transfer completion event.
-
struct nrfx_uarte_error_evt_t
- #include <nrfx_uarte.h>
Structure for UARTE error event.
Public Members
-
nrfx_uarte_xfer_evt_t rx
Transfer details, including number of bytes received.
-
uint32_t error_mask
Mask of error flags that generated the event.
-
nrfx_uarte_xfer_evt_t rx
-
struct nrfx_uarte_event_t
- #include <nrfx_uarte.h>
Structure for UARTE event.
Public Members
-
nrfx_uarte_evt_type_t type
Event type.
-
nrfx_uarte_xfer_evt_t rx
Data provided for RX completion events.
-
nrfx_uarte_xfer_evt_t tx
Data provided for TX completion events.
-
nrfx_uarte_error_evt_t error
Data provided for error event.
-
union nrfx_uarte_event_t.[anonymous] data
Union to store event data.
-
nrfx_uarte_evt_type_t type
-
NRFX_UARTE_INSTANCE(id)