How To Use

Use Basic STDIO as follows:

1. Selecting Files

Add the following source and header files to the project:

  • Core (mandatory): basic_stdio_core.c and basic_stdio_core.h

  • Interface (one interface to select):

    • UART (HAL-only): interface_io/basic_stdio_itfio_uart.c and interface_io/basic_stdio_itf_io.h

    • ITM (CMSIS-Core): interface_io/basic_stdio_itfio_itm.c and interface_io/basic_stdio_itf_io.h

    • Custom: Copy interface_io/basic_stdio_itfio_template.c into your project, implement the interface functions, and include interface_io/basic_stdio_itf_io.h

Required files when the UART interface is selected:

/Required files
        ├─ Core/
        │   ├─ basic_stdio_core.c
        │   └─ basic_stdio_core.h
        ├─ Interface/
        │   ├─ basic_stdio_itfio_uart.c
        └─  └─ basic_stdio_itf_io.h

Required files when the ITM interface is selected:

/Required files
        ├─ Core/
        │   ├─ basic_stdio_core.c
        │   └─ basic_stdio_core.h
        ├─ Interface/
        │   ├─ basic_stdio_itfio_itm.c
        └─  └─ basic_stdio_itf_io.h

Required files when a custom interface is selected:

/Required files
        ├─ Core/
        │   ├─ basic_stdio_core.c
        │   └─ basic_stdio_core.h
        ├─ Interface/
        │   ├─ basic_stdio_itfio_custom.c (copy this file from the template and adapt it)
        └─  └─ basic_stdio_itf_io.h

2. Configuration

2.1. Interface Configuration

UART Interface

  • Initialize UART with STM32 HAL (or the board BSP): enable peripheral and GPIO clocks, configure TX pins and the USART instance, set parameters (baud rate, word length, stop bits, parity, mode).

  • For detailed steps, refer to the STM32 HAL USART documentation.

ITM Interface

  • Enable SWO/ITM in the debug tool and verify that trace is active (TRCENA), ITM is enabled (ITMENA), the stimulus port is configured, and the SWO speed matches the viewer.

  • No extra code is required for Basic STDIO once ITM/SWO is active.

  • See the CMSIS-Core ITM/TPIU documentation and your toolchain’s SWO viewer guide.

Custom Interface

  • Copy the template file and implement the interface APIs.

  • Refer to the corresponding driver documentation for the exact configuration parameters.

3. Basic STDIO Initialization

Call BASIC_STDIO_Init() once after the basic hardware initialization and before entering the main loop. Use the appropriate handle for the selected interface (UART or custom), and no handle for ITM (pass NULL when applicable).

Example:

/* Select the output interface and initialize Basic STDIO */
/* UART/custom: pass the interface handle; ITM: pass NULL */
BASIC_STDIO_Init(&io_handle);   /* UART/custom example */
// BASIC_STDIO_Init(NULL);      /* ITM example */

4. Basic STDIO Usage

After completing the previous steps (file selection, interface configuration, initialization), standard C library printf calls are redirected automatically. No extra API is needed: simply use printf("text\n"); anywhere after BASIC_STDIO_Init().

Example:

printf("System ready\n");
printf("Value=%d\n", value);