🛠 Set up a serial console on HPM5100
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
- HPM5100 development board (HPM5151 model or compatible).
- USB Type-C or Micro-USB cable depending on your board's connector.
- A computer with a serial terminal (PuTTY, Tera Term, or HPMicro IDE).
- HPMicro SDK v1.13.0 installed and configured.
Steps
- 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.
- 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.
- Software Initialization: In the
main.cfile, 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. - Sending Code Implementation: Implement a simple
uart_send_stringfunction. 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. - 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.
- 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.