Loading... Kendryte K210是RISC-V Dual Core 64bit, with FPU、QVGA@60fps/VGA@30fps的AIoT方向的芯片。同时也因为采用开源的指令集,使得它可能具有无限的潜力。 我们这次依旧没有使用公版,依旧是自家的板子,但是目前还没后续消息,也不能说太多,就忽略掉相关硬件信息吧,请见谅。 # 一、Ubuntu开发环境搭建: ## 1. 获取资料 获取资料当然是应该去官方的[开发者资源中心](https://kendryte.com/downloads/),在里面可以看到资料还是比较详细的,同时也包括了工具链和SDK等等,同时开发文档有简中和繁中两种选择,这不得不说很舒服。 言归正传,我们需要下载什么呢?当然是toolchain、SDK和OpenOCD(On-Chip Debugger)了。 当然使用带有桌面的linux实体机或者虚拟机相对简单很多,如果命令行界面的话,最简单的操作步骤就是`wget URL-link`就可以了。 ``` wget https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte-openocd-0.1.3-ubuntu64.tar.gz wget https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz wget https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte-freertos-sdk-0.7.0.zip wget https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte-standalone-sdk-0.5.6.zip ``` ## 2. 安装toolchain 进入到下载文件保存的目录,将toolchain解压并放在指定目录。 ``` hulk@hulk-test:~/kendryte210$ sudo tar -xvf kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz -C /opt/ ``` 我这里面的下载目录就是`~/kendryte210`,然后使用`tar`配合`-xvf`和`-C`来解压并放在`/opt`目录下面,这个路径是自己选择的。 ``` hulk@hulk-test:~/kendryte210$ cd /opt/kendryte-toolchain/bin/ hulk@hulk-test:/opt/kendryte-toolchain/bin$ pwd /opt/kendryte-toolchain/bin ``` 我们这一步的目的是获取它的目录,然后要把它添加到系统的PATH里面,这样才能方便的使用 ``` sudo vi /etc/profile ``` 打开文件后,在文末添加一行 ``` PATH="$PATH:/opt/kendryte-toolchain/bin" ``` 然后保存退出并重载一下profile文件即可。 ``` source /etc/profile ``` 接下来就是验证一下到底有没有装好呢?利用自动补全功能即可,在命令行输入`riscv64`然后按积下TAB键,就可以看到一堆自动补全待选的内容,如果没有review上面的步骤。 ## 3. 安装OpenOCD 继续回到我们之前的下载路径,然后解压OpenOCD,并进入。 ``` hulk@hulk-test:~/kendryte210$ tar -xvf kendryte-openocd-0.1.3-ubuntu64.tar.gz hulk@hulk-test:~/kendryte210$ cd ./kendryte-openocd/ ``` 对于这个不熟悉的东西,我们可以先看下它的Readme.txt,它里面就提到了我们如何快速开始。 ``` ============== Quickstart ============== 1. Install libusb-1.0 first if you do not have: sudo apt install libusb-dev -y 2. Run the following command in the `kendryte-openocd` directory(or `check_version.sh`): ./bin/openocd -v and you will see two lines of words if it can work: Kendryte Open On-Chip Debugger For RISC-V v0.1.3 (20180912) Licensed under GNU GPL v2 ``` 我们就直接照着做就可以了。 ## 4. 开始编译 解压SDK ``` hulk@hulk-test:~/kendryte210$ unzip kendryte-standalone-sdk-0.5.6.zip hulk@hulk-test:~/kendryte210$ cd kendryte-standalone-sdk-0.5.6/ hulk@hulk-test:~/kendryte210/kendryte-standalone-sdk-0.5.6$ ls CHANGELOG.md cmake CMakeLists.txt kendryte-package.json lds lib LICENSE README.md src ``` 准备工作做完,就可以开始准备编译了。首先,我们应该先建立一个用于编译的文件夹。 ``` mkdir build cd build ``` 生成makefile,因为我们之前已经配置了相关环境 ``` hulk@hulk-test:~/kendryte210/kendryte-standalone-sdk-0.5.6/build$ cmake .. -DPROJ=hello_world PROJ = hello_world -- Check for RISCV toolchain ... -- Using /opt/kendryte-toolchain/bin RISCV toolchain -- The C compiler identification is GNU 8.2.0 -- The CXX compiler identification is GNU 8.2.0 -- The ASM compiler identification is GNU -- Found assembler: /opt/kendryte-toolchain/bin/riscv64-unknown-elf-gcc -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done SOURCE_FILES=/home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/src/hello_world/main.c Project: hello_world LIST_FILE=/home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/cmake/executable.cmake TOOLCHAIN=/opt/kendryte-toolchain/bin KENDRYTE_IDE= BUILDING_SDK=yes CMAKE_BUILD_TYPE=Debug CMAKE_C_COMPILER=/opt/kendryte-toolchain/bin/riscv64-unknown-elf-gcc CMAKE_CXX_COMPILER=/opt/kendryte-toolchain/bin/riscv64-unknown-elf-g++ CMAKE_LINKER=/opt/kendryte-toolchain/bin/riscv64-unknown-elf-ld CMAKE_OBJCOPY=/opt/kendryte-toolchain/bin/riscv64-unknown-elf-objcopy CMAKE_OBJDUMP=/opt/kendryte-toolchain/bin/riscv64-unknown-elf-objdump CMAKE_MAKE_PROGRAM=/usr/bin/make CMAKE_C_FLAGS= -mcmodel=medany -mabi=lp64f -march=rv64imafc -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fno-zero-initialized-in-bss -ffast-math -fno-math-errno -fsingle-precision-constant -Os -ggdb -std=gnu11 -Wno-pointer-to-int-cast -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Werror=frame-larger-than=32768 -Wno-unused-parameter -Wno-sign-compare -Wno-error=missing-braces -Wno-error=return-type -Wno-error=pointer-sign -Wno-missing-braces -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-error=comment -Wno-error=logical-not-parentheses -Wno-error=duplicate-decl-specifier -Wno-error=parentheses -Wno-old-style-declaration CMAKE_CXX_FLAGS= -mcmodel=medany -mabi=lp64f -march=rv64imafc -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fno-zero-initialized-in-bss -ffast-math -fno-math-errno -fsingle-precision-constant -Os -ggdb -std=gnu++17 -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Werror=frame-larger-than=32768 -Wno-unused-parameter -Wno-sign-compare -Wno-error=missing-braces -Wno-error=return-type -Wno-error=pointer-sign -Wno-missing-braces -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-error=comment -Wno-error=logical-not-parentheses -Wno-error=duplicate-decl-specifier -Wno-error=parentheses LDFLAGS= -nostartfiles -static -Wl,--gc-sections -Wl,-static -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--end-group -Wl,-EL -Wl,--no-relax -T /home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/lds/kendryte.ld CMAKE_BINARY_DIR=/home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/build Makefile created. -- Configuring done -- Generating done -- Build files have been written to: /home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/build ``` 看到`Makefile created.`,就表示OK了。 最后就可以开始编译了,可以看到如下类似的编译画面: ``` hulk@hulk-test:~/kendryte210/kendryte-standalone-sdk-0.5.6/build$ make Scanning dependencies of target kendryte [ 2%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry.c.obj [ 5%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry_user.c.obj [ 8%] Building C object lib/CMakeFiles/kendryte.dir/bsp/interrupt.c.obj [ 11%] Building C object lib/CMakeFiles/kendryte.dir/bsp/locks.c.obj [ 14%] Building C object lib/CMakeFiles/kendryte.dir/bsp/printf.c.obj [ 17%] Building C object lib/CMakeFiles/kendryte.dir/bsp/sleep.c.obj [ 20%] Building C object lib/CMakeFiles/kendryte.dir/bsp/syscalls.c.obj [ 23%] Building C object lib/CMakeFiles/kendryte.dir/drivers/aes.c.obj [ 26%] Building C object lib/CMakeFiles/kendryte.dir/drivers/apu.c.obj [ 29%] Building C object lib/CMakeFiles/kendryte.dir/drivers/clint.c.obj [ 32%] Building C object lib/CMakeFiles/kendryte.dir/drivers/dmac.c.obj [ 35%] Building C object lib/CMakeFiles/kendryte.dir/drivers/dvp.c.obj [ 38%] Building C object lib/CMakeFiles/kendryte.dir/drivers/fft.c.obj [ 41%] Building C object lib/CMakeFiles/kendryte.dir/drivers/fpioa.c.obj [ 44%] Building C object lib/CMakeFiles/kendryte.dir/drivers/gpio.c.obj [ 47%] Building C object lib/CMakeFiles/kendryte.dir/drivers/gpiohs.c.obj [ 50%] Building C object lib/CMakeFiles/kendryte.dir/drivers/i2c.c.obj [ 52%] Building C object lib/CMakeFiles/kendryte.dir/drivers/i2s.c.obj [ 55%] Building C object lib/CMakeFiles/kendryte.dir/drivers/kpu.c.obj [ 58%] Building C object lib/CMakeFiles/kendryte.dir/drivers/plic.c.obj [ 61%] Building C object lib/CMakeFiles/kendryte.dir/drivers/pwm.c.obj [ 64%] Building C object lib/CMakeFiles/kendryte.dir/drivers/rtc.c.obj [ 67%] Building C object lib/CMakeFiles/kendryte.dir/drivers/sha256.c.obj [ 70%] Building C object lib/CMakeFiles/kendryte.dir/drivers/spi.c.obj [ 73%] Building C object lib/CMakeFiles/kendryte.dir/drivers/sysctl.c.obj [ 76%] Building C object lib/CMakeFiles/kendryte.dir/drivers/timer.c.obj [ 79%] Building C object lib/CMakeFiles/kendryte.dir/drivers/uart.c.obj [ 82%] Building C object lib/CMakeFiles/kendryte.dir/drivers/uarths.c.obj [ 85%] Building C object lib/CMakeFiles/kendryte.dir/drivers/utils.c.obj [ 88%] Building C object lib/CMakeFiles/kendryte.dir/drivers/wdt.c.obj [ 91%] Building C object lib/CMakeFiles/kendryte.dir/bsp/crt.S.obj [ 94%] Linking C static library libkendryte.a [ 94%] Built target kendryte Scanning dependencies of target hello_world [ 97%] Building C object CMakeFiles/hello_world.dir/src/hello_world/main.c.obj [100%] Linking C executable hello_world Generating .bin file ... [100%] Built target hello_world ``` # 二、Windows开发环境搭建: ## 1. 获取资料 获取资料当然是应该去官方的[开发者资源中心](https://kendryte.com/downloads/),在里面可以看到资料还是比较详细的,同时也包括了工具链和SDK等等,同时开发文档有简中和繁中两种选择,这不得不说很舒服。 言归正传,我们需要下载什么呢?当然是toolchain、SDK和OpenOCD(On-Chip Debugger)了。 我们直接点击我们点击我们需要下载的包后面的下载按钮即可。 ``` Kendryte K210 FreeRTOS SDK Kendryte K210 Standalone SDK Kendryte OpenOCD for win32 RISC-V 64bit toolchain for Kendryte K210_win32 ``` ## 2. 安装toolchain 进入到下载文件保存的目录,将toolchain解压并放在指定目录。我把toolchain放在了E盘里面单独的一个文件夹`E:\Kendryte210\kendryte-toolchain`,并且进入bin文件夹,然后复制当前的目录路径,然后打开Windows的环境变量设置,将这个路径添加进去。 ![PATH](http://pic-up.yelvlab.cn/PATH.png) 这里面一定要根据你的实际存放目录来确定,并且后面一定不能删除,切记。 ## 3. 开始编译 首先在Windows下面编译,要先安装Cmake,我们可以到[Cmake官网](https://cmake.org/download/)去下载。然后一步一步安装就好了。 解压SDK,可以把SDK和刚才的toolchain放在一个目录下面`E:\Kendryte210\kendryte-standalone-sdk-0.5.6`,然后进去这个目录,我们可以按住shift+右键,打开powershell,也可以向我一样安装一个cmder,因为这个比powershell要看着舒服一些,具体用法可以百度,也可以等我后面介绍。 接下来就是创建编译需要用到的makefile ``` E:\Kendryte210\kendryte-standalone-sdk-0.5.6 $ mkdir build E:\Kendryte210\kendryte-standalone-sdk-0.5.6 $ cd build E:\Kendryte210\kendryte-standalone-sdk-0.5.6\build $ cmake .. -DPROJ=hello_world -G "MinGW Makefiles" PROJ = hello_world -- Check for RISCV toolchain ... -- Using E:/Kendryte210/kendryte-toolchain/bin RISCV toolchain -- The C compiler identification is GNU 8.2.0 -- The CXX compiler identification is GNU 8.2.0 -- The ASM compiler identification is GNU -- Found assembler: E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-gcc.exe -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done SOURCE_FILES=E:/Kendryte210/kendryte-standalone-sdk-0.5.6/src/hello_world/main.c Project: hello_world LIST_FILE=E:/Kendryte210/kendryte-standalone-sdk-0.5.6/cmake/executable.cmake TOOLCHAIN=E:/Kendryte210/kendryte-toolchain/bin KENDRYTE_IDE= BUILDING_SDK=yes CMAKE_BUILD_TYPE=Debug CMAKE_C_COMPILER=E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-gcc.exe CMAKE_CXX_COMPILER=E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-g++.exe CMAKE_LINKER=E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-ld.exe CMAKE_OBJCOPY=E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-objcopy.exe CMAKE_OBJDUMP=E:/Kendryte210/kendryte-toolchain/bin/riscv64-unknown-elf-objdump.exe CMAKE_MAKE_PROGRAM=E:/Kendryte210/kendryte-toolchain/bin/mingw32-make.exe CMAKE_C_FLAGS= -mcmodel=medany -mabi=lp64f -march=rv64imafc -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fno-zero-initialized-in-bss -ffast-math -fno-math-errno -fsingle-precision-constant -Os -ggdb -std=gnu11 -Wno-pointer-to-int-cast -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Werror=frame-larger-than=32768 -Wno-unused-parameter -Wno-sign-compare -Wno-error=missing-braces -Wno-error=return-type -Wno-error=pointer-sign -Wno-missing-braces -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-error=comment -Wno-error=logical-not-parentheses -Wno-error=duplicate-decl-specifier -Wno-error=parentheses -Wno-old-style-declaration CMAKE_CXX_FLAGS= -mcmodel=medany -mabi=lp64f -march=rv64imafc -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fno-zero-initialized-in-bss -ffast-math -fno-math-errno -fsingle-precision-constant -Os -ggdb -std=gnu++17 -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Werror=frame-larger-than=32768 -Wno-unused-parameter -Wno-sign-compare -Wno-error=missing-braces -Wno-error=return-type -Wno-error=pointer-sign -Wno-missing-braces -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-error=comment -Wno-error=logical-not-parentheses -Wno-error=duplicate-decl-specifier -Wno-error=parentheses LDFLAGS= -nostartfiles -static -Wl,--gc-sections -Wl,-static -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--end-group -Wl,-EL -Wl,--no-relax -T E:/Kendryte210/kendryte-standalone-sdk-0.5.6/lds/kendryte.ld CMAKE_BINARY_DIR=E:/Kendryte210/kendryte-standalone-sdk-0.5.6/build Makefile created. -- Configuring done -- Generating done -- Build files have been written to: E:/Kendryte210/kendryte-standalone-sdk-0.5.6/build ``` 看到`Makefile created.`就表示成功创建了makefile文件。同时可以在文件夹里面看到build目录下面生成了很多文件。 ![MakeFile](http://pic-up.yelvlab.cn/makefile.png) 现在就可以开始编译代码了。在刚才的comder里面,我们输入`mingw32-make`,就可以开始编译了。 ``` E:\Kendryte210\kendryte-standalone-sdk-0.5.6\build $ mingw32-make Scanning dependencies of target kendryte [ 2%] Building C object lib/CMakeFiles/kendryte.dir/bsp/crt.S.obj [ 5%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry.c.obj [ 8%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry_user.c.obj [ 11%] Building C object lib/CMakeFiles/kendryte.dir/bsp/interrupt.c.obj [ 14%] Building C object lib/CMakeFiles/kendryte.dir/bsp/locks.c.obj [ 17%] Building C object lib/CMakeFiles/kendryte.dir/bsp/printf.c.obj [ 20%] Building C object lib/CMakeFiles/kendryte.dir/bsp/sleep.c.obj [ 23%] Building C object lib/CMakeFiles/kendryte.dir/bsp/syscalls.c.obj [ 26%] Building C object lib/CMakeFiles/kendryte.dir/drivers/aes.c.obj [ 29%] Building C object lib/CMakeFiles/kendryte.dir/drivers/apu.c.obj [ 32%] Building C object lib/CMakeFiles/kendryte.dir/drivers/clint.c.obj [ 35%] Building C object lib/CMakeFiles/kendryte.dir/drivers/dmac.c.obj [ 38%] Building C object lib/CMakeFiles/kendryte.dir/drivers/dvp.c.obj [ 41%] Building C object lib/CMakeFiles/kendryte.dir/drivers/fft.c.obj [ 44%] Building C object lib/CMakeFiles/kendryte.dir/drivers/fpioa.c.obj [ 47%] Building C object lib/CMakeFiles/kendryte.dir/drivers/gpio.c.obj [ 50%] Building C object lib/CMakeFiles/kendryte.dir/drivers/gpiohs.c.obj [ 52%] Building C object lib/CMakeFiles/kendryte.dir/drivers/i2c.c.obj [ 55%] Building C object lib/CMakeFiles/kendryte.dir/drivers/i2s.c.obj [ 58%] Building C object lib/CMakeFiles/kendryte.dir/drivers/kpu.c.obj [ 61%] Building C object lib/CMakeFiles/kendryte.dir/drivers/plic.c.obj [ 64%] Building C object lib/CMakeFiles/kendryte.dir/drivers/pwm.c.obj [ 67%] Building C object lib/CMakeFiles/kendryte.dir/drivers/rtc.c.obj [ 70%] Building C object lib/CMakeFiles/kendryte.dir/drivers/sha256.c.obj [ 73%] Building C object lib/CMakeFiles/kendryte.dir/drivers/spi.c.obj [ 76%] Building C object lib/CMakeFiles/kendryte.dir/drivers/sysctl.c.obj [ 79%] Building C object lib/CMakeFiles/kendryte.dir/drivers/timer.c.obj [ 82%] Building C object lib/CMakeFiles/kendryte.dir/drivers/uart.c.obj [ 85%] Building C object lib/CMakeFiles/kendryte.dir/drivers/uarths.c.obj [ 88%] Building C object lib/CMakeFiles/kendryte.dir/drivers/utils.c.obj [ 91%] Building C object lib/CMakeFiles/kendryte.dir/drivers/wdt.c.obj [ 94%] Linking C static library libkendryte.a [ 94%] Built target kendryte Scanning dependencies of target hello_world [ 97%] Building C object CMakeFiles/hello_world.dir/src/hello_world/main.c.obj [100%] Linking C executable hello_world Generating .bin file ... [100%] Built target hello_world ``` 到这里Ubuntu与Windows两大常用系统下面的环境就搭建好了,怎么选择完全可以看个人了。在使用桌面版Ubuntu时,完全可以时VS Code来完成写代码,同时在Ubuntu编译(迷信编译)。后面的文章将会位大家介绍下Kflash的简单用法。 Last modification:October 12, 2020 © Allow specification reprint Like 1 If you think my article is useful to you, please feel free to appreciate