Skip to content

Rp2350 riscv32 tool chain #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions docs/common/dev/_pico2-riscv32-toolchain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
RP2350 具有两个基于 RISC-V 的 Hazard3 核心和两个基于 Arm 的核心, 在 pico-sdk 和 pico-examples 中也增加了对 RP2350 RISC-V 核心的支持。
在操作 RISC-V 核心并使用 pico-sdk 和 pico-examples 之前,我们需要先安装对应的 RISC-V 交叉编译工具链。本文将重点讲解如何安装满足 pico-sdk 和 pico-examples 需求的 RISC-V 交叉编译工具链。

## 编译环境搭建

x86 PC

Ubuntu 24.04

## 安装依赖

```bash
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
```

## 编译 RISC-V 32 的工具链

- 克隆 RISC-V 32 工具链仓库

```bash
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
```

- 创建输出目录

```bash
mkdir /honme/radxa/riscv32_toolchain
```

- 编译

```bash
cd riscv-gnu-toolchain

mkdir build

cd build

../configure --prefix=/honme/radxa/riscv32_toolchain --with-arch=rv32gc --with-abi=ilp32 --enable-multilib

make -j$(nproc)
```

## 设置环境变量

- 将以下这行添加到 /home/radxa/.bashrc 文件中

```bash
echo 'export PATH=$HOME/riscv32_toolchain/bin:$PATH' >> ~/.bashrc
```

## 验证

### 输出版本号

```bash
radxa@radxa-Default-string:~$ riscv32-unknown-elf-gcc --version
riscv32-unknown-elf-gcc (g04696df096) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

radxa@radxa-Default-string:~$ riscv32-unknown-elf-g++ --version
riscv32-unknown-elf-g++ (g04696df096) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

### 看是否符合 pico-sdk 和 pico-examples 的需求

- 克隆 pico-sdk 仓库

```bash
git clone https://github.com/raspberrypi/pico-sdk.git

cd pico-sdk

git submodule update --init
```

- 克隆 pico-examples 仓库

```bash
git clone https://github.com/raspberrypi/pico-examples.git --branch master
```

- 编译

<pre>
export PICO_SDK_PATH=path/to/pico-sdk
<!-- prettier-ignore -->
cd pico-examples
<!-- prettier-ignore -->
mkdir build
<!-- prettier-ignore -->
cd build
<!-- prettier-ignore -->
cmake .. -DPICO_PLATFORM=<b>rp2350-riscv</b> && make -j4
Comment on lines +92 to +100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export PICO_SDK_PATH=path/to/pico-sdk
<!-- prettier-ignore -->
cd pico-examples
<!-- prettier-ignore -->
mkdir build
<!-- prettier-ignore -->
cd build
<!-- prettier-ignore -->
cmake .. -DPICO_PLATFORM=<b>rp2350-riscv</b> && make -j4
export PICO_SDK_PATH=path/to/pico-sdk
<!-- prettier-ignore-start -->
cd pico-examples
mkdir build
cd build
cmake .. -DPICO_PLATFORM=<b>rp2350-riscv</b> && make -j4
<!-- prettier-ignore-end -->

试试

Copy link
Contributor Author

@nascs nascs Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不加 "<!-- prettier-ignore -->" 无法转译空行

</pre>

- 验证编译出来的程序是否为 riscv 32 的程序

```bash
file blink/CMakeFiles/blink.dir/blink.c.o
blink/CMakeFiles/blink.dir/blink.c.o: ELF 32-bit LSB relocatable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), with debug_info, not stripped
```

由此,我们完成了 RP2350 pico-sdk 和 pico-examples 所需要的交叉编译工具链的安装。
10 changes: 10 additions & 0 deletions docs/x/x5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Radxa X5"
description: "Radxa X5"
sidebar_position: 30
slug: /x/x5
---

# Radxa X5

<DocCardList />
8 changes: 8 additions & 0 deletions docs/x/x5/software/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
description: "Radxa X5 软件开发"
sidebar_position: 4
---

# 软件开发

<DocCardList />
9 changes: 9 additions & 0 deletions docs/x/x5/software/riscv32-tool-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sidebar_position: 4
---

import TOOLCHAIN from "../../../common/dev/\_pico2-riscv32-toolchain.mdx";

# 安装 RISCV32 交叉编译工具链

<TOOLCHAIN />
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
The RP2350 has two RISC-V based Hazard3 cores and two Arm based cores, and support for the RP2350 RISC-V cores has been added to the pico-sdk and pico-examples.
Before working with RISC-V cores and using pico-sdk and pico-examples, we need to install the corresponding RISC-V cross-compilation toolchain. This article will focus on how to install the RISC-V cross-compilation toolchain for pico-sdk and pico-examples.

## Environment setup

x86 PC

Ubuntu 24.04

## Install dependencies

```bash
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
```

## Compile the RISC-V 32 toolchain

- Clone the RISC-V 32 toolchain repository

```bash
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
```

- Create an output directory

```bash
mkdir /honme/radxa/riscv32_toolchain
```

- Compile

```bash
cd riscv-gnu-toolchain

mkdir build

cd build

../configure --prefix=/honme/radxa/riscv32_toolchain --with-arch=rv32gc --with-abi=ilp32 --enable-multilib

make -j$(nproc)
```

## Set environment variables

- Add the following line to the /home/radxa/.bashrc file

```bash
echo 'export PATH=$HOME/riscv32_toolchain/bin:$PATH' >> ~/.bashrc
```

## Verify

### Output version number

```bash
radxa@radxa-Default-string:~$ riscv32-unknown-elf-gcc --version
riscv32-unknown-elf-gcc (g04696df096) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

radxa@radxa-Default-string:~$ riscv32-unknown-elf-g++ --version
riscv32-unknown-elf-g++ (g04696df096) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

### See if it meets the requirements of pico-sdk and pico-examples

- Clone the pico-sdk repository

```bash
git clone https://github.com/raspberrypi/pico-sdk.git

cd pico-sdk

git submodule update --init
```

- Clone pico-examples Repository

```bash
git clone https://github.com/raspberrypi/pico-examples.git --branch master
```

- Compile

<pre>
export PICO_SDK_PATH=path/to/pico-sdk
<!-- prettier-ignore -->
cd pico-examples
<!-- prettier-ignore -->
mkdir build
<!-- prettier-ignore -->
cd build
<!-- prettier-ignore -->
cmake .. -DPICO_PLATFORM=<b>rp2350-riscv</b> && make -j4
</pre>

- Verify that the compiled program is for riscv 32

```bash
file blink/CMakeFiles/blink.dir/blink.c.o
blink/CMakeFiles/blink.dir/blink.c.o: ELF 32-bit LSB relocatable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), with debug_info, not stripped
```

This completes the installation of the cross-compilation toolchain required for the RP2350 pico-sdk and pico-examples.
10 changes: 10 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/x/x5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Radxa X5"
description: "Radxa X5"
sidebar_position: 30
slug: /x/x5
---

# Radxa X5

<DocCardList />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
description: "Radxa X5 oftware Development"
sidebar_position: 4
---

# Software Development

<DocCardList />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sidebar_position: 4
---

import TOOLCHAIN from "../../../common/dev/\_pico2-riscv32-toolchain.mdx";

# Install the RISCV32 Cross-Compile Toolchain

<TOOLCHAIN />
Loading