README_en.md
1**English** | [中文](README.md)
2# bouffalo_lab bsp
3
4## 1. Introduction
5
6bouffalo_lab bsp is a board support package for bouffalo_lab's series of AIoT chips. It adopts the latest **LHAL** driver library from bouffalo_lab, which is synchronized with the [bouffalo_sdk](https://github.com/bouffalolab/bouffalo_sdk) (formerly known as bl_mcu_sdk) code at commit id: `e6e8da79a50aeb4fcb67ac380c3bd8885cd56faf`.
7
8Currently, the following chips are supported:
9
10| | Chip Model | Kernel |
11| ---- | :----------------------- | ---------------------------------------- |
12| 1 | bl60x(bl602/bl604) | RISC-V SiFive E24 |
13| 2 | bl70x(bl702/bl704/bl706) | RISC-V SiFive E24 |
14| 3 | bl61x(bl616/bl618) | RISC-V T-Head E907 |
15| 4 | bl808 | RISC-V T-Head E902(lp)+E907(m0)+C906(d0) |
16
17**LHAL** is a driver library designed by bouffalo_lab for unified general peripheral interfaces. The code is concise and supports all series of bouffalo_lab chips.
18
19| Peripheral | BL602/BL604 | BL702/BL704/BL706 | BL616/BL618 | BL808 |
20| :------: | :---------: | :---------------: | :---------: | :---: |
21| ADC | ○ | √ | √ | ○ |
22| CAM | - | × | × | × |
23| CKS | ○ | √ | √ | ○ |
24| DAC | ○ | √ | √ | ○ |
25| DMA | ○ | √ | √ | √ |
26| EFUSE | × | √ | √ | √ |
27| EMAC | - | √ | √ | √ |
28| FLASH | √ | √ | √ | √ |
29| GPIO | ○ | √ | √ | √ |
30| I2C | ○ | √ | √ | ○ |
31| I2S | ○ | ○ | √ | ○ |
32| IR | ○ | √ | √ | ○ |
33| MJPEG | × | × | √ | √ |
34| PWM_v1 | ○ | √ | - | - |
35| PWM_v2 | - | - | √ | √ |
36| RTC | ○ | √ | √ | √ |
37| SEC_AES | ○ | √ | √ | √ |
38| SEC_SHA | ○ | √ | √ | √ |
39| SEC_TRNG | ○ | √ | √ | √ |
40| SEC_PKA | ○ | √ | √ | √ |
41| SPI | ○ | √ | √ | √ |
42| TIMER | ○ | √ | √ | √ |
43| UART | √ | √ | √ | √ |
44| USB_v1 | - | √ | - | - |
45| USB_v2 | - | - | √ | √ |
46| WDG | ○ | √ | √ | ○ |
47
48Note: **√** means supported; **×** means unsupported; **○** means supported but not tested; **-** means the peripheral is not available.
49
50
51
52## 2. Environment Setup and Compilation
53
54bl60x/bl70x/bl61x can be directly compiled for the corresponding chips. bl808 is a multi-core heterogeneous architecture, divided into m0, lp, and d0. Each core needs to be compiled separately and burned to the corresponding location. Please refer to [bl808 triple-core user guide](./bl808/README_en.md) for detailed usage.
55
56The following operations are based on the single-core bl61x chip, and the operations for other chips are the same.
57
58### 2.1. Download
59
60Please download the toolchain for the corresponding chip using the download links below.
61
62| Chip Model | Download Link |
63| ----------- | ------------------------------------------------------------ |
64| bl60x/bl70x | [Linux](https://gitee.com/bouffalolab/toolchain_gcc_sifive_linux)/[windows](https://gitee.com/bouffalolab/toolchain_gcc_sifive_windows) |
65| bl61x/bl808 | [T-Head Website](https://occ.t-head.cn/community/download?id=4073475960903634944) or [Linux](https://gitee.com/bouffalolab/linuxtoolchain_gcc_t-head)/[windows](https://gitee.com/bouffalolab/toolchain_gcc_t-head_windows) |
66
67### 2.2. Setup
68
69For Windows, please use the [env tool][1] and extract the cross-compiler with the command `tar -xvf Xuantie-900-gcc-elf-newlib-mingw-V2.6.1-20220906.tar.gz`. Extracting the cross-compiler directly with Windows tools may cause compilation errors on Windows.
70
71Add the path of the RISC-V toolchain to `EXEC_PATH` in `rtconfig.py` or specify the path using the `RTT_EXEC_PATH` environment variable.
72
73Windows:
74
75```
76set RTT_EXEC_PATH=C:\Users\xxxx\Downloads\Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1\bin
77```
78
79Linux:
80
81```
82export RTT_EXEC_PATH=/opt/Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1/bin
83```
84
85### 2.3. Compilation
86
87For Windows, it is recommended to use the [env tool][1]. Open the console and navigate to the bsp/bouffalo_lab/bl61x directory, then run:
88
89 cd bsp/bouffalo_lab/bl61x
90 menuconfig
91 pkgs --update
92
93If you are using Linux, you can execute:
94
95 scons --menuconfig
96
97It will automatically download the env-related scripts to the ~/.env directory, then execute:
98
99 source ~/.env/env.sh
100
101 cd bsp/bouffalo_lab/bl61x
102 pkgs --update
103
104After updating the software packages, use the command `scons -j10` or `scons -j10 --verbose` to compile the board support package. Alternatively, you can use the `scons --exec-path="GCC toolchain path"` command to specify the toolchain path and compile at the same time.
105
106If the compilation is successful, the rtthread.elf and rtthread.bin files will be generated. After the compilation, the script will automatically call `libraries/bl_mcu_sdk/tools/bflb_tools/bflb_fw_post_proc` to package the rtthread.bin for subsequent burning using the `bouffalo_flash_cube` tool.
107
108The script will automatically download `bflb_fw_post_proc` using the curl command line method. If the automatic download fails, you can manually download the corresponding file for your operating system and save it to the `libraries/bl_mcu_sdk/tools/bflb_tools/bflb_fw_post_proc` directory.
109
110| Download Link 1 | [windows](https://raw.githubusercontent.com/bouffalolab/bl_mcu_sdk/master/tools/bflb_tools/bflb_fw_post_proc/bflb_fw_post_proc.exe)/[Linux](https://raw.githubusercontent.com/bouffalolab/bl_mcu_sdk/master/tools/bflb_tools/bflb_fw_post_proc/bflb_fw_post_proc-ubuntu)/[macos](https://raw.githubusercontent.com/bouffalolab/bl_mcu_sdk/master/tools/bflb_tools/bflb_fw_post_proc/bflb_fw_post_proc-macos) |
111| -------------- | ------------------------------------------------------------ |
112| Download Link 2 | [bflb_fw_post_proc-win.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-win.tar.gz)/[bflb_fw_post_proc-linux.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-linux.tar.gz)/[bflb_fw_post_proc-macos.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-macos.tar.gz) |
113| Download Link 3 | [bflb_fw_post_proc-win.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-win.tar.gz)/[bflb_fw_post_proc-linux.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-linux.tar.gz)/[bflb_fw_post_proc-macos.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bflb_fw_post_proc-macos.tar.gz) |
114
115
116
117## 3. Download and Flashing
118
119### 3.1. Download the Flashing Tool
120
121The current bsp must use the `bouffalo_flash_cube-1.0.4` tool for flashing, other tools may not work correctly.
122
123- Download Link 1: [Baidu Pan](https://pan.baidu.com/s/1eG9pkxf3riAqQAu9aXiOjw?pwd=miv1)
124- Download Link 2: [bouffalo_flash_cube-win.zip](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-win.zip)/[bouffalo_flash_cube-win.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-win.tar.gz), [bouffalo_flash_cube-linux.zip](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-linux.zip)/[bouffalo_flash_cube-linux.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-linux.tar.gz), [bouffalo_flash_cube-macos.zip](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-macos.zip)/[bouffalo_flash_cube-macos.tar.gz](https://gitee.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-macos.tar.gz)
125- Download Link 3: [bouffalo_flash_cube-win.zip](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-win.zip)/[bouffalo_flash_cube-win.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-win.tar.gz), [bouffalo_flash_cube-linux.zip](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-linux.zip)/[bouffalo_flash_cube-linux.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-linux.tar.gz), [bouffalo_flash_cube-macos.zip](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-macos.zip)/[bouffalo_flash_cube-macos.tar.gz](https://github.com/flyingcys/bflb_tools/releases/download/v1.0.4/bouffalo_flash_cube-macos.tar.gz)
126
127### 3.2. Flashing via GUI
128
1291. Connect the serial port and select the corresponding port on the tool.
130
1312. Open the flash_prog_cfg.ini file in the corresponding chip folder.
132
1333. Hold down the boot button on the development board, then power on the board to enter flashing mode.
134
1354. Click "Download" to start the flashing process.
136
137
138
139
140
141### 3.2. Flashing via Command Line
142
143You can use the `bouffalo_flash_cube.sh` script in the `bsp/bouffalo_lab` directory to flash the chip via command line. Enter `./bouffalo_flash_cube.sh bl616 /dev/ttyUSB1` and the script will automatically download `bouffalo_flash_cube` using the curl command line method.
144
145If the automatic download fails, you can manually download the corresponding file for your operating system and save it to the `libraries/bl_mcu_sdk/tools/bflb_tools/bouffalo_flash_cube` directory.
146
147- bl616: chip name (bl808: simultaneous flashing of three cores; or enter: bl808-m0/bl808-lp/bl808-d0 to flash the corresponding core individually, but m0 must be flashed for normal operation)
148- /dev/ttyUSB1: download serial port number (in Linux it is /dev/ttyUSBx or /dev/ttyACMx, in Windows it is COMx)
149
150
151
152### 4. Running
153
154If the compilation and flashing are successful, when you reset the device, you will see the RT-Thread startup logo information on the serial port:
155
156
157
158
159
160## 5. Supported Development Boards
161
162| | Board Model |
163| ----- | ---------------------- |
164| bl602 | BL602-IoT-3S/BL-HWC-G1 |
165| bl702 | Maix Zero Sense |
166| bl616/bl618 | M0S Dock/M0P Dock |
167| bl808 | M1s Dock |
168
169
170
171## 6. Driver Support List
172
173| Driver | Support Status | Remarks |
174| :----- | :------------- | :--------------------- |
175| UART | Supported | Default baud rate 2000000 |
176| GPIO | Supported | |
177| I2C | Supported | |
178| SPI | Supported | Supports DMA |
179| PWM | Supported | |
180| ADC | Supported | |
181| RTC | Supported | |
182| WDT | Supported | |
183| HWTIMER | Supported | |
184| FLASH | Supported | |
185| SDCARD | Supported | |
186
187
188
189## 7. Contact Information
190
191Maintainer: [flyingcys](https://github.com/flyingcys)
192
193
194
195## 8. References
196
197* Chip [datasheet][2]
198
199 [1]: https://www.rt-thread.org/download.html#download-rt-thread-env-tool
200 [2]: https://github.com/bouffalolab/bl_docs