Quick Peek of PineCone BL602 RISC-V Evaluation Board

PineCone BL602 RISC-V Evaluation Board

đź“ť 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.

1 PineCone BL602: Why does it matter?

PineCone is based on the BL602 SoC made by Nanjing-based Bouffalo Lab…

  1. 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!

    (More about BL602 as a drop-in replacement for ESP8266)

  2. 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.

  3. 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.

  4. BL604 is the upsized sibling of BL602: BL604 has 23 GPIOs vs BL602’s 16 GPIOs. Everything else works the same.

1.1 BL602 vs ESP32

How does BL602 compare with ESP32?

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)

1.2 RISC-V vs Arm

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?

2 The Thing About RISC-V and PineCone BL602

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…

  1. Peripherals and Input/Output Ports are implemented differently: Timer, GPIO, UART, I2C, SPI, …

  2. 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.

2.1 BL602 vs Other RISC-V Microcontrollers

Let’s compare BL602 with two popular 32-bit RISC-V microcontrollers…

  1. SiFive FE310 (Released 2017)

  2. GigaDevice GD32 VF103 (Released 2019)

  3. Bouffalo Lab BL602 (Released 2020)

BL602 is new but the OS support gets better every day!

3 Hands On with PineCone BL602

Everything about BL602 (and BL604) is explained here…

To create firmware for BL602, we may use one of the following…

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…

  1. Ai-Thinker Ai-WB2

  2. Pine64 PineCone BL602

  3. Pine64 Pinenut BL602

  4. Pine64 PineDio Stack BL604

  5. DOIT DT-BL10

  6. MagicHome BL602 WiFi LED Controller

  7. Sipeed BL602 EVB

Note that the boards have different jumpers, buttons and LEDs.

3.1 Form Factor

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)

(Watch the demo on YouTube)

Flashing BL602 with Dev Cube

Flashing BL602 with Dev Cube

3.2 Flashing Firmware

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…

  1. Set the PineCone Jumper to the H Position (Like this)

    Connect PineCone to our computer’s USB port

  2. 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

  3. Download the BL602 IoT SDK…

    git clone --recursive https://github.com/bouffalolab/bl_iot_sdk
  4. Launch Dev Cube for Windows, located at bl_iot_sdk/tools/flash_tool/BLDevCube.exe

  5. Select Chip Type BL602/604, click Finish

    We should see Simple Flasher. If not, click View âžś IoT

  6. Set the following…

  7. Click Create & Program

    This flashes the firmware to PineCone. We should see…

    Verify success
    Program Finished

    See the screenshot

  8. Disconnect PineCone from the USB port.

    Set the PineCone Jumper to the L Position (Like this)

    Reconnect PineCone to the USB port.

  9. 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

    See the screenshot

In case of problems, check the instructions in…

3.2.1 Other Flashing Tools

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)

3.3 Building Firmware

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…

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…

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)

3.4 Development Tools

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…

3.5 Debugging Firmware

There’s an entire article about debugging BL602 Firmware with OpenOCD and JTAG…

3.6 Learning RISC-V and BL602

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

4 What’s Next

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

5 Notes

  1. UPDATE: Bouffalo Lab has released a revamped version of the BL602 IoT SDK based on the new “hosal” HAL.

    (See this Twitter Thread)

    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)

  2. Got a question for Bouffalo Lab? Check out their Developer Forum…

    “Bouffalo Lab Developer Forum”

  3. Also check out the Nutcracker Channel on Matrix, Telegram, Discord or IRC…

    “Pine64 Chat Platforms”

  4. 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)

  5. 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)