Getting Started

Minimum Required Versions of Dependencies

Name

Version

CMake

3.13

Python

3.8

Install Dependencies

Take Ubuntu as example

  1. Install Tools

    sudo apt install build-essential cmake ninja-build libc6-i386 libc6-i386-cross libstdc++6-i386-cross
    
  2. Install Python 3 (3.8.5 minimum) and pip

    sudo apt install python3 python3-pip
    

Prepare Toolchain & Environment Variables

Supported Toolchains

  • gnu-gcc (default toolchain)

  • nds-gcc

  • zcc

Toolchain Setup

  1. Download and Unzip the Toolchain

    • Unzip the toolchain package to a specific path (e.g., TOOLCHAIN_PATH). The executable riscv32-unknown-elf-gcc should be located in TOOLCHAIN_PATH/bin.

  2. Set Environment Variables

    Assume using zsh

    export GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH
    export HPM_SDK_TOOLCHAIN_VARIANT=
    

Environment Variables

source env.sh

Install Python Dependencies

pip3 install --user -r "$HPM_SDK_BASE/scripts/requirements.txt"

Build an Application with GNU GCC Toolchain

After completing the steps above, SDK projects can be generated and built. The following steps describe how to build a demo (e.g., hello_world):

  1. Navigate to the Application Directory

cd samples/hello_world
  1. Create a Build Directory

mkdir build
  1. Change Directory to “build”

cd build
  1. Generate Build Files for Ninja

cmake -GNinja -DBOARD=hpm6750evkmini ..

Note

If it complains about “CMAKE_MAKE_PROGRAM is not set,” append -DCMAKE_MAKE_PROGRAM=YOUR_MAKE_EXECUTABLE_PATH to the previous command. (Replace NINJA_PATH with the folder where ninja is located):

cmake -GNinja -DBOARD=hpm6750evkmini -DCMAKE_MAKE_PROGRAM=NINJA_PATH/ninja ..
  1. Build the Project

ninja

When the build is complete, the ELF file and other application-related files (e.g., map file, assembly source, or binary file) can be found in the output directory.

Quick Guide to Run/Debug an Application (hello_world)

  1. Wire Up the Board

  • Include the debug probe (by default, it supports JLink) and serial port.

  1. Power Up the Board

  2. Open a Console

  • Connect to the debug console (target serial port) with a baud rate of 115200.

  1. Install OpenOCD

  • It can be installed via a package management system or downloaded from SourceForge or GitHub. Ensure its revision is > 0.11.

  1. Set Environment Variables

source env.sh
  1. Start OpenOCD

  • Use several configuration files in the order of probe type, core type, and board type. For example, the following command sets up an OpenOCD GDB server with an FT2232 probe for a single core on the HPM6750EVKMini:

    openocd -f probes/ft2232.cfg -f soc/hpm6750-single-core.cfg -f boards/hpm6750evkmini.cfg
    

Note

If using an FTDI debugger and encountering the error Error: libusb_open() failed with LIBUSB_ERROR_NOT_FOUND, check the FTDI USB driver. If it is not installed correctly, use zadig to update:
  • Open zadig, click Options -> List All Devices.

  • Select Dual RS232-HS (Interface 0).

  • Click Install Driver or Replace Driver.

  1. Navigate to the hello_world Directory

cd samples/hello_world
  1. Start a GDB Client in Another Terminal

TOOLCHAIN_PATH/bin/riscv32-unknown-elf-gdb
  1. Connect the GDB Client to the GDB Server

gdb> file build/output/demo.elf
gdb> target remote localhost:3333
gdb> load
gdb> b main
gdb> c
  1. Verify the Output

  • On the debug console, “hello_world” should be printed.

Build an Application with Segger Embedded Studio

  1. Download Segger Embedded Studio for RISC-V

    • It can be downloaded from Segger.

  2. Generate Project File

    • The project file for Segger Embedded Studio will be generated while generating build files for Ninja (as mentioned in Build an Application with GNU GCC Toolchain -> “4. Generate Build Files for Ninja”).

    • The project file (.emProject) can be found at build/segger_embedded_studio/.

    Note

    The openocd executable needs to be found in the PATH variable of the current console. Otherwise, the debug configuration will not be generated in the project file and needs to be configured manually in Segger Embedded Studio later.