A Guide to Setup Command Line Development Environment for K210


  • Staff |  Mod

    A Guide to Setup Command Line Development Environment for K210

    Introduction

    This guide introduces how to setup command line development environment for K210 in Ubuntu or Windows seperately.

    Note: If you're used to IDE, please download here.

    Ubuntu

    Install Toolchain

    1. Install build-essential to get make tool.
    $ sudo apt install build-essential
    
    1. Install cmake.
    $ sudo apt install cmake
    
    1. Download toolchain from Kendryte website. Choose the version for Ubuntu, and V8.2.0 is recommended.

      Move the toolchain package to /opt and uncompress it.

    $ sudo mv kendryte-toolchain-ubuntu-amd64-8.2.0.tar.gz /opt
    $ cd /opt
    $ sudo tar -zxvf kendryte-toolchain-ubuntu-amd64-8.2.0.tar.gz
    

    ​ Add /opt/kendryte-toolchain/bin to PATH. Open ~/.bashrc and append the following line at the end.

    export PATH=$PATH:/opt/kendryte-toolchain/bin
    

    ​ Then enable the modification.

    $ source ~/.bashrc
    

    Install JLink Driver

    1. Download JLink driver deb package from SEGGER. Here take version V6.32i for example.
    $ dpkg -i JLink_Linux_V632i_x86_64.deb
    
    1. Plug in the JLink debugger, and check whether the driver has been installed successfully. If so, the output will be like the following.
    $ JLinkExe
    SEGGER J-Link Commander V6.32i (Compiled Jul 24 2018 15:20:49)
    DLL version V6.32i, compiled Jul 24 2018 15:20:43
    
    Connecting to J-Link via USB...O.K.
    Firmware: J-Link Ultra V4 compiled Apr 20 2018 16:46:34
    Hardware version: V4.00
    S/N: 504404532
    License(s): RDI, FlashBP, FlashDL, JFlash, GDB
    VTref=1.811V
    
    
    Type "connect" to establish a target connection, '?' for help
    J-Link>
    

    Install Openocd

    Download Kendryte openocd release version for Ubuntu from Kendryte Github. Here take version kendryte-openocd-0.2.2-ubuntu64.tar.gz for example.

    $ sudo mv kendryte-openocd-0.2.2-ubuntu64.tar.gz /opt
    $ cd /opt
    $ sudo tar -zxvf kendryte-openocd-0.2.2-ubuntu64.tar.gz
    

    Note: Before Kendryte openocd can be running, some dependencies may be needed.

    $ sudo apt install libusb-dev libftdi-dev libhidapi-dev
    

    Compile & Build

    1. Download kendryte-standalone-sdk from Kendryte Github.
    $ git clone git@github.com:kendryte/kendryte-standalone-sdk.git
    
    1. Place the source file directory, hello_world for example, into kendryte-standalone-sdk/src.
    2. Enter kendryte-standalone-sdk directory, then make and enter build directory.
    3. Run cmake.
    $ cmake .. -DPROJ=hello_world -DTOOLCHAIN=/opt/kendryte-toolchain/bin
    
    1. Compile and build.
    $ make
    

    Debug

    1. Run openocd.
    $ cd /opt/kendryte-openocd
    $ ./bin/openocd -f ./tcl/kendryte.cfg
    Open On-Chip Debugger 0.10.0+dev-ga938338 (2018-09-12-11:27)
    Licensed under GNU GPL v2
    For bug reports, read
    	http://openocd.org/doc/doxygen/bugs.html
    adapter speed: 3000 kHz
    Info : J-Link Ultra V4 compiled Apr 20 2018 16:46:34
    Info : Hardware version: 4.00
    Info : VTarget = 1.811 V
    Info : clock speed 3000 kHz
    Info : JTAG tap: riscv.cpu tap/device found: 0x04e4796b (mfg: 0x4b5 (<unknown>), part: 0x4e47, ver: 0x0)
    Info : Examined RISCV core; XLEN=64, misa=0x800000000014112d
    Info : Listening on port 3333 for gdb connections
    Info : [0] Found 4 triggers
    halted at 0x80008b74 due to debug interrupt
    Info : Listening on port 6666 for tcl connections
    Info : Listening on port 4444 for telnet connections
    
    1. Run gdb.

      Enter kendryte-standalone-sdk/build directory and open another terminal.

    $ riscv64-unknown-elf-gdb hello_world --eval-command="target remote 127.0.0.1:3333"
    

    ​ where

    • hello_world is the elf file generated from compile and build process.

    • 127.0.0.1 indicates the local IP address. If a remote machine is used, its IP address should be specified instead.

    • 3333 is the port openocd is listening on .

      After connecting to openocd server successfully, you can use gdb commands such as load, break, continue etc. to start to debug.

      Note: Refer to gdb website to get manuals.

    Download

    1. Download the kflash.py script from Kendryte Github .
    2. Download binary code to K210.
    $ sudo python3 kflash.py kendryte-standalone-sdk/build/hello_world.bin
    

    Note: -p option can be used to specify the serial port.

    Windows

    Install Toolchain

    1. Download cmake for Windows and choose a version no older than V3.0. Here take V3.12.2 for example.

      Install cmake into cmake-3.12.2-win64-x64 directory, and add cmake-3.12.2-win64-x64\bin to PATH.

    2. Download toolchain from Kendryte website. Choose the version for Windows, and V8.2.0 is recommended.

      Uncompress it and add kendryte-toolchain\bin to PATH.

    Install JLink Driver

    1. Download JLink driver package for Windows from SEGGER and install it.
    2. Plug in the JLink debugger and enter SEGGER\JLink_V632i directory where JLink driver has been installed to check whether the driver has been installed successfully using cmd.
    > Jlink.exe
    

    Install Openocd

    1. Download Kendryte openocd release version for Windows from Kendryte Github and uncompress it.
    2. Run zadig-2.4.exe in kendryte-openocd\tool, Options->List all devices, select JTAG debugger and convert the vendor drivers to WinUSB drivers.

    Compile & Build

    1. Download kendryte-standalone-sdk from Kendryte Github.
    2. Place the source file directory, hello_world for example, into kendryte-standalone-sdk\src.
    3. Enter kendryte-standalone-sdk directory, then make and enter build directory.
    4. Run cmake.
    > cmake .. -DPROJ=hello_world -DTOOLCHAIN="xxxx/kendryte-toolchain/bin" -G "MinGW Makefiles"
    

    ​ where xxxx is the directory that toolchain has been uncompressed into.

    1. Compile and build.
    > mingw32-make
    

    Debug

    1. Run openocd.

      Enter kendryte-openocd directory using cmd.

    > .\bin\openocd.exe -f .\tcl\kendryte.cfg
    
    1. Run gdb.

      Enter kendryte-standalone-sdk\build directory using another cmd.

    > riscv64-unknown-elf-gdb hello_world --eval-command="target remote 127.0.0.1:3333"
    

    where

    • hello_world is the elf file generated from compile and build process.

    • 127.0.0.1 indicates the local IP address. If a remote machine is used, its IP address should be specified instead.

    • 3333 is the port openocd is listening on .

      After connecting to openocd server successfully, you can use gdb commands such as load, break, continue etc. to start to debug.

      Note: Refer to gdb website to get manuals.

    Download

    1. Download the K-flash tool for Windows from Kendryte Github.
    2. Run K-flash.exe and choose Device and Firmware, hello_world.bin for example, to Flash.

    TroubleShooting

    1. Openocd fails to run.
    • If your JLink debugger is not official, please open it and remove the jumper connecting Vref to 3.3V.
    • Check if the jumper J96 (beside the JTAG socket) is on from KD233.
    1. Cannot enter ISP when downloading a firmware.
    • Check if the two jumpers J76 and J80 are on from KD233.
    • Alternatively, reseting KD233 while connecting IO16 to GND will force K210 to enter ISP manually.


  • @nathan What you is a screen dump from the terminal. It is telling me that the tar.gz on the download site is broken.


  • Staff |  Mod

    @Asterion Did you run tar in Ubuntu's terminal?



  • This post needs to be corrected or unpinned and marked as in error. Because:

    tar -zxvf kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz 
    
    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    

    gunzip also reports same error (obviously).



  • @wfjdemmye

    我也碰到同样的问题。请问你是怎么用JTAG调试器的?谢谢。



  • 抱歉,是我理解错了,我以为TYPE-C口可以识别为Jlink;我现在插上JTAG调试器;可以连接上了。0_1550456843441_cb36c608-b62e-4cd0-a896-f2fa0884e549-image.png


  • Staff |  Mod

    @wfjdemmye JLink hasn't been found in your lsusb list. Check if the JLink icon is on in the status bar of vmvare. If not, right-click it and connect.
    0_1550456398751_ae179218-f1f5-491a-9212-1a8a5e7d5723-image.png



  • @wfjdemmye ![替代文字](0_1550341223690_ec6b57dd-e965-484e-90e8-2cc11e98abe0-image.png 图片地址)



  • hello ,i use ubuntu1604_64bit vmare ; Use the steps above to install the SDK,I can connect my device K210 board;
    ![USB设备可以找到!](0_1550340634389_581d0a13-007b-40d2-82b6-937e26adadc0-image.png 图片地址)
    ![JLinkExe连接失败?](0_1550340653771_993b3675-b945-44d9-9f2b-5e0efbbad970-image.png 图片地址)