Installing on Atmega and Arduino

Select the uC type by including the correct include file, e.g. for Atmega 328.
Configure the clock and baudrate according to your hardware and preferences.
This is done in the configuration file, avr/src/

Compile the code with AVR Studio and program the hex file with a suitable JTAG or ICSP programmer to your chip.
The fuses must be set to BOOTSIZE=1024 words and the BOOTRESET should be active.

FlashForth has been tested on Atmega 2560, 128 and 328 sofar.
It should also work on Atmegas 168 and 644.

FlashForth has been tested on the Arduino Duemilanove, Mega 2560 R3 and Uno R3.

Preprogrammed Atmega328 chips with FF for the ArduinoUno R3 can be ordered from oh2aun at note.gif

Just pay 10EUR or 12USD to oh2aun at (PayPal), include your postal address and I will mail you a preprogrammed Atmega328 chip.

For the Arduino boards there are two hex files in the avr/hex directory.

Programming the Arduino UNO board with the ff_uno.hex file.

Inlining of words

FF can compile location independent assembler primitives as inline code. The shortest of these words have the inline bit set in the word header for automatic inlining.

Individual words can be inlined by prefixing the word with INLINE.

: newswap inline swap ; 

When compiling a new word that should be inlined automatically, the inline flag can be set with the word INLINED.

On the Atmega the following words are always inlined by the compiler.

rp@ >< cell+ cells char+ chars invert 1+ 1- 2+ 2- 2* 2/
p+ @p p2+ ei di dup drop rdrop >body idle busy

On the Atmega the following words can be prefixed with INLINE.

ticks 1 over swap + - and or xor mset mclr lshift rshift
sp@ sp! !p p++ flash eeprom ram cell false true state ticks >pr
d+ d2/ dinvert fl- fl+

Also words defined by CONSTANT, VARIABLE, 2CONSTANT and 2VARIABLE can be inlined. They compile the constant and the variable address as inline literal code.

If you append the definition with INLINED, the compiler will later compile the constant as an inline literal.

34 constant thirtyfour inlined 
: literal-34 thirtyfour ;

Interrupt handling

Interrupt routines can be written in assembly or in Forth. FF interrupt words have to be ended with ;I .

The interrupts use the parameter stack of task that happened to be executing when the interrupt occured.

In general Forth words that normally would be used in an interrupt word are interrupt safe.
Words that start the interpreter or compile new words should not be used in an interrupt.
It is not possible to store to flash or eeprom in an interrupt routine.

The following registers are always preserved before the interrupt word is executed:

R0 R1 R16 R17 R24 R25 R26 R27 R28 R29 R30 R31

To activate the interrupt you store the interrupt word xt into the interrupt vector.

' my_irq 10 int!

The interrupt vectors are stored in ram. The interrupt vectors in ram are cleared at warm start, so to enable the interrupt word at startup, a initialization word must be used.

: irq_init ['] my_irq 10 int! ;
' irq_init is turnkey 
To use individual interrupt sources the interrupt enable bits and flag bits for each interrupt source must be used.

Register usage and memory usage

SP: The return stack pointer
Y : The parameter stack pointer
X,Z: Temporary data and pointers
r24,r25: Cached TOS value
r22,r23: Internal flags
r20,R21: The P register
All other registers are used internally by FlashForth.