2.4 Linux development environment
1. Tools needed to compile K210
We are building the K210 development environment through the VSCode editor with the Win10 system. The following are the tools we need.
1-CMake.
2-Toolchain.
3-VSCode.
4-K210-SDK.
5-flash.
2. Install CMake
2.1 Verify whether CMake be installed
If you have already installed it and the CMake version is greater than 3.0, you do not need to re-install it, you can skip the step of installing CMake.
Open the Ubuntu terminal and enter the following command. If the following interface appears, it means that CMake is not installed.
cmake -version
Tip, we use Ubuntu 18.04 bit system as a example.
2.2 Download and install Cmake and make
Method-1:
Input following command to install cmake:
sudo apt-get install cmake -y
sudo apt-get install make -y
Due to network problems, downloading takes a long time, please be patient.
Method-2:
Download cmake by Ubuntu's own software manager.
Search “cmake”.
Click “Install”, start install.
After installation is complete. Click “Launch” to run CMake.
At the same time, there is also a CMake icon in the Ubuntu application.
2.3 Check and verify CMake
Open the terminal, enter cmake -version.
If you can see the CMake version number you installed, it means the installation is successful.
3. Install the cross compiler Toolchain
3.1 We have provided this toolchain file (kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz), please download from this -> [K210 Tools].
3.2 Extract toolchain file
Transfer kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz file to Downloads director.
Enter Downloads director. Input following command:
cd Downloads
tar zxvf kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz
After extract is completed, we will get a kendryte-toolchain folder.
3.3 Input following command to move all the contents of the kendryte-toolchain folder to the /opt directory.
sudo mv kendryte-toolchain /opt
4. Add toolchain to the environment variable and make it effective.
Input following command to edit/etc/profile
sudo nano /etc/profile
Enter the user password correctly and press Enter to confirm.
Add the following at the bottom.
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/kendryte-toolchain/bin
export LD_LIBRARY_PATH
/opt/kendryte-toolchain/bin is toolchain install path, you need to modify it according to the actual installation path.
3. Install VSCode editor
3.1 Download VSCode editor
VSCode official download address: https://code.visualstudio.com/Download
According to your own system version, you can choose version. I choose [System Installer 64bit], and downloaded .exe file.
Then, we can install it directly, it can be used by all users.
3.2 Install VSCode
Method-1:
Double-click to run to download the VSCode installation package .deb file, then the Ubuntu software manager interface will pop up, just click Install.
Method-2:
Ensure that the downloaded code installation package .deb file is in the current directory, and input the following command to install:
sudo dpkg -i code_1.45.1-1589445302_amd64.deb
Enter the user password correctly and press Enter to confirm.
3.3 Testing VSCode
input the following command to open VSCode.
code .
4.Download K210 software SDK
K210 official provide two SDK.
Bare machine version SDK and freertos SDK
Eg: we use a Bare machine version SDK
4.1 Download K210 Bare machine version SDK
Click “Clone or download”---> click “Download ZIP” download SDK.
We have provide this file, please click [Tools] to download this file.
4.2 After download is complete. Input following command to extract .zip file.
unzip kendryte-standalone-sdk-develop.zip
4.3 Open SDK by VSCode.
Enter SDK directory and input following command.
cd kendryte-standalone-sdk-develop
code .
5.Compile program
5.1 Open SDK by VSCode.
5.2 View the main.c file of the hello_world project in the src folder. When we run the modified program, it will print out the data from the USB serial port.
As shown below.
5.3 Create build folder
Enter the following command in the Ubuntu terminal to create the build folder.
Enter the build. The build folder is used to save the files generated by cmake compilation, and it is also the save path of the write firmware.
mkdir build
cd build
5.4 CMake compile program
cmake .. -DPROJ=hello_world -DTOOLCHAIN=/opt/kendryte-toolchain/bin
5.5 make compile program
5.6 Input command ls to View the generated file.
6. Write program into K210 board
6.1 Install pip3
Ubuntu18.04 comes with Python3, but does not come with pip3, you can enter the following command to install pip3.
If pip3 is already installed, please ignore this step.
sudo apt-get install python3-pip -y --fix-missing
6.2 Install kflash
witch to root user, enter the following command to install kflash.
sudo pip3 install kflash
6.3 Input following command to add the current user name to the dial group.
(You need tp replace $(whoami) with your username.)
sudo usermod -a -G dialout $(whoami)
6.4 Enter the following command to check kflash.
kflash --help
6.5 The source code of kflash.py can be viewed at the following URL.
https://github.com/kendryte/kflash.py
6.6 View K210 board port.
connect the computer to the K210 development board through the Type-C data cable. And open the power switch of K210 board.
Input following command to view K210 board port.
ls /dev/ttyUSB*
We can port is /dev/ttyUSB0
6.7 Write firmware
Switch to the K210-SDK directory and find the hello_world.bin file just compiled.
As shown below.
Enter the following commands to burn to the K210 development board.
-p means the port,
-t means the terminal will be opened automatically after the burning is completed,
hello_world.bin is the name of the firmware to be burned, you can modify it according to the actual situation.
sudo kflash -p /dev/ttyUSB0 -t hello_world.bin
After the firmware is write, the serial terminal of the K210 will be opened automatically, and it will print the information.
Press CTRL + ] to exit the K210 serial terminal.