Select the uC type by including the correct include file, e.g.
m328def.inc for Atmega 328.
Configure the clock and baudrate according to your hardware and preferences.
These configurations are done in the configuration file, avr/src/config.inc.
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.
Compiling with avrasm2. The wine prefix is for linux
$ wine asm2/avrasm2.exe -I asm2/include/ avr/src/ff-atmega.asm -o out.hex -fI
FlashForth has been tested on Atmega 2560, 128, 328 and 32u4 sofar.
It should also work on Atmegas 168, 644 and 16u4.
FlashForth has been tested on the Arduino Leonardo, Duemilanove, Mega 2560 R3 and Uno R3.
Just pay 12EUR to oh2aun at gmail.com (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.
Connect the ISP programmer to your PC and to your Arduino UNO board
The avrdude command line for programming the FF image looks like this on a linux machine. Note that the extended fuse value of 0xff is given as 0x07 because avrdude reads out the unused bits as 0 in the verification phase.
$ avrdude -p m328p -c stk500 -P /dev/ttyACM1 -e -u -U flash:w:ff_uno.hex:i -U efuse:w:0x07:m -U hfuse:w:0xda:m -U lfuse:w:0xff:m
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 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 turnkeyTo use individual interrupt sources, the interrupt enable bits and flag bits for each interrupt source must be used.
SP: The return stack pointer
Y(R28, R29) : The parameter stack pointer
X(R26, R27), Z(R30, R31): Temporary data and pointers
R24, R25: Cached TOS value
R22, R23: Internal flags
R20, R21: The P register
R18, R19: The A register
R0, R1, R16, R17: Temporary data for assembler words.
R4, R12, R13: CPU load measurement result (optional).
R14, R15: Millisecond counter.
R10, R11: Buffered flash page address.