Quickstart

If you need help with any of this I can be found on IRC at ##tech40+ (irc.freenode). I’m in Australia, and usually asleep midnight till dawn EST (Australia).

What is Mecrisp-Stellaris ?

  • Released under Version 3 of the GPL, Mecrisp-Stellaris Forth by Matthias Koch is Free Software. See: http://mecrisp.sourceforge.net/
  • Mecrisp-Stellaris Forth runs on M0, M3, M4 and M7 ARM Cortex M chips. This is a big family of microcontrollers with a common processor architecture and very different peripheral capabilities.
  • The Mecrisp-Stellaris Distribution tarball comes with ready to run binaries for all supported chips, you don’t need to compile anything.
  • Despite the name, not only Stellaris chips are supported.
  • Mecrisp-Stellaris Forth fits into 16 kb of flash and runs with at least 1 kb of ram.
  • If you wish Mecrisp-Stellaris Forth ran on your favourite chip, just get in contact with Matthias, and maybe there will be another port soon.

What is Forth ?

If you are familiar with Forth already, then bypass this note and go straight to “Quick Start Here” below.

Note

  • Forth is a program that once flashed into your MCU allows you to immediately write and test programs, read Registers, toggle GPIO pins, read the A-D and much, much more. No compiler is needed as it is built into the program. All you need is a serial terminal to talk to the MCU in Forth.
  • Mecrisp-Stellaris Forth can run on a single $0.60 STM32F051 MCU with zero external components, but you may need a filter capacitor depending on your wiring layout.

Quick Start Here

This describes the basic steps to quickly install flash Mecrisp-Stellaris onto a STM32F “Discovery Board” so you can try it out ASAP. In this example I’ll use a STM32F0 Discovery board, but the general process is the same for other models.
  1. Download the latest Mecrisp-Stellaris tarball: http://mecrisp.sourceforge.net/

  2. Extract the binary for your MCU, in my case it’s: mecrisp-stellaris-stm32f051.bin

  3. Install Stlink
    • FreeBsd and OpenBsd: devel/stlink
    • Linux: You may need to compile it with Linux Debian as they don’t seem to have a stlink.deb. See https://github.com/texane/stlink
  4. Connect your Discovery board to your PC using a usb cable, a led for the board power should light.

Note: Root or sudo will be required for the erase and write steps below

  1. Erase the flash on the board by running
st-flash erase

It’s advised to press the reset button on the board before the next step.

  1. Now flash the board with the Mecrisp-Stellaris binary, remember to use the binary for your MCU
st-flash write mecrisp-stellaris-stm32f051.bin 0x08000000
  1. Connect a 3.3v-USB dongle to your PC and make sure it works in a serial terminal emulator such as “Picocom”, “Minicom”, “Cutecom” etc by connecting the 3.3v TX and RX wires and observing that keys are echoed to the screen when hit. See this table for which pins to use for your board/chip. Connection config is: 115200 baud, 1 stop bit, no parity bit, and no handshaking, no xon/off. Below is a picocom example but your /dev/cuaU0 device will probably be different to mine.
picocom -b 115200 /dev/cuaU0 –imap lfcrlf,crcrlf –omap delbs,crlf
  1. Connect the TX, RX and GND wires from the 3.3v-USB dongle to your Discovery board, which pins are used depends on the board/MCU so check the pin numbers in the “Connecting a Serial Terminal” Section in this documentation.
  2. When all is working, pressing the reset button on your Discovery Board will result in a similar message being sent to your screen.
Mecrisp-Stellaris 2.3.6 with M0 core for STM32F051 by Matthias Koch

FINISHED! at this point you can talk to, and program your MCU in Mecrisp-Stellaris Forth. Have a look in the “Dictionary” Section for all the commands.

However, unless you have hardware handshaking, large Forth program uploads into a slow STM32F MCU may cause it to choke and freeze, in which case try the FE (Forth Explorer) Smart Terminal, made just for Mecrisp-Stellaris, and located in the “Forth Explorer (fe.py)” Section of the documentation. FE will wait for the “ok” from Mecrisp-Stellaris before accepting the next line of code so it never chokes. FE also has easy file upload commands and more.

You should now have a working Forth and no fuss serial terminal.

Lets assume the first thing you want to do is read the values of the GPIOA Registers, ready for some bit twiddling ?

  • After Reset, all GPIO Registers are set to “INPUT” mode, unless changed by Mecrisp-Stellaris or your program. Let’s look at the GPIOA Mode Register “GPIOA_MODER”.
  • From the STM programming documentation we learn that GPIOA_MODER is located at $48000000, so make a forth Word to read this register called “GPIOA_MODER*”
: GPIOA_MODER* $48000000 cr ." GPIOA_MODER = " @ hex. cr ;

GPIOA_MODER*
GPIOA_MODER = 28280000

What about the hundreds or thousands of other Registers inside STM32 MCU’s, ?

Fortunately you can use “Svd2forth-v2” (see the Section in the Doc) to automatically generate a custom set of Forth words specifically for every register in your MCU, along with some custom words for reading the contents of registers. I.E. “gpioa.” which prints the contents of all GPIOA Registers,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