cy_scb_uart_8h

Provides UART API declarations of the SCB driver.

Version

2.80

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Copyright

Copyright 2016-2021 Cypress Semiconductor Corporation SPDX-License-Identifier: Apache-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defines

CY_SCB_UART_IRDA_LP_OVS16

IrDA in low-power mode oversampled by 16.

CY_SCB_UART_IRDA_LP_OVS32

IrDA in low-power mode oversampled by 32.

CY_SCB_UART_IRDA_LP_OVS48

IrDA in low-power mode oversampled by 48.

CY_SCB_UART_IRDA_LP_OVS96

IrDA in low-power mode oversampled by 96.

CY_SCB_UART_IRDA_LP_OVS192

IrDA in low-power mode oversampled by 192.

CY_SCB_UART_IRDA_LP_OVS768

IrDA in low-power mode oversampled by 768.

CY_SCB_UART_IRDA_LP_OVS1536

IrDA in low-power mode oversampled by 1536.

CY_SCB_UART_RX_TRIGGER

The number of entries in the RX FIFO is more than the RX FIFO trigger level value.

CY_SCB_UART_RX_NOT_EMPTY

The RX FIFO is not empty, there is data to read.

CY_SCB_UART_RX_FULL

The RX FIFO is full, there is no more space for additional data, and any additional data will be dropped.

CY_SCB_UART_RX_OVERFLOW

The RX FIFO was full and there was an attempt to write to it.

That additional data was dropped.

CY_SCB_UART_RX_UNDERFLOW

An attempt to read from an empty RX FIFO.

CY_SCB_UART_RX_ERR_FRAME

The RX FIFO detected a frame error, either a stop or stop-bit error.

CY_SCB_UART_RX_ERR_PARITY

The RX FIFO detected a parity error.

CY_SCB_UART_RX_BREAK_DETECT

The RX FIFO detected a break transmission from the transmitter.

CY_SCB_UART_TX_TRIGGER

The number of entries in the TX FIFO is less than the TX FIFO trigger level value.

CY_SCB_UART_TX_NOT_FULL

The TX FIFO is not full, there is a space for more data.

CY_SCB_UART_TX_EMPTY

The TX FIFO is empty, note there may still be data in the shift register.

CY_SCB_UART_TX_OVERFLOW

An attempt to write to the full TX FIFO.

CY_SCB_UART_TX_UNDERFLOW

An attempt to read from an empty transmitter FIFO (hardware reads).

CY_SCB_UART_TX_DONE

All data has been transmitted out of the FIFO, including shifter.

CY_SCB_UART_TX_NACK

SmartCard only: the transmitter received a NACK.

CY_SCB_UART_TX_ARB_LOST

SmartCard only: the transmitter lost arbitration.

CY_SCB_UART_RECEIVE_ACTIVE

The receive operation started by Cy_SCB_UART_Receive is in progress.

CY_SCB_UART_RECEIVE_OVERFLOW

The hardware RX FIFO was full and there was an attempt to write to it.

That additional data was dropped.

CY_SCB_UART_RECEIVE_ERR_FRAME

The receive hardware detected a frame error, either a start or stop bit error.

CY_SCB_UART_RECEIVE_ERR_PARITY

The receive hardware detected a parity error.

CY_SCB_UART_RECEIVE_BREAK_DETECT

The receive hardware detected a break transmission from transmitter.

CY_SCB_UART_TRANSMIT_ACTIVE

The transmit operation started by Cy_SCB_UART_Transmit is in progress.

CY_SCB_UART_TRANSMIT_IN_FIFO

All data elements specified by Cy_SCB_UART_Transmit have been loaded into the TX FIFO.

CY_SCB_UART_TRANSMIT_NACK

SmartCard only: the transmitter received a NACK.

CY_SCB_UART_TRANSMIT_ARB_LOST

SmartCard only: the transmitter lost arbitration.

CY_SCB_UART_TRANSMIT_IN_FIFO_EVENT

All data elements specified by Cy_SCB_UART_Transmit have been loaded into the TX FIFO.

CY_SCB_UART_TRANSMIT_DONE_EVENT

The transmit operation started by Cy_SCB_UART_Transmit is complete.

CY_SCB_UART_RECEIVE_DONE_EVENT

The receive operation started by Cy_SCB_UART_Receive is complete.

CY_SCB_UART_RB_FULL_EVENT

The ring buffer is full, there is no more space for additional data.

Additional data is stored in the RX FIFO until it becomes full, at which point data is dropped.

CY_SCB_UART_RECEIVE_ERR_EVENT

An error was detected during the receive operation.

This includes overflow, frame error, or parity error. Check Cy_SCB_UART_GetReceiveStatus to determine the source of the error.

CY_SCB_UART_TRANSMIT_ERR_EVENT

An error was detected during the transmit operation.

This includes a NACK or lost arbitration. Check Cy_SCB_UART_GetTransmitStatus to determine the source of the error

CY_SCB_UART_RECEIVE_NOT_EMTPY

The receive fifo is not empty.

To use this event the CY_SCB_RX_INTR_NOT_EMPTY interrupt must be enabled by the user.

CY_SCB_UART_TRANSMIT_EMTPY

The transmit fifo is empty.

To use this event the CY_SCB_UART_TX_EMPTY interrupt must be enabled by the user.

CY_SCB_UART_RX_NO_DATA

Data returned by the hardware when an empty RX FIFO is read.

Typedefs

typedef void (*cy_cb_scb_uart_handle_events_t)(uint32_t event)

Provides the typedef for the callback function called in the Cy_SCB_UART_Interrupt to notify the user about occurrences of UART Callback Events.

Enums

enum cy_en_scb_uart_status_t

cy_en_scb_uart_status_t: UART status codes.

Values:

enumerator CY_SCB_UART_SUCCESS

Operation completed successfully.

enumerator CY_SCB_UART_BAD_PARAM

One or more of input parameters are invalid.

enumerator CY_SCB_UART_RECEIVE_BUSY

The UART is busy processing a receive operation.

enumerator CY_SCB_UART_TRANSMIT_BUSY

The UART is busy processing a transmit operation.

enum cy_en_scb_uart_mode_t

cy_en_scb_uart_mode_t: UART Mode.

Values:

enumerator CY_SCB_UART_STANDARD

Configures the SCB for Standard UART operation.

enumerator CY_SCB_UART_SMARTCARD

Configures the SCB for SmartCard operation.

enumerator CY_SCB_UART_IRDA

Configures the SCB for IrDA operation.

enum cy_en_scb_uart_stop_bits_t

cy_en_scb_uart_stop_bits_t: UART Stop Bits.

Values:

enumerator CY_SCB_UART_STOP_BITS_1

UART looks for 1 Stop Bit.

enumerator CY_SCB_UART_STOP_BITS_1_5

UART looks for 1.5 Stop Bits.

enumerator CY_SCB_UART_STOP_BITS_2

UART looks for 2 Stop Bits.

enumerator CY_SCB_UART_STOP_BITS_2_5

UART looks for 2.5 Stop Bits.

enumerator CY_SCB_UART_STOP_BITS_3

UART looks for 3 Stop Bits.

enumerator CY_SCB_UART_STOP_BITS_3_5

UART looks for 3.5 Stop Bits.

enumerator CY_SCB_UART_STOP_BITS_4

UART looks for 4 Stop Bits.

enum cy_en_scb_uart_parity_t

cy_en_scb_uart_parity_t: UART Parity.

Values:

enumerator CY_SCB_UART_PARITY_NONE

UART has no parity check.

enumerator CY_SCB_UART_PARITY_EVEN

UART has even parity check.

enumerator CY_SCB_UART_PARITY_ODD

UART has odd parity check.

enum cy_en_scb_uart_polarity_t

cy_en_scb_uart_polarity_t: UART Polarity.

Values:

enumerator CY_SCB_UART_ACTIVE_LOW

Signal is active low.

enumerator CY_SCB_UART_ACTIVE_HIGH

Signal is active high.

Functions

cy_en_scb_uart_status_t Cy_SCB_UART_Init(CySCB_Type *base, cy_stc_scb_uart_config_t const *config, cy_stc_scb_uart_context_t *context)

Initializes the SCB for UART operation.

note

Ensure that the SCB block is disabled before calling this function.

Parameters
  • base – The pointer to the UART SCB instance.

  • config – The pointer to configuration structure cy_stc_scb_uart_config_t.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure. If only UART Low-Level API will be used pass NULL as pointer to context.

Returns

cy_en_scb_uart_status_t

void Cy_SCB_UART_DeInit(CySCB_Type *base)

De-initializes the SCB block.

Returns the register values to default.

note

Ensure that the SCB block is disabled before calling this function.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE void Cy_SCB_UART_Enable (CySCB_Type *base)

Enables the SCB block for the UART operation.

Parameters

base – The pointer to the UART SCB instance.

void Cy_SCB_UART_Disable(CySCB_Type *base, cy_stc_scb_uart_context_t *context)

Disables the SCB block and clears context statuses.

Note that after the block is disabled, the TX and RX FIFOs and hardware statuses are cleared. Also, the hardware stops driving the output and ignores the input. Refer to section Low Power Support for more information about UART pins when SCB disabled.

note

Calling this function when the UART is busy (transmitter preforms data transfer or receiver is in the middle of data reception) may result transfer corruption because the hardware stops driving the outputs and ignores the inputs. Ensure that the UART is not busy before calling this function.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure. If only UART functions that do not require context will be used to pass NULL as pointer to context.

__STATIC_INLINE void Cy_SCB_UART_EnableCts (CySCB_Type *base)

Enables the Clear to Send (CTS) input for the UART.

The UART will not transmit data while this signal is inactive.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE void Cy_SCB_UART_DisableCts (CySCB_Type *base)

Disables the Clear to Send (CTS) input for the UART.

See Cy_SCB_UART_EnableCts for the details.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE void Cy_SCB_UART_SetRtsFifoLevel (CySCB_Type *base, uint32_t level)

Sets a level for the Ready To Send (RTS) signal activation.

When the number of data elements in the receive FIFO is below this level, then the RTS output is active. Otherwise, the RTS signal is inactive. To disable the RTS signal generation, set this level to zero.

Parameters
  • base – The pointer to the UART SCB instance.

  • level – The level in the RX FIFO for RTS signal activation.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetRtsFifoLevel (CySCB_Type const *base)

Returns the level in the RX FIFO for the RTS signal activation.

Parameters

base – The pointer to the UART SCB instance.

Returns

The level in the RX FIFO for RTS signal activation.

__STATIC_INLINE void Cy_SCB_UART_EnableSkipStart (CySCB_Type *base)

Enables the skip start-bit functionality.

When skip start is enabled the UART hardware does not synchronize to a start bit but synchronizes to the first rising edge. To create a rising edge, the first data bit must be a 1. This feature is useful when the start bit falling edge is used to wake the device through a GPIO interrupt.

note

When skip start-bit feature is enabled, it is applied (UART synchronizes to the first rising edge after start bit) whenever the SCB is enabled. This can cause incorrect UART synchronization and data reception when the first data bit is not a 1. Therefore, disable the skip start-bit when it should not be applied. Note that SCB is disabled before enter Deep Sleep mode or after calling Cy_SCB_UART_Disable.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE void Cy_SCB_UART_DisableSkipStart (CySCB_Type *base)

Disable the skip start-bit functionality.

See Cy_SCB_UART_EnableSkipStart for the details.

Parameters

base – The pointer to the UART SCB instance.

void Cy_SCB_UART_StartRingBuffer(CySCB_Type *base, void *buffer, uint32_t size, cy_stc_scb_uart_context_t *context)

Starts the receive ring buffer operation.

The RX interrupt source is configured to get data from the RX FIFO and put into the ring buffer.

note

  • The buffer must not be modified and stay allocated while the ring buffer operates.

  • This function overrides the RX interrupt sources and changes the RX FIFO level.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – Pointer to the user defined ring buffer. The element size is defined by the data type, which depends on the configured data width.

  • size – The size of the receive ring buffer. Note that one data element is used for internal use, so if the size is 32, then only 31 data elements are used for data storage.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

void Cy_SCB_UART_StopRingBuffer(CySCB_Type *base, cy_stc_scb_uart_context_t *context)

Stops receiving data into the ring buffer and clears the ring buffer.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_UART_GetNumInRingBuffer(CySCB_Type const *base, cy_stc_scb_uart_context_t const *context)

Returns the number of data elements in the ring buffer.

note

One data element is used for internal use, so when the buffer is full, this function returns (Ring Buffer size - 1).

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

The number of data elements in the receive ring buffer.

void Cy_SCB_UART_ClearRingBuffer(CySCB_Type const *base, cy_stc_scb_uart_context_t *context)

Clears the ring buffer.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_scb_uart_status_t Cy_SCB_UART_Receive(CySCB_Type *base, void *buffer, uint32_t size, cy_stc_scb_uart_context_t *context)

This function starts a UART receive operation.

It configures the receive interrupt sources to get data available in the receive FIFO and returns. The Cy_SCB_UART_Interrupt manages the further data transfer.

If the ring buffer is enabled, this function first reads data from the ring buffer. If there is more data to receive, it configures the receive interrupt sources to copy the remaining bytes from the RX FIFO when they arrive.

When the receive operation is completed (requested number of data elements received) the CY_SCB_UART_RECEIVE_ACTIVE status is cleared and the CY_SCB_UART_RECEIVE_DONE_EVENT event is generated.

note

  • The buffer must not be modified and stay allocated until end of the receive operation.

  • This function overrides the RX interrupt sources and changes the RX FIFO level.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – Pointer to buffer to store received data. The element size is defined by the data type, which depends on the configured data width.

  • size – The number of data elements to receive.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

cy_en_scb_uart_status_t

void Cy_SCB_UART_AbortReceive(CySCB_Type *base, cy_stc_scb_uart_context_t *context)

Abort the current receive operation by clearing the receive status.

  • If the ring buffer is disabled, the receive interrupt sources are disabled.

  • If the ring buffer is enabled, the receive interrupt source is configured to get data from the receive FIFO and put it into the ring buffer.

note

  • The RX FIFO and ring buffer are not cleared after abort of receive operation.

  • If after the abort of the receive operation the transmitter continues sending data, it gets into the RX FIFO. To drop this data, the RX FIFO and ring buffer (if enabled) must be cleared when the transmitter stops sending data. Otherwise, received data will be kept and copied to the buffer when Cy_SCB_UART_Receive is called.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_UART_GetReceiveStatus(CySCB_Type const *base, cy_stc_scb_uart_context_t const *context)

Returns the status of the receive operation.

This status is a bit mask and the value returned may have multiple bits set.

note

The status is only cleared by calling Cy_SCB_UART_Receive again.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

UART Receive Statuses.

uint32_t Cy_SCB_UART_GetNumReceived(CySCB_Type const *base, cy_stc_scb_uart_context_t const *context)

Returns the number of data elements received since the last call to Cy_SCB_UART_Receive.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

The number of data elements received.

cy_en_scb_uart_status_t Cy_SCB_UART_Transmit(CySCB_Type *base, void *buffer, uint32_t size, cy_stc_scb_uart_context_t *context)

This function starts a UART transmit operation.

It configures the transmit interrupt sources and returns. The Cy_SCB_UART_Interrupt manages the further data transfer.

When the transmit operation is completed (requested number of data elements sent on the bus), the CY_SCB_UART_TRANSMIT_ACTIVE status is cleared and the CY_SCB_UART_TRANSMIT_DONE_EVENT event is generated.

note

  • The buffer must not be modified and must stay allocated until its content is copied into the TX FIFO.

  • This function overrides the TX FIFO interrupt sources and changes the TX FIFO level.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – Pointer to user data to place in transmit buffer. The element size is defined by the data type, which depends on the configured data width.

  • size – The number of data elements to transmit.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

cy_en_scb_uart_status_t

void Cy_SCB_UART_AbortTransmit(CySCB_Type *base, cy_stc_scb_uart_context_t *context)

Aborts the current transmit operation.

It disables the transmit interrupt sources and clears the transmit FIFO and status.

Side Effects

The transmit FIFO clear operation also clears the shift register, so that the shifter can be cleared in the middle of a data element transfer, corrupting it. The data element corruption means that all bits that have not been transmitted are transmitted as “ones” on the bus.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_UART_GetTransmitStatus(CySCB_Type const *base, cy_stc_scb_uart_context_t const *context)

Returns the status of the transmit operation.

This status is a bit mask and the value returned may have multiple bits set.

note

The status is only cleared by calling Cy_SCB_UART_Transmit or Cy_SCB_UART_AbortTransmit.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

UART Transmit Status.

uint32_t Cy_SCB_UART_GetNumLeftToTransmit(CySCB_Type const *base, cy_stc_scb_uart_context_t const *context)

Returns the number of data elements left to transmit since the last call to Cy_SCB_UART_Transmit.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

Returns

The number of data elements left to transmit.

__STATIC_INLINE uint32_t Cy_SCB_UART_Put (CySCB_Type *base, uint32_t data)

Places a single data element in the UART TX FIFO.

This function does not block and returns how many data elements were placed in the TX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • data – Data to put in the TX FIFO. The element size is defined by the data type, which depends on the configured data width.

Returns

The number of data elements placed in the TX FIFO: 0 or 1.

__STATIC_INLINE uint32_t Cy_SCB_UART_PutArray (CySCB_Type *base, void *buffer, uint32_t size)

Places an array of data in the UART TX FIFO.

This function does not block. It returns how many data elements were placed in the TX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – The pointer to data to place in the TX FIFO. The element size is defined by the data type, which depends on the configured TX data width.

  • size – The number of data elements to TX.

Returns

The number of data elements placed in the TX FIFO.

__STATIC_INLINE void Cy_SCB_UART_PutArrayBlocking (CySCB_Type *base, void *buffer, uint32_t size)

Places an array of data in the UART TX FIFO.

This function blocks until the number of data elements specified by the size is placed in the TX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – The pointer to data to place in the TX FIFO. The element size is defined by the data type, which depends on the configured data width.

  • size – The number of data elements to write into the TX FIFO.

__STATIC_INLINE void Cy_SCB_UART_PutString (CySCB_Type *base, char_t const string[])

Places a NULL terminated string in the UART TX FIFO.

This function blocks until the entire string is placed in the TX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • string – The pointer to the null terminated string array.

void Cy_SCB_UART_SendBreakBlocking(CySCB_Type *base, uint32_t breakWidth)

Sends a break condition (logic low) of specified width on UART TX line.

Blocks until break is completed. Only call this function when UART TX FIFO and shifter are empty.

note

Before sending break all UART TX interrupt sources are disabled. The state of UART TX interrupt sources is restored before function returns.

Side Effects

If this function is called while there is data in the TX FIFO or shifter that data will be shifted out in packets the size of breakWidth.

Parameters
  • base – The pointer to the UART SCB instance.

  • breakWidth – Width of break condition. Valid range is the TX data width (4 to 16 bits)

__STATIC_INLINE uint32_t Cy_SCB_UART_Get (CySCB_Type const *base)

Reads a single data element from the UART RX FIFO.

This function does not check whether the RX FIFO has data before reading it. If the RX FIFO is empty, the function returns CY_SCB_UART_RX_NO_DATA.

Parameters

base – The pointer to the UART SCB instance.

Returns

Data from the RX FIFO. The data element size is defined by the configured data width.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetArray (CySCB_Type const *base, void *buffer, uint32_t size)

Reads an array of data out of the UART RX FIFO.

This function does not block. It returns how many data elements were read from the RX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – The pointer to the location to place the data read from the RX FIFO. The element size is defined by the data type, which depends on the configured data width.

  • size – The number of data elements to read from the RX FIFO.

Returns

The number of data elements read from the RX FIFO.

__STATIC_INLINE void Cy_SCB_UART_GetArrayBlocking (CySCB_Type const *base, void *buffer, uint32_t size)

Reads an array of data out of the UART RX FIFO.

This function blocks until the number of data elements specified by the size has been read from the RX FIFO.

Parameters
  • base – The pointer to the UART SCB instance.

  • buffer – The pointer to the location to place the data read from the RX FIFO. The element size is defined by the data type, which depends on the configured data width.

  • size – The number of data elements to read from the RX FIFO.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetTxFifoStatus (CySCB_Type const *base)

Returns the current status of the TX FIFO.

Parameters

base – The pointer to the UART SCB instance.

Returns

UART TX FIFO Statuses

__STATIC_INLINE void Cy_SCB_UART_ClearTxFifoStatus (CySCB_Type *base, uint32_t clearMask)

Clears the selected statuses of the TX FIFO.

note

Parameters
  • base – The pointer to the UART SCB instance.

  • clearMask – The mask whose statuses to clear. See UART TX FIFO Statuses for the set of constants.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetRxFifoStatus (CySCB_Type const *base)

Returns the current status of the RX FIFO.

Parameters

base – The pointer to the UART SCB instance.

Returns

UART RX FIFO status.

__STATIC_INLINE void Cy_SCB_UART_ClearRxFifoStatus (CySCB_Type *base, uint32_t clearMask)

Clears the selected statuses of the RX FIFO.

note

Parameters
  • base – The pointer to the UART SCB instance.

  • clearMask – The mask whose statuses to clear. See UART RX FIFO status. for the set of constants.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetNumInTxFifo (CySCB_Type const *base)

Returns the number of data elements in the UART TX FIFO.

note

This number does not include any data currently in the TX shifter.

Parameters

base – The pointer to the UART SCB instance.

Returns

The number of data elements in the TX FIFO. The size of date element defined by the configured data width.

__STATIC_INLINE bool Cy_SCB_UART_IsTxComplete (CySCB_Type const *base)

Checks whether the TX FIFO and Shifter are empty and there is no more data to send.

Parameters

base – Pointer to the UART SCB instance.

Returns

If true, transmission complete. If false, transmission is not complete.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetNumInRxFifo (CySCB_Type const *base)

Returns the number of data elements in the UART RX FIFO.

Parameters

base – The pointer to the UART SCB instance.

Returns

The number of data elements in the RX FIFO. The size of date element defined by the configured data width.

__STATIC_INLINE void Cy_SCB_UART_ClearRxFifo (CySCB_Type *base)

Clears all data out of the UART RX FIFO.

Side Effects

Any data currently in the shifter is cleared and lost.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE void Cy_SCB_UART_ClearTxFifo (CySCB_Type *base)

Clears all data out of the UART TX FIFO.

Side Effects

The TX FIFO clear operation also clears the shift register, so that the shifter could be cleared in the middle of a data element transfer, corrupting it. The data element corruption means that all bits that have not been transmitted are transmitted as 1s on the bus.

Parameters

base – The pointer to the UART SCB instance.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetOverSample (CySCB_Type const *base)

Returns the value of oversample.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current oversample value for provided SCB */
    (void) Cy_SCB_UART_GetOverSample(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of oversample.

cy_en_scb_uart_status_t Cy_SCB_UART_SetOverSample(CySCB_Type *base, uint32_t overSample, cy_stc_scb_uart_context_t *context)

Sets oversample bits of UART.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate oversample value for UART */
    uint32_t OverSample = 8UL;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set oversample value for UART */
    (void) Cy_SCB_UART_SetOverSample(SCB5, OverSample, &UART_1_context);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • overSample – Value of oversample to be set.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure. User should not pass NULL as pointer to context.

Returns

cy_en_scb_uart_status_t

__STATIC_INLINE uint32_t Cy_SCB_UART_GetDataWidth (CySCB_Type const *base)

Returns the value of datawidth.

note

Values of Tx and Rx datawidth are same.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current datawidth value for provided SCB */
    (void) Cy_SCB_UART_GetDataWidth(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of datawidth.

void Cy_SCB_UART_SetDataWidth(CySCB_Type *base, uint32_t dataWidth)

Sets datawidth for UART transaction.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate datawidth value for UART */
    uint32_t dataWidth = 8UL;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set datawidth value for UART */
    (void) Cy_SCB_UART_SetDataWidth(SCB5, dataWidth);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • dataWidth – The width of UART data in the UART transaction.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetParity (CySCB_Type const *base)

Returns the value of parity.

note

Values of Tx and Rx parity are same.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current parity value for provided SCB */
    (void) Cy_SCB_UART_GetParity(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of parity.

void Cy_SCB_UART_SetParity(CySCB_Type *base, cy_en_scb_uart_parity_t parity)

Sets parity for UART transaction.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate parity value for UART */
    cy_en_scb_uart_parity_t parity = CY_SCB_UART_PARITY_NONE;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set parity value for UART */
    (void) Cy_SCB_UART_SetParity(SCB5, parity);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • parity – The UART parity bit in the UART transaction.

__STATIC_INLINE uint32_t Cy_SCB_UART_GetStopBits (CySCB_Type const *base)

Returns the value of stop bits.

note

Values of Tx and Rx stop bits are same.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current stop bits value for provided SCB */
    (void) Cy_SCB_UART_GetStopBits(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of stop bits.

void Cy_SCB_UART_SetStopBits(CySCB_Type *base, cy_en_scb_uart_stop_bits_t stopBits)

Sets stop bits for UART transaction.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate stop bits value for UART */
    cy_en_scb_uart_stop_bits_t stopBits = CY_SCB_UART_STOP_BITS_1;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set stop bits value for UART */
    (void) Cy_SCB_UART_SetStopBits(SCB5, stopBits);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • stopBits – The number of stop bits in the UART transaction.

__STATIC_INLINE bool Cy_SCB_UART_GetDropOnParityError (CySCB_Type const *base)

Returns the value of SetDropOnParityError.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current SetDropOnParityError value for provided SCB */
    (void) Cy_SCB_UART_GetDropOnParityError(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of SetDropOnParityError.

void Cy_SCB_UART_SetDropOnParityError(CySCB_Type *base, bool dropOnParityError)

Sets SetDropOnParityError for UART transaction.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate SetDropOnParityError value for UART */
    bool setDropOnParityError = false;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set SetDropOnParityError value for UART */
    (void) Cy_SCB_UART_SetDropOnParityError(SCB5, setDropOnParityError);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • dropOnParityError – To enable the hardware to drop data in the RX FIFO when a parity error is detected in the UART transaction.

__STATIC_INLINE bool Cy_SCB_UART_GetEnableMsbFirst (CySCB_Type const *base)

Returns the value of enableMsbFirst.

note

Values of Tx and Rx enableMsbFirst are same.

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Get current enableMsbFirst value for provided SCB */
    (void) Cy_SCB_UART_GetEnableMsbFirst(SCB5);

Parameters

base – The pointer to the UART SCB instance.

Returns

The value of enableMsbFirst.

void Cy_SCB_UART_SetEnableMsbFirst(CySCB_Type *base, bool enableMsbFirst)

Sets enableMsbFirst for UART transaction.

note

Ensure that the SCB block is disabled before calling this function.

    /* Assign appropriate enableMsbFirst value for UART */
    bool enableMsbFirst = false;

    /* Initialize SCB for UART operation */
    (void) Cy_SCB_UART_Init(SCB5, &UART_1_config, &UART_1_context);

    /* Set enableMsbFirst value for UART */
    (void) Cy_SCB_UART_SetEnableMsbFirst(SCB5, enableMsbFirst);

    /* Enable UART to operate */
    Cy_SCB_UART_Enable(SCB5);

Parameters
  • base – The pointer to the UART SCB instance.

  • enableMsbFirst – Enables the hardware to shift out data element MSB first; otherwise, LSB first in the UART transaction.

void Cy_SCB_UART_Interrupt(CySCB_Type *base, cy_stc_scb_uart_context_t *context)

This is the interrupt function for the SCB configured in the UART mode.

This function must be called inside a user-defined interrupt service routine to make Cy_SCB_UART_Transmit and Cy_SCB_UART_Receive work. The ring buffer operation that enabled by calling Cy_SCB_UART_StartRingBuffer also requires interrupt processing.

Parameters
  • base – The pointer to the UART SCB instance.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user must not modify anything in this structure.

__STATIC_INLINE void Cy_SCB_UART_RegisterCallback (CySCB_Type const *base, cy_cb_scb_uart_handle_events_t callback, cy_stc_scb_uart_context_t *context)

Registers a callback function that notifies that UART Callback Events occurred in the Cy_SCB_UART_Interrupt.

note

To remove the callback, pass NULL as the pointer to the callback function.

Parameters
  • base – The pointer to the UART SCB instance.

  • callback – The pointer to the callback function. See cy_cb_scb_uart_handle_events_t for the function prototype.

  • context – The pointer to the context structure cy_stc_scb_uart_context_t allocated by the user. The structure is used during the UART operation for internal configuration and data retention. The user should not modify anything in this structure.

cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)

This function handles the transition of the SCB UART into and out of Deep Sleep mode.

It prevents the device from entering Deep Sleep mode if the UART is transmitting data or has any data in the RX FIFO. If the UART is ready to enter Deep Sleep mode, it is disabled. The UART is enabled when the device fails to enter Deep Sleep mode or it is awakened from Deep Sleep mode. While the UART is disabled, it stops driving the outputs and ignores the inputs. Any incoming data is ignored. Refer to section Low Power Support for more information about UART pins when SCB disabled.

This function must be called during execution of Cy_SysPm_CpuEnterDeepSleep, to do it, register this function as a callback before calling Cy_SysPm_CpuEnterDeepSleep : specify CY_SYSPM_DEEPSLEEP as the callback type and call Cy_SysPm_RegisterCallback.

Parameters
Returns

cy_en_syspm_status_t

cy_en_syspm_status_t Cy_SCB_UART_HibernateCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)

This function handles the transition of the SCB UART into Hibernate mode.

It prevents the device from entering Hibernate mode if the UART is transmitting data or has any data in the RX FIFO. If the UART is ready to enter Hibernate mode, it is disabled. If the device fails to enter Hibernate mode, the UART is enabled. While the UART is disabled, it stops driving the outputs and ignores the inputs. Any incoming data is ignored. Refer to section Low Power Support for more information about UART pins when SCB disabled.

This function must be called during execution of Cy_SysPm_SystemEnterHibernate. To do it, register this function as a callback before calling Cy_SysPm_SystemEnterHibernate : specify CY_SYSPM_HIBERNATE as the callback type and call Cy_SysPm_RegisterCallback.

Parameters
Returns

cy_en_syspm_status_t

struct cy_stc_scb_uart_config_t
#include <>

UART configuration structure.

Public Members

cy_en_scb_uart_mode_t uartMode

Specifies the UART’s mode of operation.

uint32_t oversample

Oversample factor for UART.

uint32_t dataWidth

The width of UART data (valid range is 5 to 9)

bool enableMsbFirst

Enables the hardware to shift out data element MSB first; otherwise, LSB first.

cy_en_scb_uart_stop_bits_t stopBits

Specifies the number of stop bits in the UART transaction, in half-bit increments.

cy_en_scb_uart_parity_t parity

Configures the UART parity.

bool enableInputFilter

Enables a digital 3-tap median filter (2 out of 3 voting) to be applied to the input of the RX FIFO to filter glitches on the line (for IrDA, this parameter is ignored)

bool dropOnParityError

Enables the hardware to drop data in the RX FIFO when a parity error is detected.

bool dropOnFrameError

Enables the hardware to drop data in the RX FIFO when a frame error is detected.

bool enableMutliProcessorMode

Enables the UART operation in Multi-Processor mode which requires dataWidth to be 9 bits (the 9th bit is used to indicate address byte)

uint32_t receiverAddress

If Multi Processor mode is enabled, this is the address of the RX FIFO.

If the address matches, data is accepted into the FIFO. If it does not match, the data is ignored.

uint32_t receiverAddressMask

This is the address mask for the Multi Processor address.

1 indicates that the incoming address must match the corresponding bit in the slave address. A 0 in the mask indicates that the incoming address does not need to match.

bool acceptAddrInFifo

Enables the hardware to accept the matching address in the RX FIFO.

This is useful when the device supports more than one address.

bool irdaInvertRx

Inverts the IrDA RX input.

bool irdaEnableLowPowerReceiver

Enables the low-power receive for IrDA mode.

Note that the transmission must be disabled if this mode is enabled.

bool smartCardRetryOnNack

Enables retransmission of the frame placed in the TX FIFO when NACK is received in SmartCard mode (for Standard and IrDA , this parameter is ignored)

bool enableCts

Enables the usage of the CTS input signal for the transmitter.

The transmitter waits for CTS to be active before sending data

cy_en_scb_uart_polarity_t ctsPolarity

Sets the CTS Polarity.

uint32_t rtsRxFifoLevel

When the RX FIFO has fewer entries than rtsRxFifoLevel, the RTS signal is active (note to disable RTS, set this field to zero)

cy_en_scb_uart_polarity_t rtsPolarity

Sets the RTS Polarity.

uint32_t breakWidth

Specifies the number of bits to detect a break condition.

bool breaklevel

Specifies the low or high level pulse detection for break condition.

note

This parameter is available for CAT1B devices.

uint32_t rxFifoTriggerLevel

When there are more entries in the RX FIFO than this level the RX trigger output goes high.

This output can be connected to a DMA channel through a trigger mux. Also, it controls the CY_SCB_UART_RX_TRIGGER interrupt source.

uint32_t rxFifoIntEnableMask

The bits set in this mask allow the event to cause an interrupt (See UART RX FIFO status. for the set of constants)

uint32_t txFifoTriggerLevel

When there are fewer entries in the TX FIFO then this level the TX trigger output goes high.

This output can be connected to a DMA channel through a trigger mux. Also, it controls CY_SCB_UART_TX_TRIGGER interrupt source.

uint32_t txFifoIntEnableMask

Bits set in this mask allows the event to cause an interrupt (See UART TX FIFO Statuses for the set of constants)

struct cy_stc_scb_uart_context_t
#include <>

UART context structure.

All fields for the context structure are internal. Firmware never reads or writes these values. Firmware allocates the structure and provides the address of the structure to the driver in function calls. Firmware must ensure that the defined instance of this structure remains in scope while the drive is in use.