Retarget IO
Retarget IO

General Description

Macros

#define CY_RETARGET_IO_RSLT_NULL_UART_PTR    (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_RETARGET_IO, 0))
 A null pointer was passed as a function parameter.
 
#define CY_RETARGET_IO_BAUDRATE   (115200)
 UART baud rate.
 
#define cy_retarget_io_init(tx, rx, baudrate)   cy_retarget_io_init_fc(tx, rx, NC, NC, baudrate)
 UART HAL object used by this library. More...
 
#define CY_RETARGET_IO_CONVERT_LF_TO_CRLF
 Defining this macro enables conversion of line feed (LF) into carriage return followed by line feed (CR & LF) on the output direction (STDOUT). More...
 

Functions

cy_rslt_t cy_retarget_io_init_fc (cyhal_gpio_t tx, cyhal_gpio_t rx, cyhal_gpio_t cts, cyhal_gpio_t rts, uint32_t baudrate)
 Initialization function for redirecting low level IO commands to allow sending messages over a UART interface with flow control. More...
 
cy_rslt_t cy_retarget_io_init_hal (void)
 Initialization function for redirecting low level IO commands to allow sending messages over a UART interface with a configurator generated configuration struct. More...
 
bool cy_retarget_io_is_tx_active (void)
 Checks whether there is data waiting to be written to the serial console. More...
 
void cy_retarget_io_deinit (void)
 Releases the UART interface allowing it to be used for other purposes. More...
 
cy_rslt_t cy_retarget_io_change_baud_rate (uint32_t baud_rate, uint32_t *actual_baud)
 Changes the UART baud rate for the retarget-io interface. More...
 

Macro Definition Documentation

◆ cy_retarget_io_init

#define cy_retarget_io_init (   tx,
  rx,
  baudrate 
)    cy_retarget_io_init_fc(tx, rx, NC, NC, baudrate)

UART HAL object used by this library.

defined(COMPONENT_MTB_HAL)

Initialization function for redirecting low level IO commands to allow sending messages over a UART interface. This will setup the communication interface to allow using printf and related functions.

In an RTOS environment, this function must be called after the RTOS has been initialized.

Note
The quantity and type of arguments for this function vary based on the configuration used. See the Initialization Function Reference section for details.
This is a macro that calls cy_retarget_io_init_fc() with NC values for flow control pins in CY_USING_HAL mode.
Parameters
txUART TX pin, if no TX pin use NC
rxUART RX pin, if no RX pin use NC
baudrateUART baudrate
Returns
CY_RSLT_SUCCESS if successfully initialized, else an error about what went wrong

◆ CY_RETARGET_IO_CONVERT_LF_TO_CRLF

#define CY_RETARGET_IO_CONVERT_LF_TO_CRLF

Defining this macro enables conversion of line feed (LF) into carriage return followed by line feed (CR & LF) on the output direction (STDOUT).

You can define this macro through the DEFINES variable in the application Makefile.

Function Documentation

◆ cy_retarget_io_init_fc()

cy_rslt_t cy_retarget_io_init_fc ( cyhal_gpio_t  tx,
cyhal_gpio_t  rx,
cyhal_gpio_t  cts,
cyhal_gpio_t  rts,
uint32_t  baudrate 
)

Initialization function for redirecting low level IO commands to allow sending messages over a UART interface with flow control.

This will setup the communication interface to allow using printf and related functions.

In an RTOS environment, this function must be called after the RTOS has been initialized.

Note
The quantity and type of arguments for this function vary based on the configuration used. See the Initialization Function Reference section for details.
This function provides full control including flow control pins (CTS/RTS).
Parameters
txUART TX pin, if no TX pin use NC
rxUART RX pin, if no RX pin use NC
ctsUART CTS pin, if no CTS pin use NC
rtsUART RTS pin, if no RTS pin use NC
baudrateUART baudrate
Returns
CY_RSLT_SUCCESS if successfully initialized, else an error about what went wrong

◆ cy_retarget_io_init_hal()

cy_rslt_t cy_retarget_io_init_hal ( void  )

Initialization function for redirecting low level IO commands to allow sending messages over a UART interface with a configurator generated configuration struct.

This will setup the communication interface to allow using printf and related functions.

This function assumes that you've already initialized cy_retarget_io_uart_obj using some other mechanism.

In an RTOS environment, this function must be called after the RTOS has been initialized.

Note
The quantity and type of arguments for this function vary based on the configuration used. See the Initialization Function Reference section for details.
Requires cy_retarget_io_uart_obj to be pre-initialized before calling this function.
Returns
CY_RSLT_SUCCESS if successfully initialized, else an error about what went wrong

◆ cy_retarget_io_is_tx_active()

bool cy_retarget_io_is_tx_active ( void  )

Checks whether there is data waiting to be written to the serial console.

Returns
true if there are pending TX transactions, otherwise false

◆ cy_retarget_io_deinit()

void cy_retarget_io_deinit ( void  )

Releases the UART interface allowing it to be used for other purposes.

After calling this, printf and related functions will no longer work.

◆ cy_retarget_io_change_baud_rate()

cy_rslt_t cy_retarget_io_change_baud_rate ( uint32_t  baud_rate,
uint32_t *  actual_baud 
)

Changes the UART baud rate for the retarget-io interface.

This function allows dynamic baud rate changes during runtime using the MTB-HAL framework. It operates on the UART object that was previously initialized with cy_retarget_io_init(), so no UART object parameter is needed.

The function uses the MTB-HAL baud rate setting capability to automatically determine and configure the optimal peripheral clock divider and oversample values required to achieve the target baud rate with minimal error. This leverages the HAL's built-in expertise for accurate baud rate configuration across different hardware platforms.

Note
This function requires COMPONENT_MTB_HAL to be defined. It is not available when using CY-HAL or PDL-only configurations.
Changing the baud rate will cause a brief communication interruption.
The terminal/host must also be set to the new baud rate to maintain communication.
For production environments, consider using a separate debug UART with a fixed baud rate.
Parameters
baud_rateDesired baud rate (e.g., 9600, 115200, 230400)
actual_baudPointer to store the actual baud rate achieved by the hardware, or NULL if the actual baud rate is not needed
Returns
CY_RSLT_SUCCESS if successfully changed, else an error about what went wrong