Mecrisp on Tiva

Posted at 2017-07-13.

I went through some of the Jeelabs posts again the other day. I thought that the idea of using Forth to poke at devices on SPI/I2C buses, timers, etc would be a handy way to prototype things like counters, displays and the like.

I picked up the mecrisp binary and a Tiva Launchpad to try that. Problem is, none of the words seem to match any of the tutorials io-wise. I cloned the Jeelabs mecrisp repo and built the LM120 version and flashed that.

Mecrisp-Stellaris 2.3.7 for LM4F120 by Matthias Koch
.s
.s Stack: [0 ]  TOS: 42  *>
 ok.

I set local echo on in Putty, so pastes like this would look pretty funky. Still, things I input (like .s) are mostly on a line by themselves and the echo followed the output are on the next line.

Simce I'm stuck doing this with the windows laptop, I used TI's LM flash programmer. It works nicely and eats bin files just perfectly, but the software download process from TI is just ridiculous. I didn't want to deal with trying to work out libusb on Windos this time. It would be interesting to try and set up some CI builds for various github projects sometime, and lm4tools is definitely one useful one.

$ make
arm-none-eabi-as mecrisp-stellaris-lm4f120.s -o mecrisp-stellaris-lm4f120.o
arm-none-eabi-ld -o mecrisp-stellaris-lm4f120.elf -T memmap mecrisp-stellaris-lm4f120.o
arm-none-eabi-objdump -D mecrisp-stellaris-lm4f120.elf > mecrisp-stellaris-lm4f120.list
arm-none-eabi-objcopy mecrisp-stellaris-lm4f120.elf mecrisp-stellaris-lm4f120.bin -O binary

$ arm-none-eabi-size.exe *elf
   text    data     bss     dec     hex filename
  15368       0       0   15368    3c08 mecrisp-stellaris-lm4f120.elf

Another problem is how to bundle up libraries or feed them to mecrisp so I'll have some more useful words on flash. I don't want to feed them in a line at a time. I'll have to look into that. Folie is probably the most advanced and easy cross-platform thingy here.

JCW apparently has also been working on having working native USB for input. That would be a massive improvement on the UART channel over the debugger. Downside is that there's only the STM32 implementation. I've used the TI code for USB ACM mode before on a project and it's a fantastic thing. Like a serial line where messages just magically appear on the other end with no clocking, handshaking or other issues and no perceptible delay. ST's USB implementation is apparently shadier and IIRC conflicts with CAN on the popular STM32F103 chips. TI's CAN bus I know works just fine even simulatneously with USB.

Of course I'd also be better off running a dirt cheap blue board or the Maple mini clones eventually, since they're cheap and easy to buy in small packs, but I wanted to use the launchpad for something. It does have a ton of I/O, peripherals, power, and a known working USB port to its credit. And there's also the Connected Launchpad.

Make something happen

So, the Tiva LP has an RGB LED connected to PF1-3 (order RBG). It also has switches on PF4 and PF0.

I need to find the clocks and enable the right ones. Then set direction, enable IO, and set the pin. I believe I can skip the other IO controls safely. I don't have that standard library or any other definitions. MMIO should work, though. I waded through the datasheet for the values. (Nice 1409 pages of hyperlinked facts.) It builds character and should give correct values and usage notes.

System control base is 0x400f.e000. RCGCGPIO is offset 0x0608. Bit 5 high should enable GPIOF.

The board has driver transistors and should light a LED on 1, enable and output are also 1. GPIO F is at 0x4002.5000 for APB and 0x4005.d000 for AHB. Either should work. GPIO DATA is offset 0x0000, DIR is 0x0400, DEN (digital EN) is 0x051C. All have the bottom byte mapped to the IOs.

Then there is the funny business with the mask on the pin setups (10.2.1.2).

So, sketch some code here:

$400fe000 constant SCBASE
$0608     constant RCGCGPIO

$40025000 constant GPIO.PORTF
$4005d000 constant GPIO.PORTF \ this needs something more
$0400     constant GPIO.DIR
$051C     constant GPIO.DEN
$0e constant LEDS
$38 constant MASK

1 5 lshift SCBASE RCGCGPIO + ! \ clock port f

LEDS GPIO.PORTF GPIO.DIR + ! \ set dir
LEDS GPIO.PORTF GPIO.DEN + ! \ enable

$02 GPIO.PORTF MASK + ! \ R
$04 GPIO.PORTF MASK + ! \ B
$08 GPIO.PORTF MASK + ! \ G
$06 GPIO.PORTF MASK + ! \ M
$0a GPIO.PORTF MASK + ! \ Y
$0c GPIO.PORTF MASK + ! \ C
$0e GPIO.PORTF MASK + ! \ W
$00 GPIO.PORTF MASK + ! \ Off

This is overly verbose and probably not very smart or frothy, but I'm just trying stuff out here.

Conclusion

It's certainly possible to use mecrisp for doing some things and doing them interactively. Whether using Tiva LP is worth it, I don't know. There would be lots of educational little stuff to do and lots of capacity for things.

I definitely should get to know Folie and see how that works.

Links