How Mecrisp-Across Works

No one really knows except Matthias Koch, so I will try and explain my understanding and hopefully Matthias will correct me where I’m wrong.

I’ll keep it simple, because I’m a simple electronics technician, not a real programmer.

Humble Beginnings

I’ll assume you have some programming experience because if (like me) you use embedded MCU’s you have to program them with something.

One day you find a very good MCU family, it’s well designed, outstanding in fact, affordable and available even during the ‘Great Chip Shortage’.

It is a MSP430xxx made by Texas Instruments but the cheaper MCUs don’t have much Flash, typically 512 to 2KB, so it will never host a on-chip-Forth because they need at least 11KB just for the binary Forth image. I bought mine (2KB flash) for $0.40 each, including shipping in September 2021.

MSP430’s with up to 512KB Flash are avaiMSP430FR2000IPW16Rlable to buy right now, but they are considered expensive compared to STM32 … when you could get STM32 !

https://www.arrow.com/en/products/search?q=msp430

You may or may not have Assembly language experience, but in this case, you want something MUCH faster to develop your projects than Assembly.

Debugging

When the MCU doesnt do what you want you think you told it to do, you need to debug it; get inside the MCU and read the values of the various memory mapped registers and so on.

Failure always means nothing happens, leds don’t light, motors don’t switch on etc. What is wrong, how do we find out ?

A Historical Tour

A quick recap of how debugging methods developed over the years.

Assembly Language Programming

  • Write your code, assemble it, fix any errors and then flash to target

  • Test it on the hardware

  • Verify it doesn’t work as it should

  • Read the reference manual for an hour

  • Edit your code again, assemble it, fix any errors and then flash to target again

  • Verify it still doesn’t work as it should

  • Curse

  • Read the reference manual for 10 hours

  • Try everything

  • Accept the fact you still don’t understand what the hell is going on and try harder

  • Moan about not having a Forth to explore a wide range of INTERACTIVE tests on the hardware and solve what may only be a typo in 10 seconds

  • Repeat all the above

  • Eventually fix this problem with mind power alone in much the same way as the early Greek philosopher Democritus hypothesized the existence of atoms

Monitors

These were binary programs that one ran on the Target and allowed some very limited debugging using a serial terminal.

The Buffalo 68HC11 monitor is shown below.

_images/buffalo-monitor.jpg

Simulator

These have been very popular in the past, for simple CPU’s like the Z80, 6502 etc. They’re a program you ran on your pc and it pretended to be the CPU; you could single step, read/write values to memory locations and cpu registers etc.

But it only pretended to be a CPU, they couldnt pretend to be the complex peripherals or connect to the real world. Nothing about it was realtime.

One outstanding example is Jubin Mitra’s 8085 Simulator:

https://learning-microprocessors.sourceforge.io/8085-simulator.html

_images/8085-ide-1.jpg

Development Kit

These were the only real-time solution back in the day, I owned and used one exactly like this Intel SDK8085 Kit. Unlike the Simulator, they could connect to the real world and one could develop products with them … very slowly because they were programmed in machine code, manually. You had to use a calculator to compute jump offsets etc.

They were expensive, had to be assembled, and when programming, a LOT of mistakes would be made.

See the large matrix board area to the left ? that’s where you added your own design for a EPROM programmer, extra RAM, I/O latches etc … and wired it all up. This was the first thing you had to do, because it was useless without these facilities.

_images/sdk-85-pcb.jpg

On Chip Debuggers

_images/gdbbreakpoint.png

About this time, MCU’s with advanced on chip debugging began to appear, one such example was JTAG which used magic inside the chip to read/write everything important in-between mcu clock cycles so even the CPU didn’t know it was there.

This heralded in a new age of debugging, initially with expensive proprietary gear, and later with incredible Free Open Source software like GDB and OCD etc.

Modern development systems use these facilities, and hobbyists have never had a easier time to debug their projects. This is truly the ‘Embedded Golden Age’.

So your new Micro probably has some kind of on-chip-debugger you can use to obtain real-time feedback about what is going on in your chip. This is certainly true for the Texas Instruments MSP430xxx range including the MSP430G2201 used in my examples.

However assembly is SLOW and TEDIOUS (unless you are an Assembly Wizard), so people want a higher level language like Forth, C, Circuit Python etc to speed up the development process etc.

Interactive On Chip HLL’s ————————–MSP430FR2000IPW16R As MCU’s with larger flash began to appear, developers found interactive HLL’s; applications that could not only be loaded onto the chip, they had tons of room left for application programs. Examples include Forth, Basic, Circuit Python and so on.

These applications could do debugging in real time while also developing projects. Typical Flash sizes started at 16KB for the smallest of interactive OS’s and up to half a megabyte for ones such as Circuit Python. They also needed more ram.

The Present

Enter Mecrisp-Across …

So here we are, our shiny new MSP430 chip has only 2KB flash memory, so a on chip HLL is out of the question, only Assembly or C can be used here …. or can it ?

A Wizards Tale

There was once a Great Assembly Wizard and his heart belonged to the MSP430 for it’s orthogonal instruction set and easy soldering DIP packages.

He adored simple and useful, eschewing the over-complex sales-droid crafted MCU’s made-only-to-sell with adverts like “highest speeds and lowest power, cheapest and best, lots of cores, tons of cache and super double diode oscillators”. He saw right through their snake oil products that made shareholders, and evil bosses happy but made embedded programmers sad and angry.

Their ISA’s were so UGLY they looked like a Dragon set their faces on fire, and a Knight put it out with his mace.

Luckily the Great Wizard had a Super Power, he thought in MSP430 Assembly Language and so he devised a clever Spell.

Why not host (his) Mecrisp-Stellaris Forth on a very fast and readily available Cortex-M4 development board using magic to make it pretend to be a MSP430, kind of like that Frog he once made using a Prince ?

Interactive Mode; Project Development

The Host executes the source written in Forth, and can point the Target hardware to do whatever is requested from the real world outside by carefully relaying each and all IO through the JTAG tether while the Target processor is held in eternal reset, not to disturb the stream of thoughts and feelings flowing in and out of its peripheral registers.

In other words, while developing your application in Forth, the Target CPU is held asleep, like a sleepwalker, but the Host controls the sleepwalkers hands and legs like a puppet using JTAG.

Nothing need be resident on the Target, a blank chip will work fine. No bootloader like Arduino, no nothing!

Flashtarget Mode; Project Finished

When the Forth project is finished, the User commands “FLASHTARGET” and the Host compiles everything into a highly optimised Binary Image and flashes it to the Target over the same JTAG. No extra programming boards are needed.

The Target then runs all by itself, without the Tether, doing exactly the same task it did under Forth, except a bit faster.

“To the users, it will look like Magic, but work in the real world for their rapid project developments!” he thought.

“I will name this spell ‘Mecrisp-Across’” the Wizard decided, “and it will run under the power of my Great Spell ‘Mecrisp-Stellaris’” !

Degreth, the Plant Protector

The Wizard later created a dutiful servant to look after the Whomping Willow, Gillyweed and Moonflower which grows in his greenhouse, and he named it “Degreth” because it sounded Norse-like and anyway, all the creature ever did was think about degrees of temperature in a strange Norse idiom known as ‘Celcius’.

Degreth has been working all by himself for many months and watches the plants to make sure they don’t get too hot (and bothered) or too cold and frosty. Trust me, you don’t want a unhappy Venomous Tentacula growing in your greenhouse!

Because Degreth can’t speak, he communicates with the Wizard by blinking one red eye which twinkles Degreths view of the temperature, while the other eye glows blue gently while the sun shines.

In fact the Wizard did consider naming him “Degreth Blue Eye” after a famous Norse King he once knew (who loved blueberries), but then realised his rabbits needed feeding, and so he did that instead.

Degreth also has magic eyebrows, these give him life when the sunlight is upon him, even candlelight will do !

When there is extra light, he stores it in his big nose to use later throughout the cold nights.

Degreth dutifully twinkles a code that tells the Wizard whether his greenhouse plants are happy, day or night as he looks down from his laboratory high in his castle. It’s Degreth’s only job, he loves caring for the Wizards plants and plans to do it for ever and ever.

_images/matthias-greenhouseblinky800x.jpg

The End.