SpinalHDL blinky


#1

Continuing the series on programming the TinyFPGA BX with different high-level Hardware Description languages - see Migen hello blinky world.

Here is an example of using SpinalHDL to program your TinyFPGA BX.

And here is the Verilog that it generates:

// Generator : SpinalHDL v1.3.1    git head : 9fe87c98746a5306cb1d5a828db7af3137723649
// Date      : 09/02/2019, 15:55:59
// Component : LedGlow


module LedGlow (
      output  io_led,
      input   clk);
  wire [3:0] _zz_1_;
  wire [4:0] _zz_2_;
  wire [4:0] _zz_3_;
  reg [23:0] cnt;
  reg [4:0] pwm;
  reg [3:0] pwmInput;
  assign _zz_1_ = pwm[3 : 0];
  assign _zz_2_ = {1'd0, _zz_1_};
  assign _zz_3_ = {1'd0, pwmInput};
  always @ (*) begin
    if(cnt[23])begin
      pwmInput = cnt[22 : 19];
    end else begin
      pwmInput = (~ cnt[22 : 19]);
    end
  end

  assign io_led = pwm[4];
  always @ (posedge clk) begin
    cnt <= (cnt + (24'b000000000000000000000001));
    pwm <= (_zz_2_ + _zz_3_);
  end

endmodule

The LedGlow example makes the LED glow a bit like the bootloader - in fact it is hard to tell from the bootloader, except that the LED glows slower (based on the width value in the program).

SpinalHDL is an extremely powerful and succinct language, based on Scala, that checks your design and generates error-free Verilog. I am using the sbt build system version on Linux but it is possible to set it up to use an IDE.

But the real advantage of using it comes when you use the VexRiscV system which won the recent competition for the smallest and fastest Risc-V implementation.

It is much faster than picorv32, and there are several SoC implementations based on it. I am currently using the Murax SoC as a basis for a Soft Risc-V Arduino system, but I am currently doing that on my BlackIce ice40 board.

There is also SaxonSoc which looks like it will be even better, although it is more aimed at UP5k devices.


#2

SpinalHDL looks good the code is readable and documentation look really nice. I was at FOSDEM a presentation in 2017 on this subject.


#3

The documentation link should be https://spinalhdl.github.io/SpinalDoc-RTD/