FlashForth: Compile a New Version

3 minute read

Where I describe in detail how to compile a new version of FlashForth.


Its helpful to be able to compile a new version of FlashForth. A simple reason is to increase the baudrate from 38400 to 250000, increasing your productivity. It isn’t difficult, however the tool chain can be a bit complex.


You will need to install both the MPLAB IDE and the XC8 compiler for this exercise. You will also need a hardware programmer such as the Atmel ICE or Microchip SNAP. And finally, you will definitely need the source code of which to compile, Flashforth on github.

Note: As of March 11, 2024, it appears that XC8 version 2.46 has a bug in that it creates errors on “C Language” directives in header files. The errors appear as (and lots of them):

/Applications/microchip/xc8/v2.46/avr/avr/include/avr/builtins.h:59: Error: unknown opcode `extern'

This has been fixed in the latest version of FlashForth, please make sure your version is April 1, 2024 or later. Once you have both the application and programmer, follow these instructions. They are specific to macOS, however, Linux and Windows will be quite similar.

MPLAB X Compilation

1. In terminal:

cd Documents/flashforth
cp -r avr/FF-ATMEGA.X/ ~/Desktop/FF-ATMEGA.X/
cp -r avr/src/ ~/Desktop/FF-ATMEGA.X/src

I do this to keep the flashforth folder clean, so that I can easily update the folder when the overall FlashForth source is updated.

2. Connect both Uno and Atmel ICE to Mac

In my case, I’m using the Atmel ICE to program the Uno. The SNAP will work as well. You might also be able to use another UNO, using the second UNO as an in-circuit-programmer.

3. Open MPLAB X

Follow the following steps in MPLAB IDE:

  1. File -> New Project -> Standalone Project (Microchip Embedded -> Application Project(s))
    1. Device: 328P and Tool: Atmel ICE…
    2. Choose XC8 as your compiler (XC8 2.45 works, 2.46 generates errors)
    3. Browse to Desktop and make the Project Folder FF-ATMEGA.X
    4. Set Project Name: FF and Set as main project (Creates FF.X folder which becomes the main folder)
    5. Finish
  2. In the Projects column on the left, right-click on Source Files and add Existing Item ../src/ff-xc8.asm (you will need to click the file drop down and go up one folder, to select src folder then the file ff-xc8.asm)
  3. Put the following text in Production -> Set Project Configuration -> Customize -> XC8 Global Options -> Additional Options then click Apply and OK

4. In your editor


Convert all <.inc> references to “.inc” (include quotes on change)

# in Sublime Text, Shift-Cmd-F, be sure ".*" is checked for regex search
# Made 3 replacements

Optional Change the following line 5792 (search for FlashForth), it can be anything you want to show up on reset.

# original line
        .ascii    "FlashForth 5 "
# new line
        .ascii    "FF 5 250k    "

Confirm the new text length matches the same spacing as the previous text!


Change the following line 41, this increases baud rate to 250k

# original line
#define BAUDRATE0 38400
# new line
#define BAUDRATE0 250000


Add the lines to look like this, adding the 3 DDRn registers, DDRB, DDRC and DDRD. It’s easy to reference the other two registers for each port, off of the DDRn register.:

; list here the registers and constants you want to include in the FF core dictionar
; The parameters are
; constant value, word name, word flags (inline=0x20)
m_const DDRB,ddrb,0
m_const DDRC,ddrc,0
m_const DDRD,ddrd,0

5. In terminal

cd ~/Desktop/FF-ATMEGA.X/FF.X
cp dist/default/production/FF.X.production.hex ~/Desktop/FF.hex
cd ~/Desktop
# if your using Atmel ICE and ATmega328P (Uno)
avrdude -p m328p -P usb  -c atmelice_isp -e -U flash:w:FF.hex :i -U efuse:w:0xff:m -U hfuse:w:0xda:m -U lfuse:w:0xff:m

# if you specify ATmega328PB in your project setup, you can use a ATmega328PB mini
# if your using Microchip ATmega328PB Xplained Mini
avrdude -p m328pb -P usb  -c xplainedmini -e -U flash:w:FF.hex :i -U efuse:w:0xff:m -U hfuse:w:0xda:m -U lfuse:w:0xff:m

The last step will use avrdude to copy the new .hex file from your system to the Uno. Open you serial application and see if it works!

Next Step: FlashForth Uno HAL

Comments powered by Talkyard.