Getting Started
Minimum Required Versions of Dependencies
Name |
Version |
|---|---|
CMake |
3.13 |
Python |
3.8 |
Install Dependencies
Take Ubuntu as example
Install Tools
sudo apt install build-essential cmake ninja-build libc6-i386 libc6-i386-cross libstdc++6-i386-cross
Install Python 3 (3.8.5 minimum) and pip
sudo apt install python3 python3-pip
Install Chocolatey
Chocolatey is a package manager for Windows that simplifies the installation of native Windows dependencies.
Install Chocolatey by following the instructions on the Chocolatey Install page.
Open “cmd.exe” as “Administrator”.
Disable global confirmation to avoid having to confirm the installation of individual programs:
choco feature enable -n allowGlobalConfirmation
Install CMake
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
Install Other Tools
choco install git python ninja
Close the Administrator Command Prompt Window
Prepare Toolchain & Environment Variables
Supported Toolchains
gnu-gcc (default toolchain)
nds-gcc
zcc
Toolchain Setup
Download and Unzip the Toolchain
Download the RISC-V GNU toolchain from the HPMicro official GitHub releases.
Unzip the toolchain package to a specific path (e.g.,
TOOLCHAIN_PATH). The executableriscv32-unknown-elf-gccshould be located inTOOLCHAIN_PATH/bin.
Set Environment Variables
Assume using zsh
export GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH export HPM_SDK_TOOLCHAIN_VARIANT=
set GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH set HPM_SDK_TOOLCHAIN_VARIANT=
Download and Unzip the Toolchain
Unzip the toolchain package to a specific path (e.g.,
TOOLCHAIN_PATH). The executableriscv32-elf-gccshould be located inTOOLCHAIN_PATH/bin.
Set Environment Variables
Assume using zsh
export GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH export HPM_SDK_TOOLCHAIN_VARIANT=nds-gcc
set GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH set HPM_SDK_TOOLCHAIN_VARIANT=nds-gcc
Note
For Windows, the Andes compiler requires the following libraries: -
cygwin1.dll-cygncursesw-10.dllEnsure their paths are appended to the system environment variablePATH.
Download and Unzip the Toolchain
Unzip the toolchain package to a specific path (e.g.,
TOOLCHAIN_PATH).
Set Environment Variables
export GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH export HPM_SDK_TOOLCHAIN_VARIANT=zcc
set GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH set HPM_SDK_TOOLCHAIN_VARIANT=zcc
Environment Variables
source env.sh
env.cmd
Manually declare an environment variable HPM_SDK_BASE pointing to the SDK root path.
using zsh, assuming SDK is located at $HOME/hpm_sdk
export HPM_SDK_BASE=$HOME/hpm_sdk
assuming SDK is located at c:\hpm_sdk
set HPM_SDK_BASE=c:\hpm_sdk
Install Python Dependencies
pip3 install --user -r "$HPM_SDK_BASE/scripts/requirements.txt"
By default, python3/pip3 is not available after installing Python 3.x on Windows. Only python/pip is available.
pip install --user -r "%HPM_SDK_BASE%/scripts/requirements.txt"
CMake Build System
The HPM SDK provides a comprehensive CMake-based build system that offers:
Cross-platform compatibility across Windows, macOS, and Linux
Multiple toolchain support including GNU GCC, NDS GCC, and ZCC
Flexible board configuration with custom board support
IDE integration for various development environments
SOC-agnostic application development with automatic dependency management
For detailed information about using the CMake build system, including advanced configuration options, custom board setup, and best practices, please refer to the SDK CMake User Guide.
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):
Navigate to the Application Directory
cd samples/hello_world
Create a Build Directory
mkdir buildmd build
Change Directory to “build”
cd build
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_PATHto the previous command. (ReplaceNINJA_PATHwith the folder whereninjais located):cmake -GNinja -DBOARD=hpm6750evkmini -DCMAKE_MAKE_PROGRAM=NINJA_PATH/ninja ..
Build the Project
ninjaWhen 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
outputdirectory.
Quick Guide to Run/Debug an Application (hello_world)
Wire Up the Board
Include the debug probe (by default, it supports JLink) and serial port.
Power Up the Board
Open a Console
Connect to the debug console (target serial port) with a baud rate of 115200.
Install OpenOCD
Download OpenOCD from the HPMicro official GitHub releases, or compile the riscv-hpmicro branch from the repository. This repository only adds flash operation algorithms compared to the upstream OpenOCD.
Set Environment Variables
source env.shenv.cmd
Alternatively, set the
OPENOCD_SCRIPTSenvironment variable manually:set OPENOCD_SCRIPTS=%HPM_SDK_BASE%\boards\openocd
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.cfgNote
- 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 DriverorReplace Driver.
Navigate to the hello_world Directory
cd samples/hello_world
Start a GDB Client in Another Terminal
TOOLCHAIN_PATH/bin/riscv32-unknown-elf-gdbTOOLCHAIN_PATH/bin/riscv32-elf-gdb
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
Verify the Output
On the debug console, “hello_world” should be printed.
Build an Application with Segger Embedded Studio
Download Segger Embedded Studio for RISC-V
It can be downloaded from Segger.
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
openocdexecutable needs to be found in thePATHvariable 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.