Mecrisp-Across Version 0.9a

Released January 2020, this is Matthias’s Christmas present to those of us who love Mecrisp-Stellaris and the MSP430.

~~~~~ Mecrisp-Across is now ported to run on the STM32F4 Discovery board !!! ~~~~~

Quick Mecrisp-Across Recap

  • It’s like a interactive Gcc with Gdb.

  • The peripherals are pre-defined, no need for memory maps, SVD’s, include or header files. They are ready to code for right away.

  • It generates a highly optomised bootable binary image for the target, including vector configs

  • There is no Forth kernel pre-install or bootloader necessary in the target hardware, it runs on a totally blank mcu.

  • The HOST compiler is GPL3 licensed, your target binary image license is gpl unencumbered. License it how you wish.

  • Mecrisp-Across is possibly one of the strongest optimizing Forth cross compilers you have ever seen. Out of the box, it does:
    • Constant folding

    • Register allocation for both data and return stack

    • Dead code elimination (imagine a constant feed into case)

    • Register allocation across control structures

    • Determination which definitions are in use,

    • Automatic inlining of definitions used one time only

    • Interrupt handler framing depending on register usage

I’m confused, can you explain how Mecrisp-Across works again ?

Quick MSP430 Notes

If you haven’t used the MSP430 family before, this is NOT some obsolete 16 bit MCU, in fact it’s quite unique and has stood the test of time!

Why ?

Texas Instruments have some of the very best digital and analog engineers in the world. They designed and manufactured leading edge electronics components that were used in the Apollo spacecraft that landed on the Moon in 1969. Ti are the absolute masters of power control and measurement devices with many patents.

MSP430 characteristics include:

  • Probably the lowest of low power usage in MCU’s available today

  • Low supply voltage range, 0.9 to 3.6v

  • Five power saving modes

  • 16 bit RISC architecture

  • 16 bit Sigma-Delta A/D converter

  • Spy-by Wire and JTAG interface

  • Self contained including clocks

  • Hundreds of models with a huge variety of tightly integrated peripherals, making low power usage often just one command

  • ISA that’s a pleasure to code for, completely orthogonal like the obsolete Motorola 6800 series was.

  • Matthias wrote a MSP430 bootable ‘Blinky’ that assembles to only 14 Bytes! This is impossible on any Cortex-M device as our best efforts are double that at 28 Bytes.

Terms

Term

Description

HOST

STM32F4 Discovery Board or equivalent with STM32F407 MCU. It runs Mecrisp-Across V-0.9

TARGET

MSP430xxxx 16 bit, highly integrated, lowest power MCU. Beautiful ISA. 300 models available right now on arrow.com

Advantages of Mecrisp-Across V0.9a ?

  • Runs on the STM32F407 MCU as used in the F4 Discovery Board by STI

  • The STM32F407 MCU handles everything from target JTAG control, to target flashing. No special target flashing board is required

  • Runs at the Host full speed of 168 MHz (faster target emulation)

  • Only 4 wires, including power connect to the MSP430 Target

  • Uses USB for the HOST Forth terminal. It’s the fastest terminal possible.

  • Has built in USB handshaking which means no end of line delays. Forth project files upload almost instantly.

Note

The binary image for the demo blinky is 36 Bytes total, thats ALL !

STM32F407 Discovery Board

The STM32F4 Discovery board (STM32F407) must be flashed with the following binary from the new release.

mecrisp-stellaris-stm32f407-with-mecrisp-across.bin

This is available for download at:

https://sourceforge.net/projects/mecrisp/files/mecrisp-across-0.9-experimental.tar.gz

Warning

Don’t get the “Nucleo Board” as it has a different MCU !

Warning

Check if your F4 Discovery Board has a FAULTY MCU

Availability in 2022 ?

As of 4Jan2022, I can’t see any STM32F407 Discovery Boards for sale at reputable suppliers such as arrow.com.

Chinese STM43F4 Discovery Board Clone

Genuine board on the left, Chinese board on the right. Spot the differences ?

  • Separate color leds

  • No board revision i.e. “MB997C” printed on board

  • No STMicro URL printed on board

  • Both push buttons identical black color

  • Pin Headers are unassembled

  • No STI Logo/trademark

  • Different chip between push buttons

Note

I’m not saying the Chinese board is “no good”, it may even be better then the genuine unit, I just have no information on it as yet.

_images/stm32f4-discovery-board.jpg _images/f4-disc0-chinese.jpg

Be aware that Gigadevices make a licensed second source STM32F407 named GD32F407 which I assume will work fine.

https://www.aliexpress.com/item/32658819798.html?spm=a2g0o.search0304.0.0.7c8ec711INQ2e9&algo_pvid=f5aaa440-b38e-45dd-8b54-75449c976f9a&algo_exp_id=f5aaa440-b38e-45dd-8b54-75449c976f9a-1

STM32F4 Disco Alternatives

  • Chinese STM32F4 Disco Boards

  • Any STM32F407 board used with a with a external SWD/STlink dongle if the board doesn’t have one.

Target

MSP430G2201 Used In This Project

The bottom of the Texas Instruments MSP430xxx range, the MSP430G2201 is a perfect MCU for simple projects, no extra unnecessary hardware and you can learn the entire chip inside and out within a day.

Want the lowest power use? Not having to write extra code to disable unwanted peripherals is great.

At the middle of the ‘Great MCU Shortage’, 6Sep2021 I paid $0.40 AUD each (including shipping) for 150 off MSP430G2201RSA16R. They are a 16 pin VQFN package with 2KB flash and a single timer. It works perfectly with Mecrisp-Across.

I should have purchased more of them as they’re now $1.3933 AUD (3Jan2022), an increase of 350%. At least Arrow.com have 500 parts in stock right now. If you think this is terrible and will wait for the prices to go back down, good luck, it may be years away. The STM32F051 chips I paid $0.56 USD for in 2014 are $12.60 USD each right now, IF you can find any.

https://www.arrow.com/en/products/msp430g2201irsa16r/texas-instruments

Warning

the MSP430G2201IRSA16R I received were obviously ancient stock because the pins needed cleaning before I could solder them. This involves gently rubbing the pins on a sheet of paper to remove the oxidisation, so it’s no big deal.

Other MSP430 Chips

Any other MSP430 MCU can be used and there is a LOT of variation in peripherals, memory size and types, operating voltage and packages, so I suggest researching carefully before buying.

F4 Disco Power and Target Connections

The power and flashing is done via the USB connector at the SWD STLINK programmer/interface connector.

The USB ‘terminal’ is connected by the micro USB connector next to the big black audio socket.

Target connections use only 4 wires as described below.

Target Connection Table

The STM32F4 Discovery board must be connected to the MSP430G2201IRSA16R target ($0.40 AUD) as per this Connection Table, though other MSP430 models can easily be used; just alter the pin numbers etc.

Pins

Test Clip Color

MSP430 Target Pin

PC-8

BLUE

RST - pin 9

PC-9

YELLOW

TEST - pin 10

GND

BLACK

GND - pin 14

3.3V

RED

VCC - pin 16

Target Footprint and test pcb

For the MSP430G2201IRSA16 model.

_images/MSP430G2201-pinouts.jpg _images/MSP430G2201IRSA16R-bott-view-pinouts.jpg _images/pcb-round-pins-mcu2.jpg

Target Connected To Host

_images/f4disco-roundpcb-2.jpg

My Terminal Config

For FreeBSD, Linux will have a different device.

xterm -e picocom -b 115200 /dev/cuaU1 --hangup --imap lfcrlf,crcrlf --omap delbs,crlf --send-cmd "cat" &

The awesome feature here is that because it’s using the USB driver written by Jan Bramcamp the speed seems instant, what I mean is that this is the FASTEST Forth terminal you have ever seen and as handshaking is built in, so are the source uploads.

Test Blinky

This compiled to only 36 bytes!

Source

: delay ( -- )
    65535 0 do loop
;

: minblink ( -- )
   1 p1dir c!
   begin
     1 p1out cxor! delay
   again
;

Terminal

+jtag

Chip detected: F201  ok.

target

Note

Picocom: <Ctrl+AS>, then select file to upload … in this case, blinky1.fs

*** file: blinky1.fs
$ cat blinky1.fs

*** exit status: 0 ***

: delay ( -- ) ok.
    65535 0 do loop ok.
 ; ok.
 ok.
 : minblink ( -- ) ok.
   1 p1dir c! ok.
   begin ok.
     1 p1out cxor! delay ok.
   again ok.
 ; ok.

See

Note, disassembly at this stage is in Forth!

see delay

: delay
00007784 : 0000 : $0000FFFF
00007790 : 0000 : $00000000
0000779C : 0000 : swap
000077A8 : 0000 : >r
000077B4 : 0000 : >r
000077C0 : 0000 : <--
000077F8 : 0000 : r>
00007804 : 0000 : $00000001
00007810 : 0000 : +
0000781C : 0000 : r@
00007828 : 0000 : >r
00007834 : 0000 : dup
00007840 : 0000 : r>
0000784C : 0000 : swap
00007858 : 0000 : >r
00007864 : 0000 : =
00007870 : 0000 : 0-Branch $000077C0
0000787C : 0000 : r>
00007888 : 0000 : drop
00007894 : 0000 : r>
000078A0 : 0000 : drop
000078AC : 0000 : ;
ok.


see minblink

: minblink
000078F8 : 0000 : $00000001
00007904 : 0000 : $00000022
00007910 : 0000 : c!
0000791C : 0000 : <--
00007954 : 0000 : $00000001
00007960 : 0000 : $00000021
0000796C : 0000 : cxor!
00007978 : 0000 : delay
00007984 : 0000 : Branch $0000791C
00007990 : 0000 : ;
ok.

Flash Target

Select host mode

host

Output With Stats

Memory usage in Flash without vector table 36 bytes.
Memory usage in RAM   without stacks       0 bytes.
Required passes: 1

Disassembly

Note: disassembly is now machine code and of entire target binary image.

disimage

F800: 40B2  mov.w #5A80h, &120h
F802: 5A80
F804: 0120
F806: 4031  mov.w #280h, r1
F808: 0280
F80A: 4034  mov.w #260h, r4
F80C: 0260
F80E: 43D2  mov.b #1h, &22h
F810: 0022
F812: E3D2  xor.b #1h, &21h
F814: 0021
F816: 4307  mov.w #0h, r7
F818: 4338  mov.w #FFFFh, r8
F81A: 5317  add.w #1h, r7
F81C: 9807  cmp.w r8, r7
F81E: 23FD  jnz F81A
F820: 3FF8  jmp F812
F822: 3FFF  jmp F822

Memory usage in Flash without vector table 36 bytes.
Memory usage in RAM   without stacks       0 bytes.

Hexdump

Then paste into a file on your pc to use later if flashing blank targets with a Ti Programmer, tho it’s easier to do with Mecrisp-Access.

hexdump

:10F80000B240805A20013140800234406002D2432D
:10F810002200D2E321000743384317530798FD2302
:10F82000F83FFF3FFFFFFFFFFFFFFFFFFFFFFFFF6F
:10FFF000FFFFFFFFFFFFFFFFFFFFFFFFFFFF00F817
:00000001FF

Note

Install msp430-binutils to convert hexfiles to binary

msp430-objcopy -I ihex -O binary $HEXFILE $BINARYFILE

Extras

One of Matthias favorites is the MSP430F2012

Available in TSSOP and DIP for thru hole hobbyists.

5Jan2022 @ arrow.com there are 144 parts off MSP430F2012IN available for $2.4425 USD each in minimum batch of 25 units. MCU 16-bit MSP430 RISC 2KB Flash 2.5V/3.3V 14-Pin PDIP Tube.

https://www.arrow.com/en/products/msp430f2012in/texas-instruments

_images/msp430f2012-1.jpg _images/msp430f2012-2.jpg

Round Pcb Construction

How the Roundpcb was made: https://mecrisp-stellaris-folkdoc.sourceforge.io/turret-pins.html