RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
Bsp_printf Config (Legacy)

Overview

Only applicable when using setting (NEWLIB=NOSTD) in makefile. Toggle between the Lite and Full printf implementations and enable specific format specifiers.

Note
When NEWLIB=NANO in makefile, it uses optimized printf from the C library, and these settings will have no effect.
When NEWLIB=NOSTD in makefile, it overrides printf with the legacy bsp_printf defined in this module, and these settings will configure the behavior of that custom printf.

Printf Module Selection

Printf Wrapper Helper, ignore it.

Toggle between the Lite and Full printf implementations.

#define ENABLE_BSP_PRINTF   1
 (Lite) Supports char, string, decimal, hex, floats. Moderate memory footprint.
#define ENABLE_BSP_PRINTF_FULL   1
 (Full) Full support including flags and precisions. Larger memory footprint.
#define ENABLE_BRIDGE_FULL_TO_LITE   1
 Enable function sharing between 'full' and 'lite' printing modules.
#define ENABLE_PRINTF_WARNING   1
 Print a warning message when a format specifier is not supported.

Extended Format Specifier Support

Enable specific data types (Costs extra memory).

#define ENABLE_FLOATING_POINT_SUPPORT   0
 Support for f (Printing only).
#define ENABLE_FP_EXPONENTIAL_SUPPORT   0
 Support for e / E.
#define ENABLE_PTRDIFF_SUPPORT   0
 Support for t (Pointer differences).
#define ENABLE_LONG_LONG_SUPPORT   1
 Support for lld / llu.

Introduction

Following are the available printf function when Non-standard library (NEWLIB=NOSTD) is in used.

Bsp_printf (Lightweight Printf)

bsp_printf is a lightweight alternative to the standard C library printf. It supports a minimal set of format specifiers to significantly reduce the compiled binary size. bsp_printf is automatically enabled when the project is compiled with NEWLIB = NOSTD.

It supports the following standard format specifiers:

  • c — Character
  • s — String
  • d — Decimal integer
  • x — Hexadecimal integer
  • f — Floating-point number

Single-Format Print Functions (Ultra-lightweight Printf)

For even stricter control over user's code footprint, the BSP provides ultra-lightweight functions that only handle one specific format type at a time:

  • bsp_printf_s — Prints a formatted string.
  • bsp_printf_c — Prints a single character.
  • bsp_printf_d — Prints a decimal integer.
  • bsp_printf_x — Prints a hexadecimal value in lowercase.
  • bsp_printf_X — Prints a hexadecimal value in uppercase.
Note
To print floating-point numbers (f), User must set ENABLE_FLOATING_POINT_SUPPORT to 1 in bsp.h. This definition automatically defaults to enabled if the hardware Floating-Point Unit (FPU) is included in the SoC's IP configuration.

Bsp_print_full (Floating Point Support)

Bsp_printf_full is based on open-source Tiny Printf implementation. This printf function supports most of the specifiers. Bsp_print_full is disabled by default. Bsp_printf_full can be enabled by setting the ENABLE_BSP_PRINTF_FULL to 1 in the bsp.h file.

The bsp_printf_full follows the following prototype: %[flags][width][.precision][length]type

Supported Format Types:

Type Description
d or i Signed decimal integer
u Unsigned decimal integer
b Unsigned binary
o Unsigned octal
x Unsigned hexadecimal integer (lowercase)
X Unsigned hexadecimal integer (uppercase)
f or F Decimal floating point
e or E Scientific-notation (exponential) floating point
g or G Scientific or decimal floating point
c Single character
s String of characters
p Pointer address
%% Outputs a literal % character
Note
By enabling ENABLE_BRIDGE_FULL_TO_LITE in the bsp.h file and the bsp_printf is disabled, bsp_printf_full can be called with bsp_printf instead. This would be beneficial if the program is already using the bsp_printf but requires additional specifiers support that is supported only in bsp_printf_full function

Macro Definition Documentation

◆ ENABLE_BRIDGE_FULL_TO_LITE

#define ENABLE_BRIDGE_FULL_TO_LITE   1

#include <bsp.h>

Enable function sharing between 'full' and 'lite' printing modules.

Definition at line 160 of file bsp.h.

◆ ENABLE_BSP_PRINTF

#define ENABLE_BSP_PRINTF   1

#include <bsp.h>

(Lite) Supports char, string, decimal, hex, floats. Moderate memory footprint.

Definition at line 154 of file bsp.h.

◆ ENABLE_BSP_PRINTF_FULL

#define ENABLE_BSP_PRINTF_FULL   1

#include <bsp.h>

(Full) Full support including flags and precisions. Larger memory footprint.

Definition at line 157 of file bsp.h.

◆ ENABLE_FLOATING_POINT_SUPPORT

#define ENABLE_FLOATING_POINT_SUPPORT   0

#include <bsp.h>

Support for f (Printing only).

Definition at line 171 of file bsp.h.

◆ ENABLE_FP_EXPONENTIAL_SUPPORT

#define ENABLE_FP_EXPONENTIAL_SUPPORT   0

#include <bsp.h>

Support for e / E.

Definition at line 172 of file bsp.h.

◆ ENABLE_LONG_LONG_SUPPORT

#define ENABLE_LONG_LONG_SUPPORT   1

#include <bsp.h>

Support for lld / llu.

Definition at line 174 of file bsp.h.

◆ ENABLE_PRINTF_WARNING

#define ENABLE_PRINTF_WARNING   1

#include <bsp.h>

Print a warning message when a format specifier is not supported.

Definition at line 163 of file bsp.h.

◆ ENABLE_PTRDIFF_SUPPORT

#define ENABLE_PTRDIFF_SUPPORT   0

#include <bsp.h>

Support for t (Pointer differences).

Definition at line 173 of file bsp.h.