FPz8 – An Open Source Microcontroller in VHDL

Have you ever wondered about building your own microcontroller? For the vast majority of developers, hobbyists and small companies this may sound as something completely unfeasible, but what if instead of designing a silicon chip we design a microcontroller using programmable logic? Then almost anyone would be able to design and build a microcontroller! I know that the programmable logic domain (the famous CPLD and FPGAs) is still obscure for most people, so it was for me (and still is as I am not an HDL expert)!

That’s why, in early 2016, I decided to study more on VHDL and to accomplish that, focus on a field I really love which is CPU design. At first I ported the VHDL code I’ve written for the Ahmes CPU into a synthesized version which I tested on a Cyclone IV FPGA from Altera.

Then I decided to take a step further and start a new project: designing a commercially available microcontroller CPU. The main idea was to design a softcore able to run object-code of an available commercial platform and also include additional features such as a built-in debugger.

I started designing an HCS08 based softcore but after a couple days I figured out that BDM implementation (the HCS08 debugger) would be far more complex than I wanted at that moment. So I started to wonder about another microcontroller, one that would be simple and fun to work with and which had a simple debugging hardware. After a couple weeks with no evolution, I thought about the Zilog Z8 Encore: they are a microcontroller family with a nice CISC instruction set, Harvard architecture and a simple-yet-nice debugger (OCD – On-Chip Debugger) which operates over a simple asynchronous serial line! Besides Zilog offers a free lightweight IDE (the Zilog Developer Studio or ZDS-II) which includes an editor, ANSI-C compiler, simulator and integrated debugger

About one month of work later the first completely functional version of the FPz8 came out, a Zilog Z8 Encore object-code compatible softcore which was successfully implemented on an Altera Cyclone IV FPGA (model EP4CE6).

Figure 1 – FPz8 block diagram with a basic timer

FPz8 was designed as a SoC (System on Chip) meaning it doesn’t need any external component (except for the FPGA configuration memory and clock oscillator) to operate (usually a softcore is designed to use external memories). That means it is possible to test and use FPz8 on virtually any FPGA kit!

Figure 2 – The kit used to design FPz8

The softcore includes all the basic infrastructure for the eZ8 operation: a eZ8 core with most instructions implemented (except for LDE and LDEI external data manipulation instructions), an 8-input vectorized interrupt controller with programmable priority and a fully functional OCD debugger! Isn’t it fancy?

And do you know what is the coolest about FPz8? By using a serial-to-USB converting chip (usually present on most FPGA kits)  and Zilog’s official IDE it is possible to download and debug code running on the FPGA memory! That means you can write a program in Assembly or C, assemble/compile it, download it to the FPGA and follow it running, execute it step-by-step and even inspect and change variables and registers! Is it cool or not?

I know this is not new, there are other softcores freely available (probably the most famous are Open430 and NEO430 both of them implementations of TI’s MSP430), but FPz8 comprises a very simple architecture, compatibility with a simple-lightweight IDE and can be used for studying programming, computer architecture and embedded systems! And you can change it to fit your needs, include new instructions or peripherals! And finally, as it is simple and fits even the cheapest kits, it is very cheap to use the FPz8 to teach programmable logic and microcontroller programming!

As it is, FPz8 occupies around 4889 logic elements and around 522 registers (that is some 78% of the available logic elements on the smallest Cyclone IV device, EP4CE6), a simple 16-bit basic timer module adds up another 120 logic elements and 61 registers to that amount. The maximum clock speed is 23.1MHz (the example project runs at 16.667MHz).

FPz8 complete code, including Quartus II (version 9.1sp2) project can be found at my GitHub account or at Opencores.org website! Remember: FPz8 is completely open source!

I also recorded a video some months ago showing the FPz8 (unfortunately it has low quality and it is in Portuguese, but English subtitles are available). Nuts & Volts Magazine will also publish an article featuring my FPz8 soon!

In my next articles I will describe some FPz8 internal characteristics and also show some examples. See you!

References

  1. Ahmes – Implementation on an Altera Cyclone IV FPGA
  2. FPz8 at GitHub
  3. FPz8 at OpenCores
  4. Zilog’s website
  5. Cyclone IV kit at Ebay
  6. Quartus II SP2
  7. Cyclone IV page at Altera
  8. Nuts & Volts magazine

Leave a Reply