NEORV32 - Software Framework Documentation
Functions
neorv32_uart.c File Reference

Universal asynchronous receiver/transmitter (UART0/UART1) HW driver source file. More...

#include "neorv32.h"
#include "neorv32_uart.h"
#include <string.h>
#include <stdarg.h>

Functions

int putchar (int ch)
 
int getchar (void)
 
int neorv32_uart0_available (void)
 
void neorv32_uart0_setup (uint32_t baudrate, uint8_t parity, uint8_t flow_con)
 
void neorv32_uart0_disable (void)
 
void neorv32_uart0_enable (void)
 
void neorv32_uart0_putc (char c)
 
int neorv32_uart0_tx_busy (void)
 
char neorv32_uart0_getc (void)
 
int neorv32_uart0_getc_safe (char *data)
 
int neorv32_uart0_char_received (void)
 
char neorv32_uart0_char_received_get (void)
 
void neorv32_uart0_print (const char *s)
 
void neorv32_uart0_printf (const char *format,...)
 
int neorv32_uart0_scan (char *buffer, int max_size, int echo)
 
int neorv32_uart1_available (void)
 
void neorv32_uart1_setup (uint32_t baudrate, uint8_t parity, uint8_t flow_con)
 
void neorv32_uart1_disable (void)
 
void neorv32_uart1_enable (void)
 
void neorv32_uart1_putc (char c)
 
int neorv32_uart1_tx_busy (void)
 
char neorv32_uart1_getc (void)
 
int neorv32_uart1_getc_safe (char *data)
 
int neorv32_uart1_char_received (void)
 
char neorv32_uart1_char_received_get (void)
 
void neorv32_uart1_print (const char *s)
 
void neorv32_uart1_printf (const char *format,...)
 
int neorv32_uart1_scan (char *buffer, int max_size, int echo)
 
static void __neorv32_uart_itoa (uint32_t x, char *res)
 
static void __neorv32_uart_tohex (uint32_t x, char *res)
 
static void __neorv32_uart_touppercase (uint32_t len, char *ptr)
 

Detailed Description

Universal asynchronous receiver/transmitter (UART0/UART1) HW driver source file.

Warning
UART0 (primary UART) is used as default user console interface for all NEORV32 software framework/library functions.
Note
These functions should only be used if the UART0/UART1 unit was synthesized (IO_UART0_EN = true / IO_UART1_EN = true).

Function Documentation

◆ __neorv32_uart_itoa()

static void __neorv32_uart_itoa ( uint32_t  x,
char *  res 
)
static

Private function for 'neorv32_printf' to convert into decimal.

Parameters
[in]xUnsigned input number.
[in,out]resPointer for storing the reuslting number string (11 chars).

◆ __neorv32_uart_tohex()

static void __neorv32_uart_tohex ( uint32_t  x,
char *  res 
)
static

Private function for 'neorv32_printf' to convert into hexadecimal.

Parameters
[in]xUnsigned input number.
[in,out]resPointer for storing the resulting number string (9 chars).

◆ __neorv32_uart_touppercase()

static void __neorv32_uart_touppercase ( uint32_t  len,
char *  ptr 
)
static

Private function to cast a string to UPPERCASE.

Parameters
[in]lenTotal length of input string.
[in,out]ptrPointer for input/output string.

◆ getchar()

int getchar ( void  )

Read char from UART0.

Returns
Read char.

◆ neorv32_uart0_available()

int neorv32_uart0_available ( void  )

Check if UART0 unit was synthesized.

Returns
0 if UART0 was not synthesized, 1 if UART0 is available.

◆ neorv32_uart0_char_received()

int neorv32_uart0_char_received ( void  )

Check if UART0 has received a char.

Note
This function is non-blocking.
Use neorv32_uart0_char_received_get(void) to get the char.
Returns
=!0 when a char has been received.

◆ neorv32_uart0_char_received_get()

char neorv32_uart0_char_received_get ( void  )

Get a received char from UART0.

Note
This function is non-blocking.
Should only be used in combination with neorv32_uart_char_received(void).
Returns
Received char.

◆ neorv32_uart0_disable()

void neorv32_uart0_disable ( void  )

Disable UART0.

◆ neorv32_uart0_enable()

void neorv32_uart0_enable ( void  )

Enable UART0.

◆ neorv32_uart0_getc()

char neorv32_uart0_getc ( void  )

Get char from UART0.

Note
This function is blocking and does not check for UART frame/parity errors.
Returns
Received char.

◆ neorv32_uart0_getc_safe()

int neorv32_uart0_getc_safe ( char *  data)

Get char from UART0 (and check errors).

Note
This function is non-blocking and checks for frame and parity errors.
Parameters
[in,out]dataReceived char.
Returns
Status code: 0 = char received without errors -1 = nothing received -2 = char received with frame error -3 = char received with parity error -4 = char received with overrun error.

◆ neorv32_uart0_print()

void neorv32_uart0_print ( const char *  s)

Print string (zero-terminated) via UART0. Print full line break "\r\n" for every '
'.

Note
This function is blocking.
Parameters
[in]sPointer to string.

◆ neorv32_uart0_printf()

void neorv32_uart0_printf ( const char *  format,
  ... 
)

Custom version of 'printf' function using UART0.

Note
This function is blocking.
Parameters
[in]formatPointer to format string.
sString (array of chars, zero-terminated)
cSingle char
d/i32-bit signed number, printed as decimal
u32-bit unsigned number, printed as decimal
x32-bit number, printed as 8-char hexadecimal - lower-case
X32-bit number, printed as 8-char hexadecimal - upper-case
p32-bit pointer, printed as 8-char hexadecimal - lower-case

◆ neorv32_uart0_putc()

void neorv32_uart0_putc ( char  c)

Send single char via UART0.

Note
This function is blocking.
Parameters
[in]cChar to be send.

◆ neorv32_uart0_scan()

int neorv32_uart0_scan ( char *  buffer,
int  max_size,
int  echo 
)

Simplified custom version of 'scanf' function for UART0.

Note
This function is blocking.
Parameters
[in,out]bufferPointer to array of chars to store string.
[in]max_sizeMaximum number of chars to sample.
[in]echoEcho UART input when 1.
Returns
Number of chars read.

◆ neorv32_uart0_setup()

void neorv32_uart0_setup ( uint32_t  baudrate,
uint8_t  parity,
uint8_t  flow_con 
)

Enable and configure primary UART (UART0).

Note
The 'UART0_SIM_MODE' compiler flag will configure UART0 for simulation mode: all UART0 TX data will be redirected to simulation output. Use this for simulations only!
To enable simulation mode add <USER_FLAGS+=-DUART0_SIM_MODE> when compiling.
Warning
The baud rate is computed using INTEGER operations (truncation errors might occur).
Parameters
[in]baudrateTargeted BAUD rate (e.g. 9600).
[in]parityParity configuration (00=off, 10=even, 11=odd), see NEORV32_UART_PARITY_enum.
[in]flow_conHardware flow control configuration (00=off, 01=RTS, 10=CTS, 11=RTS/CTS), see NEORV32_UART_FLOW_CONTROL_enum.

◆ neorv32_uart0_tx_busy()

int neorv32_uart0_tx_busy ( void  )

Check if UART0 TX is busy (transmitter busy or data left in TX buffer).

Note
This function is blocking.
Returns
0 if idle, 1 if busy

◆ neorv32_uart1_available()

int neorv32_uart1_available ( void  )

Check if UART1 unit was synthesized.

Returns
0 if UART1 was not synthesized, 1 if UART1 is available.

◆ neorv32_uart1_char_received()

int neorv32_uart1_char_received ( void  )

Check if UART1 has received a char.

Note
This function is non-blocking.
Use neorv32_uart0_char_received_get(void) to get the char.
Returns
=!0 when a char has been received.

◆ neorv32_uart1_char_received_get()

char neorv32_uart1_char_received_get ( void  )

Get a received char from UART1.

Note
This function is non-blocking.
Should only be used in combination with neorv32_uart_char_received(void).
Returns
Received char.

◆ neorv32_uart1_disable()

void neorv32_uart1_disable ( void  )

Disable UART1.

◆ neorv32_uart1_enable()

void neorv32_uart1_enable ( void  )

Enable UART1.

◆ neorv32_uart1_getc()

char neorv32_uart1_getc ( void  )

Get char from UART1.

Note
This function is blocking and does not check for UART frame/parity errors.
Returns
Received char.

◆ neorv32_uart1_getc_safe()

int neorv32_uart1_getc_safe ( char *  data)

Get char from UART1 (and check errors).

Note
This function is non-blocking and checks for frame and parity errors.
Parameters
[in,out]dataReceived char.
Returns
Status code: 0 = char received without errors -1 = nothing received -2 = char received with frame error -3 = char received with parity error -4 = char received with overrun error.

◆ neorv32_uart1_print()

void neorv32_uart1_print ( const char *  s)

Print string (zero-terminated) via UART1. Print full line break "\r\n" for every '
'.

Note
This function is blocking.
Parameters
[in]sPointer to string.

◆ neorv32_uart1_printf()

void neorv32_uart1_printf ( const char *  format,
  ... 
)

Custom version of 'printf' function using UART1.

Note
This function is blocking.
Parameters
[in]formatPointer to format string.
sString (array of chars, zero-terminated)
cSingle char
d/i32-bit signed number, printed as decimal
u32-bit unsigned number, printed as decimal
x32-bit number, printed as 8-char hexadecimal - lower-case
X32-bit number, printed as 8-char hexadecimal - upper-case
p32-bit pointer, printed as 8-char hexadecimal - lower-case

◆ neorv32_uart1_putc()

void neorv32_uart1_putc ( char  c)

Send single char via UART1.

Note
This function is blocking.
Parameters
[in]cChar to be send.

◆ neorv32_uart1_scan()

int neorv32_uart1_scan ( char *  buffer,
int  max_size,
int  echo 
)

Simplified custom version of 'scanf' function for UART1.

Note
This function is blocking.
Parameters
[in,out]bufferPointer to array of chars to store string.
[in]max_sizeMaximum number of chars to sample.
[in]echoEcho UART input when 1.
Returns
Number of chars read.

◆ neorv32_uart1_setup()

void neorv32_uart1_setup ( uint32_t  baudrate,
uint8_t  parity,
uint8_t  flow_con 
)

Enable and configure secondary UART (UART1).

Note
The 'UART1_SIM_MODE' compiler flag will configure UART1 for simulation mode: all UART1 TX data will be redirected to simulation output. Use this for simulations only!
To enable simulation mode add <USER_FLAGS+=-DUART1_SIM_MODE> when compiling.
Warning
The baud rate is computed using INTEGER operations (truncation errors might occur).
Parameters
[in]baudrateTargeted BAUD rate (e.g. 9600).
[in]parityParity configuration (00=off, 10=even, 11=odd), see NEORV32_UART_PARITY_enum.
[in]flow_conHardware flow control configuration (00=off, 01=RTS, 10=CTS, 11=RTS/CTS), see NEORV32_UART_FLOW_CONTROL_enum.

◆ neorv32_uart1_tx_busy()

int neorv32_uart1_tx_busy ( void  )

Check if UART1 TX is busy (transmitter busy or data left in TX buffer).

Note
This function is blocking.
Returns
0 if idle, 1 if busy

◆ putchar()

int putchar ( int  ch)

Send char via UART0

Parameters
[in]Charto be send.
Returns
Char that has been sent.