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 (or a Teensy). 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

The standard Mecrisp-Cube features like RTOS, Filesystem, USB, etc.

  • 63 KiB RAM Forth dictionary
  • 128 KiB Flash Forth dictionary
  • 50 KiB for C code
  • Internal Flash drive 0:, 384 KiB (for details see Nucleo)
  • microSD drive 1: (needs external adapter)
  • Digital and analog pins
    • LED1 (blue), PE4
    • Button, PH3
    • Digital port pins: D0 to D15
    • Analog port pins: A0 to A4
    • PWM: TIM1CH3 D0, TIM1CH2 D1, TIM1CH1 A4
    • Input capture TIM2CH2 A1
    • Output compare TIM2CH1 D13, TIM2CH3 A2, TIM2CH4 A3
    • EXTI: D2, D4, D7, D10
  • UART: D0 RX, D1 TX
  • SPI: D13 SCK, D12 MISO, D11 MOSI (e.g. for display, memory)
  • I2C: D14 SDA, D15 SCL (external peripherals e.g. pressure sensor)
  • Optional Neopixel on port D8

For more BSP details see BoardSupportPackageFirefly.

For this sample OCTOPUS OLED display PIS-1277 e.g. from Digikey or Distrelec is used. See also OledDisplay.

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

  • Firefly BLE Development 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 e.g. STLINK-V3MINIE.
  • 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 FS-binary (MecrispCubeFireflyFS.bin, everything included e.g. internal flash drive and Forth utilities) 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 MecrispCubeFireflyFS.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.5.0 for STM32WB Firefly, 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

There are two drives available, drive 0: is the flash drive (384 KiB internal flash, see MicroSdBlocks#Flash_Drive) and drive 1: is the microSD drive (optional MicroSdBlocks#SD_Drive).

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 2 Minutes):

dd 1:/boot/fd-384k.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 FS-binary or 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 Development Environment

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 simpler
$ git stash
$ git 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

Extensions

Arduino UNO Adaptor

It is a one evening project to solder this adaptor. For the pinout see BoardSupportPackageFirefly#Pinout and the JTAG see BoardSupportPackageFirefly#JTAG_SWD.

DIL# Descr Descr' UNO UNO' Pin
1 GND   GND    
2 D0 UART_RX RX GPIO0 CN4.1
3 D1 UART_TX TX GPIO1 CN4.2
4 D2   GPIO2   CN4.3
5 D3   GPIO3   CN4.4
6 D4   GPIO4   CN4.5
7 D5   GPIO5   CN4.6
8 D6   GPIO6   CN4.7
9 D7   GPIO7   CN4.8
10 D8   GPIO8   CN1.1
11 D9   GPIO9   CN1.2
12 D10   GPIO10   CN1.3
13 D11 SPI_MOSI GPIO11 MOSI CN1.4
14 D12 SPI_MISO GPIO12 MISO CN1.5
15 D13 SPI_CLK GPIO13 SCK CN1.6
16 D14 SCL SCL GPIO15 CN1.10
17 D15 SDA SDA GPIO14 CN1.9
18 A0 D16 A0 GPIO16 CN3.1
19 A1 D17 A1 GPIO17 CN3.2
20 A2 D18 A2 GPIO18 CN3.3
21 A3 D19 A3 GPIO19 CN3.4
22 A4 D20 A4 GPIO20 CN3.5
23 SWCLK        
24 SWDIO        
25 nRST   RESET   CN2.3
26 3.3V   3.3V   CN2.4
27 GND   GND   CN2.6
28 VIN   VIN   CN2.8

There is a Teensy Arduino Shield Adapter from Sparkfun, but I2C and analog pins are different. You have to modify it.

Adafruit Feather Adaptor

https://learn.adafruit.com/adafruit-feather/feather-specification. You have to adapt the firmware for using the Feather pinout.

There is a Teensy 3.x Feather Adapter from Adafruit, but I2C and analog pins are different. You have to modify it. You can build your own one from scratch by yourself.

JP1 Left, JP3 Right

DIL# Descr Descr' Feather Feather' Pin SWD ST
1 GND   GND   JP1.13 5, 7, 11
2 D0 UART_RX RX GPIO0 JP1.3 13
3 D1 UART_TX TX GPIO1 JP1.2 14
4 D2   GPIO11   JP3.6  
5 D3   GPIO12   JP3.5  
6 D4   GPIO13 red LED JP3.4  
7 D5   GPIO5 BUTTONC JP3.10  
8 D6   GPIO6 BUTTONB JP3.9  
9 D7   A5   JP1.7  
10 D8   Neopixel      
11 D9   GPIO9 BUTTONA JP3.8  
12 D10   GPIO10   JP3.7  
13 D11 SPI_MOSI MOSI GPIO25 JP1.5  
14 D12 SPI_MISO MISO GPIO24 JP1.4  
15 D13 SPI_CLK SCK GPIO23 JP1.6  
16 D14 SCL SCL GPIO15 JP3.11  
17 D15 SDA SDA GPIO14 JP3.12  
18 A0 D16 A0 GPIO16 JP1.12  
19 A1 D17 A1 GPIO17 JP1.11  
20 A2 D18 A2 GPIO18 JP1.10  
21 A3 D19 A3 GPIO19 JP1.9  
22 A4 D20 A4 GPIO20 JP1.8  
23 SWDCLK         6
24 SWDIO         4
25 nRST   RESET   JP1.16 12
26 3.3V   3.3V   JP1.15 3
27 GND   GND   JP1.13  
28 VIN   USB   JP3.3  

2 or 16 MiB QSPI NOR Flash

The only thing I really miss is a serial Flash (like the one the Katydid has). But it is not a big deal to add one.

-- 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 firefly-adaptor-back.jpg r1 manage 383.7 K 2022-11-23 - 11:19 PeterSchmid  
JPEGjpg firefly-arduino-adaptor-bottom.jpg r1 manage 4532.6 K 2022-10-17 - 19:28 PeterSchmid  
JPEGjpg firefly-arduino-adaptor-top.jpg r1 manage 992.3 K 2022-10-17 - 19:28 PeterSchmid  
JPEGjpg firefly-feather-adaptor-top.jpg r1 manage 282.4 K 2022-11-23 - 11:19 PeterSchmid  
JPEGjpg firefly-feather.jpg r1 manage 433.8 K 2022-11-23 - 11:37 PeterSchmid  
JPEGjpg firefly-header.jpg r1 manage 63.5 K 2022-10-17 - 19:34 PeterSchmid  
JPEGjpg firefly2.jpg r1 manage 662.4 K 2022-08-29 - 19:43 PeterSchmid  
JPEGjpg firefly4-c.jpg r1 manage 1664.2 K 2022-10-17 - 19:28 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: r28 < r27 < r26 < r25 < r24 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r28 - 2022-12-03 - PeterSchmid
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback