đź“ť 13 Jan 2022
Let’s learn about the BL602 SoC and Pine64’s PineCone BL602 Board… And how we can contribute to the RISC-V Open Source Ecosystem.
PineCone is based on the BL602 SoC made by Nanjing-based Bouffalo Lab…
Low Cost: BL602 is a General Purpose 32-bit Microcontroller. (Think STM32 Blue Pill, Nordic nRF52)
But BL602 supports Bluetooth LE AND 2.4 GHz WiFi… At the low low price of an ESP8266.
That’s a game changer!
Power Efficient: BL602 is perfect for wearables and other power-constrained devices. (Maybe even PineTime!)
By performance, BL602 belongs to the same class of microcontrollers as Nordic nRF52832. BL602 won’t run Linux, but it runs Apache NuttX OS, which works like a tiny Linux.
CPU is based on RISC-V, not Arm: Yep this scares most people, because BL602 will NOT run code compiled for Arm processors. Instead we need to use the 32-bit RISC-V version of the GCC compiler to compile our programs.
BL604 is the upsized sibling of BL602: BL604 has 23 GPIOs vs BL602’s 16 GPIOs. Everything else works the same.
How does BL602 compare with ESP32?
BL602 is a General Purpose Microcontroller (based on RISC-V) that supports Bluetooth LE and WiFi
ESP32 is more of a Bluetooth LE + WiFi Controller (based on Xtensa) that supports Embedded Programs
To folks who are familiar with Arm microcontrollers (STM32 Blue Pill, Nordic nRF52), BL602 looks like another microcontroller… Except that it runs on the RISC-V Instruction Set instead of Arm.
(There’s a new ESP32 based on RISC-V. Compare BL602 with ESP32-C3)
Why not stick with Arm? Why get adventurous with RISC-V?
Nintendo Switch (the #1 gaming console) runs on Arm. iPhone and the new M1 Macs also run on Arm. Most of our gadgets are powered by Arm today.
Before Arm gets too successful and locks us in… Shouldn’t we explore alternatives like RISC-V?
32-bit RISC-V microcontrollers all run on the same core instruction set…
So the same firmware should run on different RISC-V microcontrollers… Right?
Nope! Because across different brands of RISC-V microcontrollers…
Peripherals and Input/Output Ports are implemented differently: Timer, GPIO, UART, I2C, SPI, …
Exceptions and Interrupts also work differently on various RISC-V microcontrollers.
(Arm microcontrollers all handle Exceptions and Interrupts the same way)
Hence the operating systems supported on each RISC-V Microcontroller will vary.
Let’s compare BL602 with two popular 32-bit RISC-V microcontrollers…
SiFive FE310 (Released 2017)
GigaDevice GD32 VF103 (Released 2019)
Bouffalo Lab BL602 (Released 2020)
BL602 is new but the OS support gets better every day!
Everything about BL602 (and BL604) is explained here…
To create firmware for BL602, we may use one of the following…
(Supports WiFi and is POSIX Compliant, works like a tiny Linux)
BL602 IoT Software Development Kit
(Supports WiFi and is based on FreeRTOS)
BL602 MCU Software Development Kit
(Doesn’t support WiFi, also based on FreeRTOS)
The BL602 docs are located in the BL602 Docs Repo…
BL602’s RISC-V Core seems to be based on either SiFive E21 or SiFive E24 (to be confirmed, though the SDK source code suggests E21 here and here)…
More docs and tools for BL602 may be found here…
Which dev boards are supported?
Firmware built with NuttX, BL602 IoT SDK and BL602 MCU SDK will work fine on…
Note that the boards have different jumpers, buttons and LEDs.
The PineCone BL602 Evaluation Board has a similar form factor to other wireless dev boards, like EBYTE E73-TBB (which is based on nRF52832)
The PineCone board comes with a USB-C Connector. When connected to our computer via USB, the BL602 board is recognised as a Serial Device, ready to be flashed.
(PineCone’s USB Vendor ID is 0x1A86
, Product ID is 0x7523
)
Flashing BL602 with Dev Cube
To flash Apache NuttX Firmware to BL602, see this…
For BL602 IoT SDK: We flash firmware to the BL602 board through the USB Serial Connection using the Dev Cube Tool…
Set the PineCone Jumper to the H
Position (Like this)
Connect PineCone to our computer’s USB port
Download the PineCone Sample Firmware images from GitHub Actions. See the next section “Building Firmware”
Unzip the files in customer_app.zip
Or download this Hello World sample firmware: sdk_app_helloworld.bin
Download the BL602 IoT SDK…
git clone --recursive https://github.com/bouffalolab/bl_iot_sdk
Launch Dev Cube for Windows, located at bl_iot_sdk/tools/flash_tool/BLDevCube.exe
Select Chip Type BL602/604
, click Finish
We should see Simple Flasher
. If not, click View âžś IoT
Set the following…
Interface: UART
COM Port: Select the Serial COM port for PineCone
UART Rate: 2000000
(default)
Board: IoTKitA
(default)
Xtal: 40M
(default)
Chip Erase: False
âś… Factory Params
âś… Partition Table: Click Browse
and select from the PineCone SDK…
bl_iot_sdk/tools/flash_tool/bl602/partition/partition_cfg_2M.toml
âś… Boot2 Bin: Click Browse
and select from the PineCone SDK…
bl_iot_sdk/image_conf/bl602/blsp_boot2_release.bin
âś… Firmware Bin: Click Browse
and select from the PineCone Sample Firmware sdk_app_helloworld.bin
…
customer_app.zip/sdk_app_helloworld/build_out/sdk_app_helloworld.bin
This is the “Hello World” sample firmware that we’ll be flashing.
The three files selected should NOT have any spaces in their pathnames.
Click Create & Program
This flashes the firmware to PineCone. We should see…
Verify success
Program Finished
Disconnect PineCone from the USB port.
Set the PineCone Jumper to the L
Position (Like this)
Reconnect PineCone to the USB port.
Click Open UART
Press the RST
button on PineCone (Look here)
Our firmware starts to run. We should see…
[helloworld] start
[helloworld] helloworld
[helloworld] end
In case of problems, check the instructions in…
Are there command-line tools for flashing firmware to PineCone on Linux, macOS and Windows?
Check out the article…
Is JTAG supported for flashing firmware to the PineCone Board?
JTAG works for loading firmware into PineCone’s Cache Memory (similar to RAM). But not to PineCone’s Internal Flash ROM (XIP Flash).
So we must flash firmware to PineCone over UART.
More about JTAG, OpenOCD and GDB in the BL602 official docs…
Are SWD and ST-Link supported for flashing firmware to the PineCone board?
Sorry no. SWD is available only on Arm Microcontrollers. (SWD was created by Arm)
The UART flashing protocol for PineCone is described in the BL602 Flash Programming doc.
(The BL602 Flash Programming doc seems to suggest that BL602 may also be flashed from an SD Card via Secure Digital Input/Output)
To build Apache NuttX Firmware for BL602, see this…
For BL602 IoT SDK: We may use Linux, Windows or macOS to build the BL602 firmware…
Download the BL602 IoT SDK…
git clone --recursive https://github.com/pine64/bl_iot_sdk
cd bl_iot_sdk
Follow the build instructions for Linux, Windows and macOS like so…
## TODO: Change this to the full path of bl_iot_sdk
export BL60X_SDK_PATH=~/bl_iot_sdk
export CONFIG_CHIP_NAME=BL602
make
See also the Linux Starter Guide and the Windows Starter Guide
On Windows, MSYS2 is required. Alternatively, we may use Windows Subsystem for Linux (WSL). (Some USB Devices don’t work under WSL… Beware!)
UPDATE: Bouffalo Lab has released a new version of the BL602 IoT SDK
Can we download the firmware without building it ourselves?
For BL602 IoT SDK the firmware is built automatically in the cloud by GitHub Actions…
Download the built firmware from GitHub Actions:
github.com/lupyuen/bl_iot_sdk/actions
(Requires login to GitHub)
Under All Workflows âžś Results
, click the first row
Under Artifacts
, click customer_app.zip
(Like this)
The built firmware images in the downloaded ZIP have the extension *.bin
See the Modified GitHub Actions Workflow that builds the firmware
If we have trouble building the firmware on our own, just download the built firmware images from above.
The downloaded firmware images *.bin
may be flashed to BL602 with the BLFlashEnv Tool on Linux and Windows. (No need for MSYS2)
VSCode works fine for creating BL602 firmware with Apache NuttX OS, BL602 IoT SDK and BL602 MCU SDK.
For BL602 IoT SDK: The official development tools are…
(Because BL602 is based on SiFive’s E21 or E24 RISC-V Core)
There’s an entire article about debugging BL602 Firmware with OpenOCD and JTAG…
How shall we learn about writing RISC-V firmware for BL602?
For Apache NuttX OS: Check out this article…
For BL602 IoT SDK: Check out the “Hello World” sample firmware…
Start by reading the C source file: main.c
Then browse the other firmware samples in the BL602 IoT SDK…
Some of the firmware samples are documented here
We’re in the middle of a pandemic. Why not take the time to learn some RISC-V… And contribute to the RISC-V Open Source Ecosystem!
Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…
lupyuen.github.io/src/pinecone.md
UPDATE: Bouffalo Lab has released a revamped version of the BL602 IoT SDK based on the new “hosal” HAL.
We have no plans to merge with the new HAL, because it will impact all the articles and code on BL602 IoT SDK that we have written for “The RISC-V BL602 / BL604 Book”.
All new articles will be based on Apache NuttX OS, which is not affected by the change.
(NuttX uses its own community-supported HAL for BL602)
Got a question for Bouffalo Lab? Check out their Developer Forum…
Also check out the Nutcracker Channel on Matrix, Telegram, Discord or IRC…
I’m not a Pine64 employee and I’m not paid by Pine64 to write these articles on BL602.
Pine64 sponsors my coffee (as a GitHub Sponsor) and they send me samples (of gadgets, not coffee) for evaluation and experimentation.
(I’m not connected to Bouffalo Lab either)
Can we flash firmware to PineCone via a Web Browser through the Web Serial API? That would be really interesting.
The Web Serial API works OK for sending commands to the BL602 Command Line Interface. (See this)