您尚未登录。

楼主 # 2022-08-03 20:11:58

HonestQiao
会员
注册时间: 2022-08-03
已发帖子: 1
积分: 51

无需MRS,MC3172在多平台上的编译(基于梦程大佬的CMake模板)

梦程大佬提供了MC3172的CMake工程,网址是:https://github.com/dreamcmi/MC3172-CMake/

我的工作环境是macOS,之前使用赛昉科技RISC-V星光派时,用过赛昉的编译工具链,提供了Linux、Windows、macOS环境,非常好用。
该编译工具链,我后来使用CH32V307开发板时,发现也很好用。
这次感芯提供了一块MC3172的工程板,因为也是RISC-V的,所以试用了一下,也很好用,先分享给大家。


1. 下载赛昉RISC-V编译工具链:
网址是:https://github.com/sifive/freedom-tools/releases/
按照当前平台下载好对应的:
macOS环境:
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv-openocd-0.10.0-2020.12.1-x86_64-apple-darwin.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/sdk-utilities-1.0.1-2020.12.1-x86_64-apple-darwin.tar.gz

centos6环境:
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-centos6.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv-openocd-0.10.0-2020.12.1-x86_64-linux-centos6.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/sdk-utilities-1.0.1-2020.12.1-x86_64-linux-centos6.tar.gz

ubuntu:
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv-openocd-0.10.0-2020.12.1-x86_64-linux-ubuntu14.tar.gz
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/sdk-utilities-1.0.1-2020.12.1-x86_64-linux-ubuntu14.tar.gz

Windows环境:
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-w64-mingw32.zip
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv-openocd-0.10.0-2020.12.1-x86_64-w64-mingw32.zip
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/sdk-utilities-1.0.1-2020.12.1-x86_64-w64-mingw32.zip


2. 下载CMake工程:
网址:https://github.com/dreamcmi/MC3172-CMake/

3. 设置工具链:
1) 解压上面的编译链工具,并找到 riscv64-unknown-elf-gcc 的目录,路径参考下面的:
/Users/HonestQiao/Projects/starfive/freedom-tools/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin/bin/riscv64-unknown-elf-gcc

上述路径中的/Users/HonestQiao/Projects/starfive/freedom-tools/,是我的macOS上的路径,请根据实际情况修改,下同


2)打开MC3172-CMake/CMakeLists.txt,修改其中工具链部分的配置:
macOS、Linux环境:具体路径请根据实际情况修改

# 工具链设置
set(TOOLPATH  /Users/HonestQiao/Projects/starfive/freedom-tools/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin/bin/riscv64-unknown-elf-)
set(CMAKE_C_COMPILER ${TOOLPATH}gcc)
set(CMAKE_CXX_COMPILER ${TOOLPATH}g++)
set(CMAKE_ASM_COMPILER ${TOOLPATH}gcc)
set(CMAKE_AR ${TOOLPATH}ar)
set(CMAKE_OBJCOPY ${TOOLPATH}objcopy)
set(CMAKE_OBJDUMP ${TOOLPATH}objdump)
set(SIZE ${TOOLPATH}size)

Windows环境:具体路径请根据实际情况修改

set(TOOLPATH  D:/0wch/toolchain/RISCVEmbeddedGCC/bin/riscv-none-embed-)
set(CMAKE_C_COMPILER ${TOOLPATH}gcc.exe)
set(CMAKE_CXX_COMPILER ${TOOLPATH}g++.exe)
set(CMAKE_ASM_COMPILER ${TOOLPATH}gcc.exe)
set(CMAKE_AR ${TOOLPATH}ar.exe)
set(CMAKE_OBJCOPY ${TOOLPATH}objcopy.exe)
set(CMAKE_OBJDUMP ${TOOLPATH}objdump.exe)
set(SIZE ${TOOLPATH}size.exe)

4. 编译:

cd MC3172-CMake
mkdir build
cd build
cmake ../CMakeLists.txt
make

执行make后,输出如下,表示成功:

[ 25%] Building C object CMakeFiles/mc3172-cmake.elf.dir/MC3172/thread_start.c.obj
[ 50%] Building C object CMakeFiles/mc3172-cmake.elf.dir/USER_CODE/GPIO_GPCOM_TIMER_Example.c.obj
[ 75%] Building C object CMakeFiles/mc3172-cmake.elf.dir/USER_CODE/main.c.obj
[100%] Linking C executable mc3172-cmake.elf
Memory region         Used Size  Region Size  %age Used
      CODE_SPACE:        1374 B      65520 B      2.10%
      DATA_SPACE:         256 B      61248 B      0.42%
[100%] Built target mc3172-cmake.elf

5. 下载:
使用感芯提供 GX_ISPTool 工具,下载MC3172-CMake/build/mc3172-cmake.hex 即可


现在,可以在当前环境中编译了,就可以用vscode进行开发了。

最近编辑记录 HonestQiao (2022-08-03 20:14:10)

离线

#1 2022-08-03 22:36:22

support_gxchip
Moderator
注册时间: 2022-07-26
已发帖子: 24
积分: 103

Re: 无需MRS,MC3172在多平台上的编译(基于梦程大佬的CMake模板)

感谢大佬分享,这次各个OS都有了。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn