Jianan Kanzhi k230 development board unpacking and building a development environment (1)


foreword

On July 7, 2023, Canaan Technology released the software and hardware development kit of the latest generation K230 chip on the Internet. I tried to click on the released GitHub repository, and was pleasantly surprised to find that this open source project is very well done. The entire sdk project has been released, the project directory is concise and clear, and the technical documentation is also done with great care.

It happened that I encountered a closed-source problem when I used Aixin's ax620a to make a mobile AI sensor product. For me, custom hardware is not flexible and the cost is high, which is a headache. Now I just came across a seemingly suitable replacement plan, so I immediately contacted Jianan's young lady. The young lady is very enthusiastic and nice. After knowing my small needs, she also professionally explained and introduced the situation of this chip to me, and tried to provide me with this latest development board. I am so touched. >_<~+

1. Unpacking

  • I unpacked it immediately after receiving it, and I was a little excited. First of all, there are small cards and stickers for precautions, small details with careinsert image description here
  • Then there is the main body, which is bigger than expected. Then there is a small complaint, that is, the decorative panel on the LCD is too thin and fragile, and there is no protective edging on the four sides. Perhaps this screen was directly used in those smart door lock products.insert image description here
  • Accessories are two typec cables and a typec to ethernet cableinsert image description here
  • The protagonist is the big and small core controller with k230 printed on it.insert image description here
  • High-definition camera and LCD, the speed of the preview screen is still good for the first impression
    insert image description here

2. Understanding of operating system concepts

Compared with the previous generation of Internet celebrity products K210, k230 uses a more complex Linux&RT-smart dual-core heterogeneous system. The development environment needs to use the container environment built by docker under ubuntu for cross-compilation, and the development language is currently mainly c/c++.
Among them, the small core runs the linux system and realizes services such as linux driver and network control. The big core runs the RT-smart system to realize the control of the camera sensor and audio and video hardware. The large and small cores need to use their own cross-compilation tool chains, and the communication between them needs to use a set of inter-core communication APIs . File access between large and small cores uses a shared file system called Sharefs . insert image description here
In actual experience, the linux side is a standard linux buildroot, and the CLI on the rt-smart side is similar to linux, so both are relatively simple to operate.

3. Use vscode to build a development environment

To quickly learn how to use a new solution, of course, directly look at the application demo/example inside, so it is very necessary to use a good IDE to read and track the source code

By viewing the directory structure of the k230 sdk source code, the sdk itself builds the project through Makefile, and the reference routines in the directory https://gitee.com/kendryte/k230_sdk/tree/main/src/reference/ use CMake to constructed. VSCODEAt this time , it is very convenient to manage and use this sdk project by using Microsoft .
Because the document mentions that the docker container environment is preferred for compilation, it will be a little troublesome when configuring vscode.
The following is my process of configuring the vscode development environment under windows11 :

1. Use WSL2 to install ubuntu

You can refer to my previous article AX620A to run the yolov5s self-training model whole process record (windows) for the operation steps of using WSL2 to install ubuntu, and now you can install the newer 22.04. Note that there is no need to install the Docker-Desktop client in Windows, just install docker under ubuntu.
After installing ubuntu, enter install docker in the terminal of ubuntu

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

2. Pull the k230 sdk warehouse and download the cross-compilation tool

Under ubuntu (root user)

git clone https://github.com/kendryte/k230_sdk
cd k230_sdk
#下载toolchain
source tools/get_download_url.sh && make prepare_sourcecode
  • If there is an error
    insert image description here
    , install itbzip2
apt install bzip2

3. Build docker image

docker build -f tools/docker/Dockerfile -t k230_docker tools/docker

The above process is very smooth, there is no troublesome problem of ladders, and the domestic production is good.

  • Create and enter the container
docker run -u root -it -v $(pwd):$(pwd) -v $(pwd)/toolchain:/opt/toolchain -w $(pwd) k230_docker /bin/bash

This step will configure the toolchain location in the container environment to be in the /opt/toolchain directory

  • At this point, in fact, you can directly enter make in the container to compile the sdk and generate the final burning image. The whole process is a bit long. My cpu is 7840H 16 threads. After compiling, the entire output directory is just 10 G in size.
make CONF=k230_evb_defconfig

4. vscode installs wsl, Dev Containers and docker plugins

  • Open vscode, search for WSL and Dev Containers in the extension to install.
    insert image description hereinsert image description here

  • Enter the wsl environment
    insert image description here

  • After entering the vscode of the wsl environment, install the docker plugin
    insert image description here

5. Start the container in vscode

insert image description here

  • After starting the container, click the right-click menu, click "Add VIsual Studio Code", select the k230 container, and a new vscode window will open. This window has pointed to the container development environment of k230 in docker.
    insert image description here
  • Find the k230_sdk directory in the resource manager and open it.
    insert image description here
    If it is correct, the lower left of vscode will show that it is currently a container development environment.
    insert image description here

6. Configure cmake and cross compile

  • Open the command panel: Ctrl+Shift+P, enter: cmake:q, select GCC9.4.0this compiler first, then manually edit cmake-tools-kits.jsonthis file later, and add the cross compiler used by k230insert image description hereinsert image description here
  • Open the command panel, enter: cmake configure, select a CMakeLists. Here I chose src/reference/ai_poc/CMakeLists.txt to compile the sample program here
  • Then open the command panel, enter: cmake, find 编辑用户本地Cmake工具包. After clicking, cmake-tools-kits.jsonthe configuration file will be opened and a Risv64 option will be added:
[
  {
    
    
    "name": "GCC 9.4.0 x86_64-linux-gnu",
    "compilers": {
    
    
      "C": "/usr/bin/gcc",
      "CXX": "/usr/bin/g++"
    },
    "isTrusted": true
  },
  {
    
    
    "name": "Risv64",
    "toolchainFile": "/home/k230_sdk/src/reference/ai_poc/cmake/Riscv64.cmake"
  }
]
  • Open the command panel, enter: cmake, find 选择工具包, select the newly added Risv64
    insert image description here
  • At this time, if you build directly, you will be prompted that the two paths of riscv64-unknown-linux-musl-gcc and g++ cannot be found. One way is to edit the file in the container and add a .bashrcline at the end of the file
export PATH=$PATH:/opt/toolchain/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/
# 保存文件后再执行
source .bashrc 
  • After closing vscode and reopening, you should be able to find the compiler and configure cmake correctly. Click the button next to the build button at the bottom of vscode [all], and the compilation target options included in CMakeLists.txt will be listed. Here I choose a routine of yolov8 as the compilation target
    insert image description here
  • Finally, click the build button to cross-compile the specified program in vscdoe. Finally, the executable file ob_det.elfis generated in the build directory of the sdk root directory.
    insert image description here

Summarize

Thanks to Canaan's detailed and friendly technical documentation, developers can set up a k230 development environment in a short period of time. Of course, the above is only the first step in developing an application, and there are still many related principles, concepts, and module functions that need to be learned and used. The next step should be to obtain video from the camera on the board, send it to the self-trained yolo model for inference, and output the result to the LCD in real time for display.

Guess you like

Origin blog.csdn.net/flamebox/article/details/131778837