This is the variant of the MiSTeryNano FPGA companion firmware for the BL616 MCU (M0S Dock).
JTAG signals, UART RX and TX are re-purposed as SPI and control interface. MPU is Master and FPGA is slave. UART RX GPIO is board specific and used as an SPI interrupt input. The UART TX GPIO is a board-specific signal used to control the FPGA’s dedicated JTAG hw pins and determine whether the interface operates in native JTAG or SPI mode. Nano 20k always stays in JTAG active enabled mode as both JTAG and SPI are as dedicated hw pins available.
| Tang Board wiring BL616 | BL616 GPIO | SPI re-use | Note |
|---|---|---|---|
| JTAG TMS | GPIO0 | SPI _SS | |
| JTAG TCK | GPIO1 | SPI SCK | |
| JTAG TDO | GPIO2 | SPI MISO | EN_CHIP BL616 |
| JTAG TDI | GPIO3 | SPI MOSI | |
| BL616 UART RX | GPIO x | SPI _IRQ | |
| BL616 UART TX | GPIO x | V_JTAGSELN | 1=JTAG, 0=SPI |
| BL616 TWI SCL1 | GPIO x | UART TX | debug console |
Primer25K re-use after a needed HW modification by removing capacitor C22 the GPIO12 available at button S3 to access debug console. Mega 60k could likely re-use GPIO 16 or GPIO 17 to output debug data.
Download the Bouffalo toolchain:
git clone https://github.com/bouffalolab/toolchain_gcc_t-head_linux.gitand the patched Bouffalo SDK with latest version common CherryUSB Stack:
git clone --recurse-submodules https://github.com/MiSTle-Dev/bouffalo_sdk.gitCompile the firmware for M0S Dock
git clone --recurse-submodules https://github.com/MiSTle-Dev/FPGA-Companion.git
cd FPGA-Companion
git submodule init
git submodule update
CROSS_COMPILE=<where you downloaded the toolchain>/toolchain_gcc_t-head_linux/bin/riscv64-unknown-elf- BL_SDK_BASE=<where you downloaded the sdk>/bouffalo_sdk/ makefor a specific board select in between: m0sdock nano20k console60k mega60k mega138kpro primer25k
BL_SDK_BASE=<where you downloaded the sdk>/bouffalo_sdk/ make TANG_BOARD=console60kYou can simplify the make a bit by setting in your bashrc BL_SDK_BASE and include the toolchain_gcc_t-head_linux in the search path.
nano ./bashrc
export BL_SDK_BASE=xyz
PATH=$PATH:/abc/toolchain_gcc_t-head_linux/binA simple make or make CHIP=bl616 COMX=/dev/ttyACMxyz flash in your bl616 folder will do then.
for onboard BL616 see: Windows 11 Build AiO
The resulting binary can be flashed onto the M0S. If you don't have further debugger or prorgammer hardware connected to the M0S Dock, then you need to perform the following manual steps:
First, you need to unplug the M0S from USB, press the BOOT button and plug the M0S Dock back into the PCs USB with the BOOT button still pressed. Once connected release the BOOT button. The device should now be in bootloader mode and show up with its bootloader on the PC:
$ lsusb
...
Bus 002 Device 009: ID 349b:6160 Bouffalo Bouffalo CDC DEMO
...Also an ACM port should have been created for this device as e.g.
reported in the kernel logs visible with dmesg:
usb 2-1.7.3.3: new high-speed USB device number 9 using ehci-pci
usb 2-1.7.3.3: config 1 interface 0 altsetting 0 endpoint 0x83 has an invalid bInterval 0, changing to 7
usb 2-1.7.3.3: New USB device found, idVendor=349b, idProduct=6160, bcdDevice= 2.00
usb 2-1.7.3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-1.7.3.3: Product: Bouffalo CDC DEMO
usb 2-1.7.3.3: Manufacturer: Bouffalo
cdc_acm 2-1.7.3.3:1.0: ttyACM3: USB ACM device
Once it shows up that way it can be flashed.
If you have built the firmware yourself and have the SDK installed you can simply enter the following command:
BL_SDK_BASE=<where you downloaded the sdk>/bouffalo_sdk/ make CHIP=bl616 COMX=/dev/ttyACM3 flashIf you have downloaded the firmware from the release page you can use the graphical BLFlashCube tool using the fpga_companion_bl616_cfg.ini file.
or alternatively for the .ini file including the companion fw and the fpga-companion:
BLFlashCube-ubuntu --interface=uart --baudrate=2000000 --port=/dev/ttyACMtbd --chipname=bl616 --cpu_id= --config buildall/flash_nano20k.iniAfter successful download you need to unplug the device again and reinsert it without the BOOT button pressed to boot into the newly installed firmware.
Looks that recent SDK build doesn't support Windows properly anymore! Use Linux instead.
Install Git for Windows
Install cmake for Windows
Install Bouffalo RISC-V MCU toolchain
Open Start Search, type “cmd” or Win + R and type “cmd”
cd %HOMEPATH%
git clone https://github.com/bouffalolab/toolchain_gcc_t-head_windows.gitand the patched Bouffalo SDK with latest version common CherryUSB Stack:
cd %HOMEPATH%
git clone --recurse-submodules https://github.com/MiSTle-Dev/bouffalo_sdk.gitSet Windows SDK Environment Variable:
Open Start Search, type “env”, and select “Edit the system environment variables”.
BL_SDK_BASE=C:\Users\xyzuser\bouffalo_sdk
Set Windows search PATH for Toolchain:
C:\Users\xyzuser\toolchain_gcc_t-head_windows\bin
C:\Users\xyzuser\bouffalo_sdk\tools\make
C:\Users\xyzuser\bouffalo_sdk\tools\ninjaClose shell
exitOpen Start Search, type “cmd” or Win + R and type “cmd”
check individually proper start of each single tool
make -v
cmake -version
ninja --help
riscv64-unknown-elf-gcc -vDownload FPGA companion repository
cd %HOMEPATH%/Documents
git clone --recurse-submodules https://github.com/MiSTle-Dev/FPGA-Companion.git
cd FPGA-Companion
git submodule init
git submodule updateCompile the firmware for M0S Dock
cd %HOMEPATH%/Documents\FPGA-Companion\src\bl616
make clean
makefor a specific board select in between: m0sdock nano20k console60k mega60k mega138kpro primer25k
make TANG_BOARD=console60kA build script creates for the several setups specific binaries and .ini files including the needed bl616_fpga_partner_ firmware. The buildall folder will contain all needed files for a release. So far Nano20k, Console60k, Console138k, Primer25k, Mega138k Pro, Mega NEO Dock 60k apart from M0S Dock are supported.
Primer20k and TN9k are excluded as their BL702 doesn't support required USB host mode.
buildall.bat
buildall.shFirst, you need to unplug the M0S_DOCK from USB, press the BOOT button and plug the M0S Dock back into the PCs USB with the BOOT button still pressed. Once connected release the BOOT button. The device should now be in bootloader mode and show up with its bootloader on the PC.
Figure out MPU bootloader COM port and use shell command to program:
Press Windows + R keyboard shortcut to launch the Windows Run box, type “devmgmt.msc” , and click the OK button.
Device Manager will open.
Locate Ports (COM & LPT) in the list.
Check for the COM ports by expanding the same.
make CHIP=bl616 COMX=COMabc flashIf you have downloaded the firmware from the release page you can use the graphical BLFlashCube tool using the fpga_companion_bl616_cfg.ini file.
or alternatively a shell based tool:
cd %HOMEPATH%/Documents\FPGA-Companion\src\bl616
BLFlashCommand.exe --interface=uart --baudrate=2000000 --port=COM_tbd --chipname=bl616 --cpu_id= --config %HOMEPATH%/Documents\FPGA-Companion\src\bl616\buildall\flash_nano20k.iniAfter successful download you need to unplug the device again and reinsert it without the BOOT button pressed to boot into the newly installed firmware.
Footnotes
-
The extra TWI SCL connection is only available for Console60k/138k and Mega138k Pro.
Nano20k uses default BL616 UART TX for the debug console as no V_JTAGSELN needed.
TN20k has a differnt pin mapping and uses GPIO16, GPIO10, GPIO14, GPIO12 for JTAG. ↩
