FORTH on Arduino

From Modding Fridays
Jump to: navigation, search

Trying to put some FORTH in there...

float

FORTH on Arduino

FlashForth

http://flashforth.com

http://flashforth.com/ff5-tutorial-guide.pdf

Arduino Diecimila (ATMEGA168-20PU)

There are no ready to use .hex file for this device in the FlashForth distribution.

Making an hex file

avra did not work with the FlashForth source, it is recommended to use the official assembler from Atmel: [avrasm2.exe].

  • Make the following changes to the source files:
diff --git a/avr/src/config.inc b/avr/src/config.inc
index 21f6bff..fc5a359 100644
--- a/avr/src/config.inc
+++ b/avr/src/config.inc
@@ -4,9 +4,10 @@
 ;.include "m2561def.inc"  ;
 ;.include "m2560def.inc"  ; Tested     Fuses: E:0xff H:0xdc L:0xff
 ;.include "m128def.inc"   ; Tested     Fuses: E:0xff H:0xdc L:0xff
+.include "m168def.inc"    ; Tested     Fuses: E:0xf8 H:0xdf L:0xff
 ;.include "m168pdef.inc"
 ;.include "m328pdef.inc"   ; Tested    Fuses: E:0xff H:0xda L:0xff
-.include "m328def.inc"   ; Tested    Fuses: E:0xff H:0xda L:0xff
+;.include "m328def.inc"   ; Tested    Fuses: E:0xff H:0xda L:0xff
 ;.include "m32adef.inc"
 ;.include "m644pdef.inc"

diff --git a/avr/src/ff-atmega.asm b/avr/src/ff-atmega.asm
index 555e5c2..61dd095 100644
--- a/avr/src/ff-atmega.asm
+++ b/avr/src/ff-atmega.asm
@@ -5340,7 +5340,7 @@ WARM_1:
         ldi     xl, 0x1C  ; clear ram from y register upwards
 WARM_2:
         st      x+, r_zero
-        cpi     xh, 0x10  ; up to 0xfff, 4 Kbytes
+        cpi     xh, 0x04  ; up to 0x3ff, 1 Kbytes
         brne    WARM_2

 ; Init empty flash buffer
  • Generate ff-atmega.hex:
wine avrasm2.exe -I /include/path -o ff.hex -l ff.lst -m ff.map -fI ff-atmega.asm
  • Use avrdude to flash:
avrdude -p m168 -c usbtiny -e -u -U flash:w:ff.hex:i -U lfuse:w:0xFF:m -U hfuse:w:0xDF:m -U efuse:w:0xF8:m -U lock:w:0xFF:m

Connect to FlashForth

screen /dev/device 9600

or use the ff-shell.py script

sudo python ff-shell.py --xonxoff -s 9600 -p /dev/ttyACM0

this python script can also send .txt files to flashforth

#send ../forth/test

to send the file test.txt to flashforth in a slow way not to overflow the buffer.

Troubleshooting

Fuses? FUSES!

A Handy calculator: http://eleccelerator.com/fusecalc/fusecalc.php

The fuses must be set to BOOTSIZE=1024 words and the BOOTRESET should be active.

avrdude

Test if avrdude sees the AVR Pocket Programmer correctly:

sudo avrdude -c usbtiny -p m8

If it complains about checking connections, then it's all good!

FreeBSD

Of course, FreeBSD FTDI support is different from Linux:

ugen3.2: <FTDI FT232R USB UART> at usbus3
uftdi0 on uhub2
uftdi0: <FT232R USB UART> on usbus3

Which means, somehow that the device will be available at /dev/cuaU0

sudo screen /dev/cuaU0 9600