Mecrisp-Cube for the Firefly BLE Development Board
Intro
Unfortunately the STM32WB Feather Development Board is no longer available. But there is a very good substitute the Firefly designed by Tlera Corp. The pinout is very similar to Arduino UNO but with the size of an Arduino Nano. The GPIOs are very carefully selected. JTAG SWD is on the pin header too!

Instant real-time programming with Forth.

Sources on GitHub (Firefly branch on Mecrisp-Cube)

Features

  • 61 KiB RAM dictionary
  • 128 KiB Flash dictionary
  • Forth as CMSIS-RTOS thread. CMSIS-RTOS API to use FreeRTOS within Forth.
  • Buffered terminal I/O (5 KiB buffer for UART Rx). Interrupt driven and RTOS aware, key and emit block the calling thread. USART1: D0 RX, D1 TX
  • USB-CDC for serial communication via USB. Redirect console I/O like cdc-emit, cdc-key
  • microSD and internal serial Flash mass storage for blocks and FAT filesystem.
  • Digital and analog pins
    • LEDs: LED1 (blue), Neopixel (D8, optional)
    • Digital port pins: D0 to D15 (some ports are shared)
    • Analog port pins: A0 to A4 (can also be used as digital port pins D16 to D20)
    • PWM: D0 (TIM1CH3), D1 (TIM1CH2), A4 (TIM1CH1)
    • Input capture A1 (TIM2CH2)
    • Output compare D13=13 (TIM2CH1), A2=18 (TIM2CH3), A3=19 (TIM1CH4)
    • EXTI: D2, D4, D7, and D10
  • UART: D0 RX, D1 TX
  • SPI: D11 SCK, D12 MISO, D13 MOSI (e.g. for display, memory, CS for SD-Card is D10)
  • I2C: D14 SDA, D15 SCL (external peripherals e.g. pressure sensor, OLED)
  • vi Editor origin in BusyBox tiny vi. Workflow development: begin Edit EVALUATE while SaveFile repeat
  • Real Time Clock (32 bit UNIX time stamp, valid times are from 1.1.2000 to 31.12.2099 because of the STM32WB RTC peripheral) time!, time@, and .time (YYYY-MM-DDTHH:MM:SS ISO 8601).

For more BSP details see BoardSupportPackageFirefly.

Getting Started

These instructions will get you a copy of the project up and running on your local machine (STM32WB Firefly Developer Board) for development and testing purposes.

Prerequisites

  • STM32WB Feather Development Board Stackable Feather board with STM32WB55 MCU (Cortex ARM M4) runs at a 32 MHz (the Bluetooth stack runs on a Cortex ARM M0+ core). If you want to debug C and assembler programs you need an ST-Link debugger/programmer.
  • Terminal emulator application for PC, e.g.:
    • PuTTY - Windows and Linux
    • Tera Term - Windows
    • Realterm - Windows
    • minicom, microcom, screen - Linux
    • Use the built in Eclipse console (but no LF)

Flash the Mecrisp-Cube binary (MecrispCubeFirefly.bin) or the util-binary (MecrispCubeUtil.bin, everything included e.g. internal flash drive and Forth tools) to the Firefly Board.

  1. Connect the Firefly Board USB to the PC
  2. Hold the BTN button (BOOTP Pin), push the nRST button, release the nRST button
  3. Program the binary (MecrispCubeFirefly.bin or MecrispCubeUtil.bin) with the STMCubeProgrammer (select USB Device)
  4. Reset or power cycle the Firefly board

Start the terminal emulator application on the PC. Check for the serial communication port (e.g. for Linux /dev/ttyACM0). I set the putty terminal configuration to

  • Implicit CR in every LF
  • Local echo: Auto
  • Local line editing: Auto
  • Keyboard Backspace: Control-H
  • Keyboard Function: Keys VT100
  • Remote character set: CP850

Mecrisp-Stellaris RA 2.5.4 by Matthias Koch.

Mecrisp-Cube 1.4.5 for STM32WB Nucleo, 63/128  KiB RAM/FLASH dictionary (C) 2022 peter@spyr.ch
  * Firmware Package STM32Cube FW_WB V1.14.1, USB-CDC, BLE Stack 5.3 (C) 2022 STMicroelectronics
  * CMSIS-RTOS V2 FreeRTOS wrapper, FreeRTOS Kernel V10.3.1 (C) 2020 Amazon.com
  * FatFs for internal flash and microSD - Generic FAT fs module  R0.12c (C) 2017 ChaN
  * tiny vi - part of BusyBox (C) 2000, 2001 Sterling Huxley

include 0:/etc/rc.local
23 5 / .[CR] 4  ok.
: hello ." World" ;[CR]  ok.
hello[CR] World ok.

Special Functions on Startup

USB-CDC is the default console.
Button BTN
start STM bootloader
blue LED
the LED lights up during the initialization phase

Neopixel as Status Indicator

The optional NeoPixel displays the status
dimmed Green
USB enumeration successfull
dimmed Blue
BLE connected
flashing Red
"disk" (serial flash or SD) write operation
flashing Yellow
"disk" (serial flash or SD) read operation

Additional Tools and Local Filesystem

Populate a microSD with the contents of sdcard. Put the microSD into the uSD Card slot and reset or power cycle the board.

The directory should look like this:

ls -l 1:[CR]
drw-         0 2021-04-18T18:12:38 boot
drw-         0 2021-03-21T18:47:52 etc
drw-         0 2021-03-21T18:47:54 fsr
drw-         0 2021-03-21T18:47:54 home
drw-         0 2021-03-21T18:47:56 man
-rwa      7219 2021-01-08T19:42:36 README.md
ok.

You can use the local CLI commands like mkfs, mkdir and cp to create a filesystem on the serial flash and fill it with files and folders. But this is tedious job because I haven't yet implemented a recursive copy for MecrispCube. But there is prepared disk image (for details see MicroSdBlocks#Serial_Flash) on microSD and the tool dd. You can copy the disk image to the drive 0: (this takes about 8 Minutes):

dd 1:/boot/fd-16MiB.img 0:[CR]
 ok.
mount 0:[CR]
 ok.
ls 0:[CR]
man                     fsr                     README.md               boot
etc                     home
 ok.

The Mecrisp have some tools bundled in its distribution e.g. assembler, disassembler, dump, float. I put those tools and some more into the folder /fsr. With the "init.fs script" I compile my favorite ones into the flash directory (if you use the util-binary binary, these tools are already compiled in):

compiletoflash[CR]  ok.
include /etc/init.fs[CR]
init.fs Loading started
RAM Dictionary: 392991 KiB
utils.fs loading ...
conditional.fs loading ...
dump.fs loading ...
disassembler-m3.fs loading ...
float.fs loading ...
threads.fs loading ...
RAM Dictionary: 392981 KiB
init.fs finished  ok.

For example, the word disassember is available now:

see dump[CR]
080405F0: B500  push { lr }
080405F2: F7C2  bl  08002A3E  --> cr
080405F4: FA24
080405F6: CF08  ldmia r7 { r3 }
080405F8: F013  ands r2 r3 #F
080405FA: 020F
080405FC: F847  str r3 [ r7 #-4 ]!
080405FE: 3D04
08040600: 2A00  cmp r2 #0
08040602: D000  beq 08040606
08040604: 3610  adds r6 #10
08040606: CF08  ldmia r7 { r3 }
08040608: F847  str r6 [ r7 #-4 ]!

Installing

A step by step series of examples that tell you how to get a development env running

Install the IDE STM32CubeIDE, it is Eclipse and GCC based. STM32CubeMX is included in the IDE, you need a stand alone installation only if you do not want to use the STM32CubeIDE.

Get the sources from github:

psi@homer:~> git clone --branch firefly https://github.com/spyren/Mecrisp-Cube
Klone nach 'Mecrisp-Cube' ...
remote: Enumerating objects: 1157, done.
remote: Counting objects: 100% (1157/1157), done.
remote: Compressing objects: 100% (620/620), done.
remote: Total 3183 (delta 720), reused 934 (delta 525), pack-reused 2026
Empfange Objekte: 100% (3183/3183), 41.60 MiB | 6.96 MiB/s, Fertig.
Löse Unterschiede auf: 100% (2100/2100), Fertig.

Import the project into the IDE:

File -> Import -> General -> Existing Projects into Workspace -> Select root directory
Copy project into workspace
Browse to Mecrisp-Cube directory

Generate code from the STM32CubeMX MecrispCubeFirefly.ioc file:

Project -> Generate Code 

Restore changed source files

$ git status
{list of changed files}
$ git restore {files to restore} 
or instead of git restore
$ git stash
$ git stash drop

Select the Build Configuration (Debug if you want to debug the project) and Build the project:

Project -> Build Configurations -> Set Active -> Debug/Release 
Project -> Build Project

-- Peter Schmid - 2021-07-01

Creative Commons License
This work by Peter Schmid is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Topic attachments
I Attachment History Action Size Date Who Comment
JPEGjpg firefly2.jpg r1 manage 662.4 K 2022-08-29 - 19:43 PeterSchmid  
JPEGjpg header.jpg r1 manage 51.7 K 2022-08-29 - 19:52 PeterSchmid  
JPEGjpg wbfeather.jpg r1 manage 697.5 K 2021-07-01 - 20:38 PeterSchmid  
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2022-08-30 - PeterSchmid
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback