🛠 Set up a serial console on HPM5100

HPMicro HPM5100: 400 MHz RISC-V MCU for Motor Control and Analog Sensing · debutant · Apprenez à configurer l'UART pour afficher des messages de débogage sur le terminal de votre PC.

Objectives

This tutorial aims to configure the UART interface of the HPM5100 microcontroller to establish serial communication with a computer. This is a fundamental step for any embedded development, allowing you to display log messages, debug code, and interact with the program via the serial port. You will learn how to initialize the peripheral, configure the baud rate, and send data.

Required Hardware

Steps

  1. Environment Preparation: Open your IDE or terminal and navigate to the UART example folder in the SDK. The HPM5100 features 5 independent UARTs; we will use UART0 by default as it is often routed to the board's USB serial connector.
  2. Hardware Configuration: Check the pins associated with UART0 in your board's schematic. Generally, TX (transmit) and RX (receive) must be correctly mapped via the signal matrix (Pinmux). Ensure these pins are not used by other critical peripherals like PWM or ADC.
  3. Software Initialization: In the main.c file, include the necessary headers. Initialize the system clock to ensure the UART receives the correct clock signal. Configure the UART control register to set the baud rate to 115200 bps, a reliable standard for debugging.
  4. Sending Code Implementation: Implement a simple uart_send_string function. This function must check if the transmit buffer is empty before writing each character. For beginners, it is advisable to use a blocking wait loop (while(busy)) to simplify the initial logic.
  5. Compilation and Download: Compile the project in Debug mode. Use the SDK's flash tool to load the binary onto the HPM5100 board. The 1 MB SiP Flash memory is more than sufficient for this example.
  6. Terminal Connection: Open your serial terminal on the computer. Select the COM port corresponding to the board. Set the parameters: 115200 baud, 8 data bits, 1 stop bit, no parity.

Verification

Once the program is running, you should see a message like "Hello HPM5100" followed by a counter incremented every second displayed in the terminal. If nothing appears, check the COM port, baud rate, and physical TX/RX connections. The absence of a message often indicates a Pinmux or clock configuration error.

Further Reading

Explore UART interrupts to avoid blocking loops and free up the RISC-V core. You can then integrate FreeRTOS to create a dedicated task for managing serial communications, thereby improving your application's responsiveness.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials