Docker Template Stack STM32-F4

A Docker container for microcontroller bare-bone projects

View project on GitHub



This file is part of: STM32F4 Template Stack Copyright (c) 2025 Nico Jan Eelhart This source code is licensed under the MIT License found in the ‘LICENSE.md’ file in the root directory of this source tree.

Some header files in this project are © STMicroelectronics and used under their permissive license. See license notices in each file, and refer to: https://www.st.com/en/microcontrollers-microprocessors/stm32f4-series.html


Debug Output in Terminal via USART

1 Output

To display (debug) output to a terminal, on your host, there are 3 functions defined in the file: \startup-code\syscalls.c

  1. USART_Init(...)
  2. _write_impl_USART_SendChar(...)
  3. _write(...)

When USART2_Init(...) is called during the initialization phase of your program, you can use standard output functions such as:

printf("Debug this variable: %s\r\n",var1);     // Note the \r\n instead of just \n
puts("Enter function: HelloWorld()\r\n ");

The output will appear in a terminal emulator like PuTTY, provided the hardware and serial connection are correctly configured.

📍 More documentation can be found in the above meantioned syscalls.c file.

2 Input

Just like output above the syscalls.c also implements the system function: int _read(...) which makes sure you can ask for input in your PuTTy terminal with scanf function or by calling the function direct.

char name[50];   
unsigned  len = 50;    
_read(0, name, len);        // CR Return will end the input

3 Configure PuTTY

Assuming the files are already part of your project, and you’re using the STM32F4-Discovery board (or a compatible one):

  1. Hardware Requirements:
    • Make sure you have a USB-to-TTL Serial Cable (USB connector on one side and four lose connectors on the otherside, see remark below)
  2. Wiring: Connect the USB-to-TTL cable between your host and the STM32 board:

    • USB-to-TTL TX → STM32 PA3 (USART2 RX) (White)
    • USB-to-TTL RX → STM32 PA2 (USART2 TX) (Green)
    • GND → GND (black)
    • Power → NOT needed (red)
  3. Make the connection

    • On the Host (Windows)
      • Locate the used COM port number using Windows Device manager
      • In the Host start Putty and configure it:
      • set the connection type to: serial
      • enter the COM Port number
      • specify the speed: 9600

Once everything is connected and the program runs, output from the device will appear in the terminal.


Remark

I used a cable like: Exactly this ( alternative 1 alternative 2 )

In Device Manager it shows up like: Silicon Labs CP210x usa to UART Bridge (COM3)

Home Sites
















Maintained by NicoJanE. Generated by GitHub Pages.