RISC-V Processor On TinyFPGA BX

The TinyFPGA BX board is a tiny FPGA board based on ICE40LP8K from Lattice. The board is a perfect choice for hobbyist and makers that want start with FPGAs. Now with Instant SoC the development will be as easy as working with micro-controllers without sacrificing the flexibility and power of FPGAs.

RISC-V processor / Instant SoC running on a TinyFPGA BX ICE40
RISC-V On TinyFPGA BX

This tutorial will be using iCEcube2 for building the output from Instant SoC. For programming the TinyFPGA board follow instructions found on TinyFPGA.com.

We will create a very simple system that controls a LED with a PWM controller. The LED will ramp up during 1 s, do a couple of flashes and then ramp down.

Make sure Instant SoC and Lattice Diamond are installed properly.

Start Instant SoC and select a directory. Make sure to check the “create a example cpp file” option. Press the “Setup Project Folder” to create the project files.

Start Visual Studio Code and open the folder you created. Open the “example.cpp” file and remove the FC_IO_Out object. Add a FC_IO_PWM object and name it “led”.

The clk input on the board is 12 MHz so we need the change the “clk” constructor argument to 12. The C++ code will then look like the following.

Setup the timer and add the for-loops according to code below.

#include "fc_io.h"
#include "fc_system.h"

int main()
{
    //% hw_begin
    FC_IO_Clk clk(12);
    FC_IO_PWM led(1);
    FC_System_Timer timer;
    //% hw_end
 
    led.Setup(100, TU_clk);

    for (;;)
    {
        // Count up
        for( int i=0; i< 100; i++) {
            led.SetOnOff(0,i,0);
            timer.Sleep(10, TU_ms);
        }
        // A couple of flashes
        for( int i=0; i< 5; i++) {
            led.SetOnOff(0,100,0);
            timer.Sleep(100, TU_ms);
            led.SetOnOff(0,0,0);
            timer.Sleep(100, TU_ms);
        }
        // Count down
        for( int i=100; i>0; i--) {
            led.SetOnOff(0,i,0);
            timer.Sleep(10, TU_ms);
        }        
    }
}

Build it with “Ctrl+Shift+B”. A couple of files are now generated, e.g. example.vhd. This VHDL file contains a RISC-V processor with memories and code to execute the C++ code above. If you prefer Verilog a Verilog header is also created.

Start iCECube2 and create a new project. Select iCE40 / LP8K / CM81 device. Add the “example.vhd” file that was created above. Make sure you use Synplify Pro for synthesis.

Create a constraints file with the following content to assign the pins.

set_io clk B2
set_io led B3

Add this constraints file to “P&R Flow”-“Add P&R Files”-“Constraints File”. Run Synthesis and Place and Route.

To show the efficiency of Instant SoC we show the device utilization on this very tiny FPGA:

Device Utilization Summary
    LogicCells                  :	894/7680
    PLBs                        :	181/960
    BRAMs                       :	10/32
    IOs and GBIOs               :	2/63
    PLLs                        :	0/1

That all! Now you can download the programming file to the TinyFPGA. If TinyProg is correct installed you type at the Windows command prompt:

tinyprog -p "filename.bin"

Connect your FPGA