px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2

Description

Initialises the stdout stream to output to UART.

File(s):

This component initialises the stdout stream to output over UART.

px_uart_stdio_putchar() will intercept all line feed characters (\n) and replace it with a carriage return, line feed sequence (\r\n).

References:

  1. newlib-2.5.0/newlib/libc/sys/arm/syscalls.c

Example:

#include <stdio.h>
#include "px_board.h"
#include "px_uart.h"
#include "px_uart_stdio.h"
// Create UART handle object
px_uart_handle_t px_uart_handle;
int main(void)
{
uint8_t counter;
// Initialise board
// Initialise module
// Open UART1 @ 115200 BAUD, 8 data bits, no parity, 1 stop bit
px_uart_open2(&px_uart_handle,
PX_UART_NR_1,
115200,
PX_UART_DATA_BITS_8,
PX_UART_PARITY_NONE,
PX_UART_STOP_BITS_1);
// Initialise stdio stream to use the specified UART
px_uart_stdio_init(&px_uart_handle);
printf("Starting counter...\n");
for(counter = 0; counter < 8; counter++)
{
printf("Counter = %u\n", counter);
}
}
void px_board_init(void)
Initialise the board hardware.
Definition: px_board.c:168
void px_uart_stdio_init(px_uart_handle_t *handle)
Initialise stdio stream to use a UART driver.
Definition: px_uart_stdio.c:94
bool px_uart_open2(px_uart_handle_t *handle, px_uart_nr_t uart_nr, uint32_t baud, px_uart_data_bits_t data_bits, px_uart_parity_t parity, px_uart_stop_bits_t stop_bits)
Open UART peripheral using specified parameters.
Definition: px_uart.c:483
void px_uart_init(void)
Initialise UART driver.
Definition: px_uart.c:452
Define UART handle.
Definition: px_uart.h:141

Functions

void px_uart_stdio_init (px_uart_handle_t *handle)
 Initialise stdio stream to use a UART driver. More...
 
int px_uart_stdio_putchar (char data)
 Function to send a byte. More...
 
int px_uart_stdio_getchar (void)
 Function to receive a byte. More...
 

Function Documentation

◆ px_uart_stdio_init()

void px_uart_stdio_init ( px_uart_handle_t handle)

Initialise stdio stream to use a UART driver.

px_uart_stdio_putchar() is provided as the handler for all outgoing data.

Parameters
handleopened handle to UART peripheral

Definition at line 94 of file px_uart_stdio.c.

◆ px_uart_stdio_putchar()

int px_uart_stdio_putchar ( char  data)

Function to send a byte.

Every carriage return ("\n") will be intercepted and replaced with a carriage return, new line sequence ("\r\n").

Parameters
databyte to send
Returns
int always returns 0

Definition at line 106 of file px_uart_stdio.c.

◆ px_uart_stdio_getchar()

int px_uart_stdio_getchar ( void  )

Function to receive a byte.

This function will block until a character has been received.

Returns
int received byte

Definition at line 120 of file px_uart_stdio.c.