FORTH on Arduino

From Modding Fridays
Jump to: navigation, search

Trying to put some FORTH in there...


FORTH on Arduino


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/ b/avr/src/
index 21f6bff..fc5a359 100644
--- a/avr/src/
+++ b/avr/src/
@@ -4,9 +4,10 @@
 ;.include ""  ;
 ;.include ""  ; Tested     Fuses: E:0xff H:0xdc L:0xff
 ;.include ""   ; Tested     Fuses: E:0xff H:0xdc L:0xff
+.include ""    ; Tested     Fuses: E:0xf8 H:0xdf L:0xff
 ;.include ""
 ;.include ""   ; Tested    Fuses: E:0xff H:0xda L:0xff
-.include ""   ; Tested    Fuses: E:0xff H:0xda L:0xff
+;.include ""   ; Tested    Fuses: E:0xff H:0xda L:0xff
 ;.include ""
 ;.include ""

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
         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 -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 script

sudo python --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.


Fuses? FUSES!

A Handy calculator:

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


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!


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