Serial Monitor [USART of STM32]

Debug programming using the USART of the STM32 MCU. Debugging is achieved by inserting microcontroller-specific tsprintf statements that display numerical values at arbitrary points in the program and displaying the data using general-purpose terminal emulator on a PC.

めかのとろ

Introducing a serial monitor application for monitor debugging, which is useful for identifying the data of calculation results inside a program, branch locations, etc.

めかのとろ

It is based on sending a string (buffered) using an interrupt. The sample program sets up serial communication USART3 for serial monitoring and defines the send function USART3_Send_String().

めかのとろ

The sample program uses the defined USART3 serial transmission to send numerical values and character strings in the program. Specifically, it converts two types of numerical values, data1 and data2, into character strings, String_data1 and String_data, and displays them alternately with the message strings stored in an array every 1000ms.

めかのとろ

The configuration for using the serial monitor is described in Embedded system program debugging in "Embedded Development Design".

めかのとろ

The usage of this application is simple, and the USART3 part and interrupt transmission related settings in this sample program can be diverted and utilized in the actual application.

めかのとろ

Since tsprintf() is used for numeric-to-string conversion, tsprintf.c and its header file tsprintf.h should be copied to the same location as the source file.

Colum

tsprintf() is a customized version of the standard output function printf() in C for the STM32 microcontroller.
In the sample example, it is used to convert the data handled in the program into character strings for transmission via serial communication.

Execution Example of tsprintf(): tsprintf(String, ,"%d",data);

The first argument of the function specifies the pointer (first address) to the array variable that will store the string, and the second argument specifies the type of number to display.

  • Decimal display:%d
  • Hexadecimal display(0-f):%x
  • Hexadecimal display(0-F):%X
  • Character:%c
  • ASCII string:%s

The third and final argument specifies the numerical data to be converted.

Follow me!