F103 + USB = Swiss Army Knife May 2017
The original code and inspiration for this driver came from Eckhart Köppen’s early CoreForth implementation. While changes and a whole lot of head-scratching was needed, his code was proof that implementing a serial port driver in Forth was worth trying, and ulitmately: doable!
Having a Forth implementation interacting via serial USB is a big deal, because of the large variety of very low-cost F103-based boards on eBay. With Forth installed, and some utility code such as from the Embello project, you end up with a plug-and-play jack-of-all-trades gadget:
- a 32-bit ARM chip running at 72 MHz
- an interactive command prompt, ready to tinker
- lots of drivers pre-loaded
- a collaborative multi-tasker and easy to use software timers
- plenty of free flash and RAM to implement fun stuff
- a snappy serial console, noticeably faster than a 115,200 baud link
- no toolchain: just plug it in and use Folie or some other terminal emulator
The no toolchain aspect is quite important, as it means that you can take such a board with you, and use it to start trying out physical-computing related stuff wherever you are:
- connecting over USART, I2C, or SPI with “other devices”
- reading analog data at up to 1 Msps and 12-bit resolution
- generating square waves or pulses, or multi-bit patterns
… as well as all the obvious tasks of reading out button states, encoders, driving LEDs, connecting relay-, motor-, or stepper-drivers and … making real things “happen”.
When you need more I/O pins and more interfaces than the TQFP-48 package on the low-end F103 boards provide: there are also 100-pin and 144-pin packages, with considerably more I/O, more h/w interfaces, and more features (like DACs) - search for “STM32F103 board” on eBay.
To use a Blue Pill and others for all sorts of quick / ad-hoc projects requires:
- A simple way to upload Mecrisp and additional Forth code onto each new board
- Access to easy-to-use documentation for the (over 750!) pre-loaded “words”
For details on how to upload a complete USB-enabled image to one of several common F103 boards with Folie, see this README on GitHub. There is a nasty chicken-and-egg problem involved in creating a suitable BUB- or SerPlus-like interface, but once you have such a thing, turning an F103-based µC board into this Swiss Army Knife will be a piece of cake.
The main words in the Mecrisp core are (tersely) documented on the official glossary page.
If you would like to help improve on this, by improving the documentation, or by contributing general-purpose code, or drivers for some USART/I2C/SPI device, please consider submitting a pull request, which is GitHub’s powerful way of collaborating on open source projects. With a pull request, your contribution will not only show up among all the others, Git also archives the complete logs of who contributed what and when, i.e. giving full attribution to everyone.
As well as an honourable mention, as a small-but-sincere token of appreciation.