Tutorial: How to use the BASCOM-AVR IDE and the Papilio One to run BASIC programs on an FPGA

Prior to starting this tutorial, you should verify that the FTDI drivers are installed correctly and verify that your Papilio One board is working correctly by following the Papilio One Quickstart Guide.


This tutorial will demonstrate how to easily and seamlessly use the BASCOM-AVR IDE to develop and compile BASIC programs that will run on the pre-synthesized open source AVR8 soft-processor (based on the ATmega103). The AVR8 softprocessor used in this tutorial is optimized to run on Gadget Factory’s Papilio One FPGA development platform, and is automatically loaded to the FPGA when you tell BASCOM to program the device.


It’s natural to ask why you should want to emulate AVR functionality on an FPGA. It wouldn’t make sense to use an FPGA chip just to do the job of an inexpensive microcontroller. The real power of using an FPGA is that you can synthesize additional hardware and logic on the same chip that can be internally interfaced to the AVR8 soft-processor. That way, a developer can use a higher level environment like avr-gcc, BASCOM, or even an Arduino sketch to design a user interface that can might be used in turn to control additional high speed application-specific functionality within the other cores or logic that is simultaneously running in parallel on the same FPGA chip.

Additional cores and logic can be developed from scratch in VHDL, Verilog, or schematically by using Xilinx’s free Webpack FPGA Integrated Development Environment, or you can also use the tools in Webpack to augment the AVR8 soft-processor with cores now available as open source projects at sites like opencores.org. It’s worth saying that integrating other cores with the AVR8 soft-processor is not a walk in the park and goes beyond the scope of this introductory tutorial, but will be addressed in future tutorials.

The Tutorial:

Step 1: Download BASCOM AVR Basic Compiler Demo from MCS Electronics and install it.

Step 2: Download the Gadget Factory BASCOM Toolchain for Papilio (also supporting older legacy Gadget Factory Butterfly development boards) and unzip it to any folder. (The BASCOM Toolchain combines your compiled program with the AVR8 Softprocessor, and then streaming the resulting .bit file to the Papilio One.)

Step 3: Open BASCOM-AVR from the Start menu by going to Start->All Programs->MCS Electronics->BASCOM-AVR->BASCOM-AVR.

Step 4: Click on the Options dropdown menu from the top of the screen and select Programmer.

Step 5: Click to the right of Programmer in the Options window and select External programmer from the drop down list.

Step 6: Click the folder to the right of Program.

Step 7: Browse to the location where you unzipped BASCOM Toolchain for Papilio, open the folder, and double click on the file “BASCOM Toolchain.bat” (or “BASCOM Toolchain”, depending on your settings in the Windows folder options settings).

Step 8: Click in the field to the right of Parameter.

Step 9: Type “{FILE}” (without quotes), followed by a space, and then add the flag that corresponds with your specific Papilio or legacy Butterfly development board according to the table below:


Development Board Flag
Papilio One 250k papilio_papilioOne_250
Papilio One 500k papilio_papilioOne_500
Papilio Overshield 250k papilio_Uno_250
Butterfly 2.01 butterfly_2p01
Butterfly Flight butterfly_flight
Butterfly Light butterfly_light


Step 10: Place a check in the box to the left of “Use HEX file”.

Step 11: Optionally, you can place a check in the box next to the left of “Program after compile” to program your board automatically after each time you compile a program.

Step 12: Click on the Compiler tab in the Options window.

Step 13: Click on the dropdown menu to the right of Chip and select m103def.dat.

Step 14: Click the Ok button at the bottom of the window.

Step 15: Enter following test program can be run on the Papilio One with the Button/LED wing to verify everything is working correctly:

Step 16: Press F7 to compile the program. If you didn’t select “Program after compile” in Step 10, then you’ll also need to press F4 to program the board.

Once loaded, you should see the LEDs on the Button/LED wing of the Papilio One each all toggling one by one in series to an “on” state in series, then to an “off” state.

Additional notes:

When a BASCOM program is compiled and programmed to an FPGA as described in this tutorial, it’s actually being merged with a pre-synthesized version of the open source AVR8 core optimized to run on the Papilio One FPGA hardware. The AVR8 is based on the ATmega103 processor and includes a full toolchain developed specifically for seamless integration with the BASCOM environment.

Existing BASCOM code should be easily ported to the AVR8, and BASCOM code written for the ATmega103 will likely run without any modification. There are a couple of differences worth noting between the AVR8 soft-processor and a true ATmega103:

First, the AVR8 is limited to 16K versus 128K on the ATmega103. The smaller available space is intended to allow more room on the FPGA for dedicated cores. To give you a frame of reference as to the space considerations, the AVR8 core with 16K of RAM will consume about 37 to 38% of the resources on a Papilio One 500K, versus 75% of the resources on a Papilio One 250K and other legacy Butterfly boards. With this in mind, we strongly recommend the Papilio One 500K for those intending to run the AVR8 along side larger cores.

Second, since FPGAs are digital devices by design, they lack the analog inputs available on the ATmega103 and other AVR processors.  With this said however, Gadget Factory is working on a modified version of the AVR8 that should add comparable simulated ADC functionality requiring very minimal hardware. We hope to release this in the near future.

Lastly, the BASCOM IDE is a terrific environment to begin developing for the Papilio One, either as a starting place for those wanting to dive into the world of FPGAs, as well as for developers looking for a rapid development tool to integrate an AVR based softprocessor core into an FPGA based design. The demo version downloaded for this tutorial is limited compiling 4K of the available 16K on the AVR8. We encourage you to buy the full version of BASCOM-AVR if you want to take full advantage of the AVR8 softprocessor on the Papilio One.


Bryan Pape

Gadget Factory

Tags: , , ,

Leave a Reply

You must be logged in to post a comment.