上一篇介绍了K210的编译环境配置,同时也编译了一个hello_world工程,这篇我们就来介绍一下K210的烧写工具,把我们上次的编译出来的文件烧入板子看一下结果如何。
Windows系统下的Kflash之kflash.py
Kflash.py是一个基于python的烧录工具,所以它更具有通用性(只要有python环境就可以)
我们可以在官方Github上找到这个repo:kendryte/kflash.py
在repo的ReadMe里面其实就可以看到很多信息,包括如何使用与安装等等相关资料。
kflash.py Readme部分内容
Usage
# kflash --help
usage: kflash [-h] [-p PORT] [-f FLASH] [-b BAUDRATE] [-l BOOTLOADER]
[-k KEY] [-v] [-t] [-n] [-s] [-B BOARD] [-S SLOW]
firmware
positional arguments:
firmware firmware bin path
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT COM Port
-f FLASH, --flash FLASH
SPI Flash type, 0 for SPI3, 1 for SPI0
-b BAUDRATE, --baudrate BAUDRATE
UART baudrate for uploading firmware
-l BOOTLOADER, --bootloader BOOTLOADER
bootloader bin path
-k KEY, --key KEY AES key in hex, if you need encrypt your firmware.
-v, --verbose increase output verbosity
-t, --terminal Start a terminal after finish (Python miniterm)
-n, --noansi Do not use ANSI colors, recommended in Windows CMD
-s, --sram Download firmware to SRAM and boot
-B BOARD, --Board BOARD
Select dev board, e.g. kd233, dan, bit, goD, goE or
trainer
-S SLOW, --Slow SLOW Slow download mode
环境版本要求:
python>=3 or python=2.7
pyserial>=3.4
pyelftools>=0.25
那么我们就选择python3吧,毕竟python2年事已高,hah。
python get-pip.py
python -m pip install pyserial
python -m pip install pyelftools
相关环境安装好之后就可以开始安装kflash了。
C:\Users\hulk
$ python -m pip install kflash
Collecting kflash
Downloading https://files.pythonhosted.org/packages/a0/42/c79ed7a9bd176be0632e7b767a48c9e337bbe843bf324aefb16dc13733f1/kflash-0.8.2-py3-none-any.whl (75kB)
|█████████████ | 30kB 109kB/s eta 0:00 |███████████████
██ | 40kB 65kB/s eta 0 |█████████████████████▌ | 51kB 79kB/s
|██████████████████████████ | 61kB 95k |███████████████
███████████████ | 71kB |████████████████████████████████| 8
1kB 93kB/s
Collecting enum34>=1.1.6
Downloading https://files.pythonhosted.org/packages/af/42/cb9355df32c69b553e72a2e28daee25d1611d2c0d9c272aa1d34204205b2/enum34-1.1.6-py3-none-any.whl
Requirement already satisfied: pyserial>=3.4 in c:\users\hulk\appdata\local\programs\python\python37\lib\site-packages (from kflash) (3.4)
Requirement already satisfied: pyelftools>=0.25 in c:\users\hulk\appdata\local\programs\python\python37\lib\site-packages (from kflash) (0.25)
Installing collected packages: enum34, kflash
Successfully installed enum34-1.1.6 kflash-0.8.2
安装完成之后,我们简单的来验证一下:
C:\Users\hulk
$ kflash
usage: kflash [-h] [-p PORT] [-f FLASH] [-b BAUDRATE] [-l BOOTLOADER] [-k KEY]
[-v] [-t] [-n] [-s] [-B BOARD] [-S SLOW]
firmware
kflash: error: the following arguments are required: firmware
那么可以说已经安装完成了,下面就开始研究下它的选项该怎么使用,使用kflash.py来烧录K210了。
怎么操作呢?我是按照下面这个思路来确定的:
- 我只需要烧录firmware.bin(因为目前阶段还没有特殊需求只是烧录固件)
- 我电脑有不止一个串口设备,需要确定端口号
看一下官方的Sample Usage
C:\Users\hulk $ kflash -p COM50 E:\Kendryte210\kendryte-standalone-sdk-0.5.6\build\hello_world.bin [INFO] COM Port Selected Manually: COM50 [INFO] Default baudrate is 115200 , later it may be changed to the value you set. [INFO] Trying to Enter the ISP Mode... ._ [INFO] Automatically detected goE/kd233 [INFO] Greeting Message Detected, Start Downloading ISP Downloading ISP: |============================================================================| 100.0% 10kiB/s [INFO] Booting From 0x80000000 [INFO] Wait For 0.1 second for ISP to Boot [INFO] Boot to Flashmode Successfully [INFO] Selected Flash: On-Board [INFO] Initialization flash Successfully Programming BIN: |============================================================================| 100.0% 10kiB/s [INFO] Rebooting...
成功!NICE!
Ubuntu系统下的Kflash(kflash.py)
环境介绍:
Ubuntu 18.04LTS
python 3.6.8
安装pip:
sudo apt update
sudo apt install python3-pip
安装pyserial和pyelftools:
pip3 install pyserial
pip3 install pyelftools
安装kflash:
pip3 install kflash
查看下是否成功安装:
kflash -h
返回结果:
kflash -h
usage: kflash [-h] [-p PORT] [-f FLASH] [-b BAUDRATE] [-l BOOTLOADER] [-k KEY]
[-v] [-t] [-n] [-s] [-B BOARD] [-S SLOW]
firmware
positional arguments:
firmware firmware bin path
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT COM Port
-f FLASH, --flash FLASH
SPI Flash type, 0 for SPI3, 1 for SPI0
-b BAUDRATE, --baudrate BAUDRATE
UART baudrate for uploading firmware
-l BOOTLOADER, --bootloader BOOTLOADER
bootloader bin path
-k KEY, --key KEY AES key in hex, if you need encrypt your firmware.
-v, --verbose increase output verbosity
-t, --terminal Start a terminal after finish (Python miniterm)
-n, --noansi Do not use ANSI colors, recommended in Windows CMD
-s, --sram Download firmware to SRAM and boot
-B BOARD, --Board BOARD
Select dev board, e.g. kd233, dan, bit, goD, goE or
trainer
-S SLOW, --Slow SLOW Slow download mode
测试烧录:
kflash -p /dev/ttyUSB0 /home/hulk/kendryte210/kendryte-standalone-sdk-0.5.6/build/hello_world.bin
如果这一步报错的话,那可能是串口权限的问题,执行下面的语句:
sudo usermod -a -G dialout $(whoami)
到此烧录的方法基本介绍结束了。