Mecrisp Forth for the STM32WB

Interactive and extensible language. Built-in lexical analysis (tokenizer, parser), needs less than 32 KiB Flash and 4 KiB RAM.

The competitor is MicroPython, but it needs more than 250 KiB of Flash.

But what about uLisp? It is also small and self-contained.


SVD 2 Forth

Install the STM32CubeIDE and get the STM32WBxx_CM4.svd from the folder:

Version 1.6: stm32cubeide_1.1.0/plugins/
Version 1.7: stm32cubeide_1.2.0/plugins/

Install the Mecrisp-Stellaris and copy the STM32WBxx_CM4.svd into common/svd2forth-v3. Edit the Makefile

common/svd2forth-v3> diff Makefile Makefile~
< FOLDED_SVD            = STM32WBxx_CM4.svd
> FOLDED_SVD            = STM32L07x.svd

Edit the shell script Replace gsed with sed.

Generate the Forth and Assembler source files:

common/svd2forth-v3> make everything
common/svd2forth-v3> make mem

STM32WB Nucleo Board


Schematic Nucleo Board MB1355

Schematic Nucleo Dongle MB1293


Linux packages:

  • cross-arm-binutils
  • cross-arm-none-gcc9
  • cross-arm-none-newlib-devel

  • stlink
  • stlink-gui
  • stm32flash
  • openocd

/opt/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI -c port=SWD -ob displ


There is good architecture diagram from STM32MPU Wiki (consider only the Cortex-M4 parts):



OpenOCD 0.10.0 does not support STM32WB, therefore I built the OpenOCD from the sources.

$ git clone openocd-code

But openSUSE' jimtcl Package conflicts with the configure script, to prevent this:

$ mv /usr/bin/jimsh /usr/bin/jimsh-unused

The usual configure/make/install:

$ ./configure
$ make
# make install

The stm32wbx.cfg is derived from st_nucleo_l4.cfg.

$ openocd -f /usr/local/share/openocd/scripts/board/st_nucleo_wb.cfg
Open On-Chip Debugger 0.10.0+dev-01031-gff6d0704 (2020-01-19-11:35)
Licensed under GNU GPL v2
For bug reports, read
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 500 kHz
Info : STLINK V2J34M25 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.221593
Info : stm32wbx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections

Test the server from another terminal:

$ telnet localhost 4444
Trying ::1...
telnet: connect to address ::1: Connection refused
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> shutdown
shutdown command invoked
Connection closed by foreign host.

$ gdb
GNU gdb (GDB; openSUSE Tumbleweed) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
(gdb) file mecrisp-stellaris-stm32wb55.elf
Reading symbols from mecrisp-stellaris-stm32wb55.elf...
(gdb) break Reset
Breakpoint 1 at 0x8003aaa: file mecrisp-stellaris-stm32wb55.s, line 89.
(gdb) break faulthandler
Breakpoint 2 at 0x80038ea: file ../common/interrupts-common.s, line 144.
(gdb) break uart_init
Breakpoint 3 at 0x800146e: file terminal.s, line 31.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x1fff5904 in ?? ()
(gdb) monitor reset
Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
(gdb) load
Loading section .text, size 0x3c18 lma 0x8000000
Start address 0x8000000, load size 15384
Transfer rate: 19 KB/sec, 15384 bytes/write.
(gdb) continue
Note: automatically using hardware breakpoints for read-only addresses.

-- Peter Schmid - 2019-12-29


  • 700px-GDB_openOCD_focus_graph.png:
Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatfs 1b.fs r1 manage 0.7 K 2020-01-12 - 10:21 PeterSchmid  
PNGpng 700px-GDB_openOCD_focus_graph.png r1 manage 103.5 K 2020-01-19 - 16:11 PeterSchmid  
Unknown file formatsvd STM32WBxx_CM4.svd r1 manage 1536.1 K 2019-12-31 - 18:11 PeterSchmid  
Unknown file formats STM32WBxx_CM4.svd.equates.s r1 manage 447.3 K 2020-01-12 - 10:21 PeterSchmid  
Unknown file formatfs bitfields.fs r1 manage 526.9 K 2020-01-12 - 10:21 PeterSchmid  
Unknown file formatfs memmap.fs r1 manage 132.7 K 2020-01-12 - 10:21 PeterSchmid  
Unknown file formatcfg st_nucleo_wb.cfg r1 manage 0.3 K 2020-01-19 - 15:32 PeterSchmid  
JPEGjpg stm32wb-nucleo.jpg r1 manage 85.8 K 2019-12-30 - 16:51 PeterSchmid  
Edit | Attach | Watch | Print version | History: r16 < r15 < r14 < r13 < r12 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r16 - 2020-01-23 - PeterSchmid
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback