在串口通信时,这里有一个点需要注意的问题,串口通信时除了信号线还需要接地线,如下图。配置好串口速率等就可以用串口软件或者树莓派来获取。
![](https://i-blog.csdnimg.cn/blog_migrate/0df0499dd03eec0837b3cd3c19ba1abc.jpeg)
![](https://img-blog.csdnimg.cn/20210319160420860.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BvcDU0MTExMQ==,size_16,color_FFFFFF,t_70)
K210与树莓派pi 3b+串口通讯,通过UART (波特115200,TX 5 RX 4) 传输
- RX <----------> IO05
- TX <----------> IO04
- GND <----------> GND
串口通信脚本
#!/usr/bin/env python #树莓派上的串口实验
import os
import serial
import re
isProcessing = 0
ser = serial.Serial(
# port='/dev/ttyUSB0', #usb接入串口
port='/dev/ttyAMA0', #板载串口
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
while 1:
if isProcessing == 0:
x=ser.readline()
print(x)
开发板上串口程序示例
//头文件与初始化uart
#include "uarths.h"
#define UART_NUM UART_DEVICE_3
uart_init(UART_NUM);
uart_configure(UART_NUM, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
char *hel = {"hello world!\n"};
uart_send_data(UART_NUM, hel, strlen(hel));
k210编译与烧写
[root@ton home]#git clone https://github.com/kendryte/kendryte-standalone-sdk.git #clone kendryte SDK
[root@ton home]#cp -r face_detect/ /home/kendryte-standalone-sdk/src/ #拷贝项目到src目录下
[root@ton home]#cd kendryte-standalone-sdk/src/face_detect/
[root@ton face_detect]#mkdir build && cd build/
[root@ton build]#cmake .. -DPROJ=face_detect #这里会报错
CMake Error: The source directory "/home/kendryte-standalone-sdk/src/face_detect" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
[root@ton build]#cmake ../../../ -DPROJ=face_detect #定位到SDK目录
PROJ = face_detect
-- Check for RISCV toolchain ...
-- Using /opt/kendryte-toolchain/bin RISCV toolchain
-- The C compiler identification is GNU 8.2.0
...
Makefile created.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kendryte-standalone-sdk/src/face_detect/build
[root@ton build]#make #编译
Scanning dependencies of target nncase
[ 2%] Building CXX object lib/nncase/CMakeFiles/nncase.dir/nncase.cpp.obj
[ 4%] Building CXX object lib/nncase/CMakeFiles/nncase.dir/runtime/cpu/cpu_ops.cpp.obj
...
[ 98%] Building C object CMakeFiles/face_detect.dir/src/face_detect/w25qxx.c.obj
[100%] Linking C executable face_detect
Generating .bin file ...
[100%] Built target face_detect
[root@ton build]#
[root@ton build]#ls #make 后生成.bin文件
CMakeCache.txt CMakeFiles cmake_install.cmake face_detect face_detect.bin lib Makefile to
#下面进行烧写
[root@ton k210-face-detect]#zip -d face_detect.kfpkg face_detect.bin #删除kfpkg包里的指定文件
deleting: face_detect.bin
[root@ton k210-face-detect]#zip -m face_detect.kfpkg face_detect.bin #添加.bin文件,或者同样可以添加kmodel文件
adding: face_detect.bin (deflated 41%)
[root@ton k210-face-detect]#python3 kflash.py -b 1500000 face_detect.kfpkg #烧写程序
可以写成脚本来完成上述步骤
github上的例程
https://github.com/tonixtom/k210-yolo3.git
#模形训练时命令记录
toco --graph_def_file=./Freeze_save.pb --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE \
--output_file=./Freeze_save.tflite --inference_type=FLOAT --input_type=FLOAT --input_arrays=Input_image \
--output_arrays=Yolo/Final/conv2d/BiasAdd --input_shapes=1,240,320,3
ncc -i tflite -o k210model --dataset ../../../../k210-face-detection/FDDB/ \
./workspace/Freeze_save.tflite ./workspace/Freeze_save.kmodel