Quantcast
Channel: iCE40 – Hackaday
Viewing all 25 articles
Browse latest View live

Reverse Engineering Lattice’s iCE40 FPGA Bitstream

$
0
0

Unlike microcontroller projects, projects involving FPGAs cannot yet claim to rely on a mature open-source toolchain. Each FPGA will, at some point, need to be configured with a proprietary bitstream produced from a closed source synthesis tool. This lack of a full FPGA toolchain to take your project from Verilog-or-VHDL to an uploadable bitstream is due to many reasons. First, writing such a “compiler” is complicated. It involves intimate knowledge of the resources available on the FPGA that can assimilate the functionality of the intended design. Second, the entire synthesis procedure is closed-source, a “secret sauce” of sorts for each FPGA vendor.

In response, [Alex] and [Clifford] have taken the first step towards an open-source toolchain for one FPGA; they’ve reverse-engineered the bitstream of Latttice Semiconductor’s iCE40 FPGA. The duo didn’t just pick the iCE40 on a whim. This choice was deliberately because that FPGA is available on a development board for a mere $22 so that others could follow in their footsteps without breaking the bank.

In the video below, [Clifford] demos the functionality of this new tool by synthesizing a design from Verilog to a bitstream and then back from a bitstream to Verilog. Given this feature, a staggering amount of work has been done towards developing a polished open-source toolchain for this particular FGPA.

To snag a copy of the latest code, have a look at its documentation page.


Filed under: FPGA

An Open Source Toolchain For iCE40 FPGAs

$
0
0

FPGAs are great, but open source they are not. All the players in FPGA land have their own proprietary tools for creating bitstream files, and synthesizing the HDL of your choice for any FPGA usually means agreeing to terms and conditions that nobody reads.

After months of work, and based on the previous work of [Clifford Wolf] and [Mathias Lasser], [Cotton Seed] has released a fully open source Verilog to bitstream development tool chain for the Lattice iCE40LP with support for more devices in the works.

Last March, we saw the reverse engineering of the Lattice ICE40 bitstream, but this is a far cry from a robust, mature development platform. Along with Yosys, also written by [Clifford Wolf] it’s relatively simple to go from Verilog to an FPGA that runs your own code.

Video demo below, and there’s a ton of documentation over on the Project IceStorm project page. You can pick up the relevant dev board for about $22 as well.


Filed under: FPGA

Hackaday Prize Entry: They Make FPGAs That Small?

$
0
0

There are a few development boards entered in this year’s Hackaday Prize, and most of them cover well-tread ground with their own unique spin. There are not many FPGA dev boards entered. Whether this is because programmable logic is somehow still a dark art for solder jockeys or because the commercial offerings are ‘good enough’ is a matter of contention. [antti lukats] is doing something that no FPGA manufacturer would do, and he’s very good at it. Meet DIPSY, the FPGA that fits in the same space as an 8-pin DIP.

FPGAs are usually stuffed into huge packages – an FPGA with 100 or more pins is very common. [antti] found the world’s smallest FPGA. It’s just 1.4 x 1.4mm on a wafer-scale 16-pin BGA package. The biggest problem [antti] is going to have with this project is finding a board and assembly house that will be able to help him.

The iCE40 UltraLite isn’t a complex FPGA; there are just 1280 logic cells and 7kByte of RAM in this tiny square of programmable logic. That’s still enough for a lot of interesting stuff, and putting this into a convenient package is very interesting. The BOM for this project comes out under $5, making it ideal for experiments in programmable logic and education.

A $5 FPGA is great news, and this board might even work with the recent open source toolchain for iCE40 FPGAs. That would be amazing for anyone wanting to dip their toes into the world of programmable logic.

The 2015 Hackaday Prize is sponsored by:


Filed under: The Hackaday Prize

FPGAs For The Raspberry Pi

$
0
0

FPGA development has advanced dramatically in the last year, and this is entirely due to an open-source toolchain for Lattice’s iCE40 FPGA. Last spring, the bitstream for this FPGA was reverse engineered and a toolchain made available for anything that can run Linux, including a Raspberry Pi. [Dave] from Xess thought it was high time for a Raspberry Pi FPGA board. With the help of this open-source toolchain, he can program this FPGA board right on the Raspberry Pi.

The inspiration for [Dave]’s board came from the XuLA and StickIt! boards that give the Raspberry Pi an FPGA hat. These boards had a problem; the Xilinx bitstreams had to be compiled on a ‘real’ PC and brought over to the Raspberry Pi world. The new project – the CAT Board – brings an entire FPGA dev kit over to the Raspberry Pi.

The hardware for the CAT Board is a Lattice iCE-HX8K, 32 MBytes of SDRAM, a serial configuration flash, LEDs, buttons, DIP switches, grove connectors, and SATA connectors (although [Dave] is just using these for differential signals; he doesn’t know if he can get SATA hard drives to work with this board).

Despite some problems with his board house, [Dave] eventually got his FPGA working, or at least the bitstream configuration part, and he can blink a pair of LEDs with a Raspberry Pi and programmable logic. The Hello World for this project is done, and now the only limit is how many gates are on this FPGA.


Filed under: FPGA, Raspberry Pi

Hackaday Links: November 29, 2015

$
0
0

The Raspberry Pi Zero was announced this week, so you know what that means: someone is going to destroy a Game Boy Micro. If you’re interested in putting the Zero in a tiny handheld of your own design, here are the dimensions, courtesy of [Bert].

[Ahmed] – the kid with the clock – and his family are suing his school district and city for $15 Million. The family is also seeking written apologies from the city’s mayor and police chief.

There are a lot — a lot — of ‘intro to FPGA’ boards out there, and the huge variety is an example of how the ‘educational FPGA’ is a hard nut to crack. Here’s the latest one from a Kickstarter. It uses an ICE40, so an open source toolchain is available, and at only $50, it’s cheap enough to start digging around with LUTs and gates.

Over on Hackaday.io, [Joseph] is building a YAG laser. This laser will require a parabolic mirror with the YAG rod at the focus. There’s an interesting way to make one of these: cut out some acrylic and beat a copper pipe against a form. A little polish and nickel plating and you have a custom mirror for a laser.

You know those machines with wooden gears, tracks, and dozens of ball bearings? Cool, huh? Tiny magnetic balls exist, and the obvious extension to this line of thought is amazing.

[David Windestål] is awesome. Completely and totally awesome. Usually, he’s behind the controls of an RC plane or tricopter, but this time he’s behind a slo-mo camera, an RC heli, and a watermelon. That’s a 550-sized heli with carbon fiber blades spinning at 2500 RPM, shot at 1000 FPS.

How do you label your cables? Apparently, you can use a label printer with heat shrink tubing. Nothing else, even: just put heat shrink through a label maker.


Filed under: Hackaday Columns, Hackaday links

Does the World Need an FPGA Arduino?

$
0
0

What would you get it you mashed up an FPGA and an Arduino? An FPGA development board with far too few output pins? Or a board in the form-factor of Arduino that’s impossible to program?

Fortunately, the ICEZUM Alhambra looks like it’s avoided these pitfalls, at least for the most part. It’s based on the Lattice iCE40 FPGA, which we’ve covered previously a number of times because of its cheap development boards and open-source development flow. Indeed, we were wondering what the BQ folks were up to when they were working on an easy-to-use GUI for the FPGA family. Now we know — it’s the support software for an FPGA “Arduino”.

Icezum-rev1-1607-img1-peq_thumbnail

The Alhambra board itself looks to be Arduino-compatible, with the horrible gap between the rows on the left-hand-side and all, so it will work with your existing shields. But they’ve also doubled them with pinheaders in a more hacker-friendly layout: SVG — signal, voltage, ground. This is great for attaching small, powered sensors using a three-wire cable like the one that you use for servos. (Hackaday.io has two Arduino clones using SVG pinouts: in SMT and DIP formats.)

The iCE40 FPGA has 144 pins, so you’re probably asking yourself where they all end up, and frankly, so are we. There are eight user LEDs on the board, plus the 28 I/O pins that end in pinheaders. That leaves around a hundred potential I/Os unaccounted-for. One of the main attractions of FPGAs in our book is the tremendous availability of fast I/Os. Still, it’s more I/O than you get on a plain-vanilla Arduino, so we’re not complaining too loudly. Sometimes simplicity is a virtue. Everything’s up on GitHub, but not yet ported to KiCad, so you can tweak the hardware if you’ve got a copy of Altium.

We’ve been seeing FPGA projects popping up all over, and with the open-source toolchains making them more accessible, we wonder if they will get mainstreamed; the lure of reconfigurable hardware is just so strong. Putting an FPGA into an Arduino-compatible form-factor and backing it with an open GUI is an interesting idea. This project is clearly in its very early stages, but we can’t wait to see how it shakes out. If anyone gets their hands on these boards, let us know, OK?

Thanks [RS] for the tip!


Filed under: Arduino Hacks, FPGA

The Open Source Hacker’s Laptop

$
0
0

[Tsvetan Usunov] has been Mr. Olimex for about twenty five years now, and since then, he’s been through a lot of laptops. Remember when power connectors were soldered directly to the motherboard? [Tsvetan] does, and he’s fixed his share of laptops. Sometimes, fixing a laptop doesn’t make any sense; vendors usually make laptops that are hard to repair, and things just inexplicably break. Every year, a few of [Tsvetan]’s laptops die, and the batteries of the rest lose capacity among other wear and tear. Despite some amazing progress from the major manufacturers, laptops are still throwaway devices.

Since [Tsvetan] makes ARM boards, boards with the ~duino suffix, and other electronic paraphernalia, it’s only natural that he would think about building his own laptop. It’s something he’s been working on for a while, but [Tsvetan] shared his progress on an Open Source, hacker’s laptop at the Hackaday | Belgrade conference.

As with any project, the first step is a good googling. By typing ‘Do It Yourself Laptop’ into the Mother Brain, you get back a list of projects that are ugly and certainly not as convenient as even the largest MacBook Pro. This build from 2007 features a Mini-ITX motherboard, with all the heat and power commensurate with this odd hardware choice. You could go old school, but again this is a project to build a usable laptop. Turning to the world of Raspberry Pis, these laptops are chunky, and this one is made out of a Little Caesars box.

To be fair, not all DIY, Open Source laptops are underpowered or covered in Crazy Bread crumbs. [Bunnie]’s Novena laptop is a work of electronic art, very capable, and a laptop that could conceivably make sense as a daily driver. The Novena isn’t exactly a convenient laptop, though: it’s rather chunky, the display is on the outside, and it doesn’t have the grace of a MacBook Air or Thinkpad Carbon X1.

[Tsvetan]’s laptop combines all of these features, is lightweight, has a battery big enough to run all day, is elegant, stylish, and above all, open source. It’s a laptop that will be modular, easy to repair and upgrade, and has spare parts that are cheap.

allwinner boardTo that end, [Tsvetan] spent four months building a powerful ARM board based on a 64-bit Allwinner chip. There’s HDMI, USB, output for an LCD, and this was made in KiCad, making the schematics and board files completely open source.

There’s more to it than just an ARM single board computer running Linux to this laptop. Thanks to the recent advances of an Open Source Toolchain for the Lattice iCE40 FPGA, [Tsvetan] is thinking about making this open source laptop a true hacker’s tool, with a logic analyzer, DSO, and DDFS generator.

What’s the future of [Tsvetan]’s open source laptop? He should – hopefully – have a prototype running at TuxCon, held in Plovdiv, Bulgaria in early July. There’s still a lot of work to do, but so far [Tsvetan] has contracted a plastics manufacturer for the case, found a nice eDP panel, small camera, speakers, a battery that will last at least six hours, and has a keyboard and touchpad working.

Building a laptop from scratch is among the hardest electronic manufacturing challenges we can imagine. It’s a true full-stack development job, with skillsets ranging from writing custom drivers for Linux to the intricacies of injection molding. With any luck, [Tsvetan] and Olimex will have some kits ready by this September. That’s an amazingly fast development time, and wouldn’t be possible without putting all the design files up on the Internet from the start, allowing other enthusiasts to contribute to the creation of an Open Source laptop.


Filed under: cons, Hackaday Columns, laptops hacks

STM32 and FPGAs In A Tiny Package

$
0
0

Slowly, very slowly, the time when we don’t subject embedded beginners to AVRs and PICs is coming. At a glacial pace, FPGA development platforms are becoming ever more capable and less expensive. [Eric Brombaugh] has been playing around with both ARMs and FPGAs for a while now and decided to combine these two loves into a single board that’s capable of a lot.

This board is fittingly called an STM32F303 + ice5 development board, and does exactly what it says on the tin. There’s an STM32F303 on board providing a 32-bit CPU running at 72 MHz, 48 kB of SRAM, a quarter meg of Flash, and enough peripherals to keep anyone happy. The FPGA side of this board is a Lattice iCE5 with about 3k Look Up Tables (LUTs), and one time programmable non-volatile config memory.

The connections between the ARM and FPGA include a dedicated SPI port, and enough GPIOs to implement full-duplex I2S and a USART. Like all good projects, [Eric] has shared all the files, schematics, and BOMs required to make this board your very own reality, and has provided a few links to the development toolchains. While the FPGA is from Lattice’s ice40 family, it’s not supported by the Open Source Project Icestorm toolchain. Still, it’s a very capable board for ARM and FPGA development.


Filed under: ARM, FPGA

Hackaday Links: November 6, 2016

$
0
0

Here’s a life protip for you: get really, really good at one video game. Not all of them; you only want to be good – top 10% at least – at one video game. For me, that’s Galaga. It’s a great arcade game, and now it’s IoT. [justin] has been working on publishing high scores from a Galaga board to the Internet. The electronics are actually pretty simple – just a latch on a memory address, and an ESP8266 for comms.

On with the mergers and acquisitions! Lattice has been sold to Canyon Bridge, a Chinese private equity firm, for $1.3 Billion. Readers of Hackaday should know Lattice as the creators of the iCE40 FPGA platform, famously the target of the only Open Source FPGA toolchain.

The Internet of Chocolate Chip Cookies. Yes, it’s a Kickstarter for a cookie machine, because buying a tube of pre-made cookie dough is too hard. There is one quote I would like to point out in this Kickstarter: “Carbon Fiber Convection Heating Element (1300W) is more energy-efficient than traditional electric elements and heats up instantly.” Can someone please explain how a heating element can be more efficient? What does that mean? Aren’t all resistive heating elements 100% efficient by default? Or are they 0% efficient? The Internet of Cookies broke my brain.

The USB Rubber Ducky is a thumb-drive sized device that, when plugged into a computer, presents itself as a USB HID keyboard, opens up a CLI, inputs a few commands, and could potentially do evil stuff. The USB Rubber Ducky costs $45, a Raspberry Pi Zero and a USB connector costs $6. [tim] built his own USB Rubber Ducky, and the results are great.


Filed under: Hackaday Columns, Hackaday links

Adding IceZero To The Raspberry Pi

$
0
0

[Kevinhub] noticed there were quite a few FPGA hats for the Raspberry Pi. Instead going out and buying one of these boards like a filthy commoner, he decided to spin up his own FPGA Pi accessory. This IceZero FPGA board combines the best features from other FPiGA boards, and does it in a form factor that fits right on top of the minuscule Pi Zero.

If you think slapping a Lattice FPGA onto a Pi has been done before, you’re right. Here’s a hat for the Pi using an iCE5LP4K-SG48, an FPGA with 3520 LUTs. The CAT Board from Xess has a slightly bigger FPGA with 7680 logic cells, and the FleaOhm has a monster FPGA on board that costs about $70 USD.

[Kevin]’s IceZero is at the lower end of these Raspberry Pi FPGA hats, using a Lattice ICE40HX4K. That’s only 3520 logic cells, but it only costs about $7 USD in quantity one. The board design is a standard two layer board that shouldn’t be too terrible for hand soldering. The boards are shared on OSH Park, should you want to test this little guy out.

This Pi Hat is specifically designed to be used with Project IceStorm, the Open toolchain for Lattice’s iCE40 FPGAs. That means there’s already a few projects out in the wild that can be easily ported to this platform, and already [Kevin] has a logic SUMP example going on his board.


Filed under: FPGA, Raspberry Pi

Lattice iCE40 FPGA Configured by Linux Kernel

$
0
0

The Linux kernel recently added support for loading firmware into an FPGA via the FPGA Manager Framework. [OpenTechLab] has built a driver for the Lattice iCE40 FPGA (same chip used on the iCEStick and other development boards). One attraction to the iCE40 is there is an open source toolchain called iCEStorm.

Even if you aren’t specifically interested in FPGAs, the discussion about Linux device drivers is good background. The principles would apply to other drivers, and would definitely apply if you want to write another FPGA loader.

The example uses a Raspberry Pi connected to an evaluation board. A cheap Sigrok-based logic analyzer let him troubleshoot and debug. If you think FPGA development is expensive,  think again. The board used here is well under $50 and the software is free. An iCEStick is even cheaper, and would probably work here, too. You are likely to have the other bits, but even if you need to buy a Pi and the logic analyzer, the whole thing is way under $100.

We’ve covered the iCEStick and iCEStorm quite a bit in the past. There are also quite a few iCE40 boards for the Raspberry Pi that ought to work well with this, including this one.


Filed under: FPGA, linux hacks, Raspberry Pi

Learn FPGA Programming from the 1940s

$
0
0

We often think that not enough people are building things with FPGAs. We also love the retrotechtacular posts on old computer hardware. So it was hard to pass up [karlwoodward’s] post about the Chip Hack EDSAC Challenge — part of the 2017 Wuthering Bytes festival.

You might recognize EDSAC as what was arguably the first operational computer if you define a computer as what we think of today as a computer. [Maurice Wilkes] and his team invented a lot of things we take for granted today including subroutines (Wheeler jumps named after a graduate student).

The point to the EDSAC challenge was to expose people to creating designs with FPGAs, particularly using the Verilog hardware description language (HDL). If you want to follow along or run your own Chip Hack, the materials are available on the Web. You can see an FPGA driving a tape punch to create souvenir tapes in the video, below.

Some of the exercises are pretty simple and that’s perfect if you are starting out. The challenge uses a board with a Lattice ice40 FPGA and the open source toolchain for Lattice we’ve covered before. In fact, we’ve even done our own tutorials on the same basic device (but not the same board). Our final project generated PWM, not paper tape.

For the record, EDSAC was awesome. The execution unit was serial and processed bits that marched in one at a time over a mercury delay line. There is quite a bit of documentation and even some simulators, so if you ever wanted to get your hands into an old computer, this one isn’t a bad one to try.

FPGA Design From Top to Bottom

$
0
0

[Roland Lutz] gave a talk about FPGA design using the free tools for Lattice devices at the MetaRheinMainChaosDays conference this year. You can see the video below. It’s a great introduction to FPGAs that covers both the lowest-level detail and some higher level insight. If you’re getting started with these FPGAs, this video is a must-see.

[Roland] starts with the obligatory introductory material. He then jumps into an actual example before zooming back out to look at the internal details of the Lattice FPGA. For instance, this FPGA supports multiple bitstreams, so you can switch between different “programs” on the fly.

If you ever wondered how tiles and cells relate you’ll get a lot out of the low-level discussion. There’s also a very concise explanation of how tiles interconnect. If you are hazy on the difference between a span-4 and a span-12 wire, you’ll want to watch.

There’s plenty of complimentary details on the web and [Roland] includes some references at the end of the talk. We did our own introduction videos when the IceStorm tools first appeared. If you prefer a graphical tool, you might be interested in Icestudio.

An Ultrasound Driver With Open Source FPGAs

$
0
0

Ultrasound imaging has been around for decades, but Open Source ultrasound has not. While there are a ton of projects out there attempting to create open ultrasound devices, most of this is concentrated on the image-processing side of things, and not the exceptionally difficult problem of pinging a sensor at millions of times a second, listening for the echo, and running that through a very high speed ADC.

For his entry into the Hackaday Prize, [kelu124] is doing just that. He’s building an ultrasound board that’s built around Open Hardware, a fancy Open Source FPGA, and a lot of very difficult signal processing. It also uses some Rick and Morty references, so you know this is going to be popular with the Internet peanut gallery.

The design of the ultrasound system is based around an iCE40 FPGA, the only FPGA with an Open Source toolchain. Along with this, there are a ton of ADCs, a DAC, pulsers, and a high voltage section to drive the off-the-shelf ultrasound head. If you’re wondering how this ultrasound board interfaces with the outside world, there’s a header for a Raspberry Pi on there, too, so this project has the requisite amount of blog cred.

Already, [kelu] has a working ultrasound device capable of sending pulses out of its head and receiving the echo. Right now it’s just a few pulses, but this is a significant step towards a real, working ultrasound machine built around a reasonably Open Source toolchain that doesn’t cost several arms and legs.

Three Part Deep Dive Explains Lattice iCE40 FPGA Details

$
0
0

It is no secret that we like the Lattice iCE40 FPGA. It has a cheap development board and an open source toolchain, so it is an easy way to get started developing low-cost, low-power FPGA designs. There are a few members of the family that have similar characteristics including the top-of-the-line UltraPlus. [Steve] from Lattice and [Michael Klopfer] from the University of California Irvine have a three-part video series that explain the architecture of the devices. Altogether, the videos are about an hour long and — of course — they use the official tools, not IceStorm. But it is still a great time investment if you have an iCE40 board and you want to understand what the chip has under the hood.

The first part is fairly short and talks a lot about applications. There’s also a nod to the hobbyist use of FPGAs. Keep in mind that the iCE40 FPGAs come in different sizes and variants, so don’t get excited when you see them mention a RISC-V — that isn’t going to fit in your iCEStick, that we know of. The iCEstick has a HX-1K onboard, which is the high-performance variant with 1,280 logic elements, as opposed to the low-power (LP) version.

In fact, you might want to watch the video with the datasheets open. The lowest-end UltraPlus device has more logic elements (2,800 vs 1,280) and more RAM (1,104 kbits vs 64 kbit). It also has specialized I2C, SPI, DSP, and PWM hardware onboard. While the HX-1K lacks those extra features, it does allow 98 I/Os maximum compared to the low-end UltraPlus’ 21 I/O. They also have lower maximum propagation delays which means you can usually get them to clock faster than other members of the family.

However, the core fabric is the same: a four-input lookup table (LUT4), a D flip-flop, and some carry logic. More modern FPGAs will often have more inputs to the LUTs to provide denser packing, so be careful comparing one FPGA family’s cell count to another.

Of course, if you are using the iCEstick, you may want to graduate to the more powerful family members and then everything in the videos will apply. They use the UpDuino which is a good upgrade and still very inexpensive. The third video covers the Lattice-specific tools. Be aware that if you want to use the Ultra or UltraPlus devices that Icestorm only supports some of them. If you do use IceStorm, you’ll want to read about the support for newer devices. If you haven’t gotten started with FPGAs yet, why not head over to Hackaday.io and learn more about using the iCE40 in the FPGA bootcamps?


Icestorm Tools Roundup: Open Source FPGA Dev Guide

$
0
0

We like the ICE40 FPGA from Lattice for two reasons: there are cheap development boards like the Icestick available for it and there are open source tools. We’ve based several tutorials on the Icestorm toolchain and it works quite well. However, the open source tools don’t always expose everything that you see from commercial tools. You sometimes have to dig a little to find the right tool or option.

Sometimes that’s a good thing. I don’t need to learn yet another fancy IDE and we have plenty of good simulation tools, so why reinvent the wheel? However, if you are only using the basic workflow of Yosys, Arachne-pnr, icepack, and iceprog, you could be missing out on some of the most interesting features. Let’s take a deeper look.

Yosys Options

Yosys is software that converts your Verilog into a BLIF file which stands for Berkeley Logic Interchange Format. It has an interactive command line, but most people use it with a command string as part of a script. For example:

yosys -p "synth_ice40 -blif demo.blif" demo.v

The synth_ice40 is sort of a script, though, and it does quite a few operations for you. There are other commands you can use, too:

  • check – The check command looks for errors in whatever you have loaded so far.
  • show – Generates a “schematic” using graphviz (see below).
  • write_verilog – You can write out an intermediate Verilog which might be useful to simulate to run down synthesis issues if you have a simulation library for the FPGA primatives.
  • write_spice – You can also write out a Spice net list if you prefer.

Note that at the time I’m writing this, there’s a bug in the documentation page where — starting with attrmvcp — the descriptions are one off. That is, the description for chparm is supposed to be the description for check, for example. Perhaps it has been fixed by now. You might also notice a reference to commands to read VHDL automatically through a translator. Don’t get excited, because this has been removed in recent versions since all of the translators have some issues with certain VHDL. Of course, if it works for you, it is possible to do that conversion before calling yosys, if you like. There’s also a plugin for using vhdl2vl if you are brave. Or just stick with Verilog.

An Example

Just to look at a few of these features, here’s a really simple piece of Verilog that won’t win any prizes:

module test(input clk, input reset, input a, input b, input enable, output reg q);
wire q_intermediate;
assign q_intermediate=a^b;

// enable next line to see an error

// always @(posedge clk) q<=1'b1;
always @(posedge clk)
if (reset)
q<=1'b0;
else
if (enable) q<=q_intermediate;

endmodule

This module XORs the a and b inputs and latches the value on q at the rising clock edge if the input enable is high. Simple.

Instead of giving yosys a command line, just run yosys with no options. You’ll get a prompt. If you try entering the check command, you’ll get a message that you need to run proc first. So try that and then run check. You should see zero problems.

Maybe you’d like to see a problem. Uncomment the line between the assign and the always statement that says:


always @(posedge clk) q<=1'b1;

Now if you load the code, run proc, and then run check, you’ll see that the program knows you have too many things driving q. Be sure to take the line back out.

Once you have good code in again, you can try doing a synth_ice40 followed by a write_verilog command. Here’s the entire list of commands:

read_verilog test.v
proc
check
synth_ice40
write_verilog int.v

Now you have a file that represents the synthesized code. It is fairly long, partly because there are comments to keep track of the source file, but you’ll see FPGA primitives like this:


(* src = "/usr/bin/../share/yosys/ice40/cells_map.v:43" *)
SB_LUT4 #(
.LUT_INIT(4'b0110)
) _2_ (
.I0(a),
.I1(b),
.I2(1'b0),
.I3(1'b0),
.O(q_intermediate)
);
(* src = "test.v:6|/usr/bin/../share/yosys/ice40/cells_map.v:8" *)
SB_DFFESR _3_ (
.C(clk),
.D(q_intermediate),
.E(_0_),
.Q(q),
.R(reset)
);

A LUT is a Look Up Table. Because there are only two inputs used, the initialization for the table is only four bits and you can see that it is the truth table for our XOR gate that drives q_intermediate. THe SB_DFFESR module is a D flipflop, “obviously”.

Somewhat more useful is the show command. There are quite a few options, but for a simple circuit like this, just enter show. Assuming you have the graphics software on your machine you should see something like this:


This is fairly easy to puzzle out, especially if you look at the output Verilog code, too. The topmost LUT is the XOR gate, while the bottom one is an OR gate that feeds the flip flop enable (E). This allows the reset signal to also enable the flip flop.

One other thing you might find interesting. Remember I mentioned that synth_ice40 is a script? Try typing this:

help synth_ice40

You can see what commands execute. You can also use labels to skip some of the processes if you like. There are also many other options you can set.

Timing Analysis

One of the problems with doing any sort of FPGA design is making timing closure. In the above example, for instance, you have to assume the a and b inputs are synchronized appropriately with the clock. If they were not, we’d need some more flip flops. However, imagine you had three of these circuits. Let’s assume one circuit processes A0 and B0 to generate Q0 and a second one generates Q1 from A1 and B1. Then the third gate has Q0 connected to A and Q1 connected to B to generate the final Q. Something like this:


module test_blk(input clk, input reset, input a, input b, input enable, output reg q);
wire q_intermediate;
assign q_intermediate=a^b;

always @(posedge clk)
if (reset)
q<=1'b0;
else
if (enable) q<=q_intermediate;

endmodule

module test(input clk, input reset, input A0, input B0, input A1, input B1, input enable, output q);

wire Q0;
wire Q1;

test_blk block0(clk,reset,A0,B0,enable,Q0);
test_blk block1(clk,reset,A1,B1,enable,Q1);
test_blk block2(clk,reset,Q0,Q1,enable,q);
endmodule

Even though FPGAs are fast, they aren’t infinitely fast. So the amount of time for the change in, say, Q0 to make its way into A could take more time than the clock if the clock were very fast. This would lead to bad operation. So how fast can the clock be?

With this simple design, pretty fast. You can use icetime to find out just how fast. Assuming you are using an hx1k device and you’ve already run yosys and arachne-pnr:

icetime -d hx1k test.asc

You’ll see this output:

// Reading input .asc file..
// Reading 1k chipdb file..
// Creating timing netlist..
// Timing estimate: 2.81 ns (355.34 MHz)

Since I didn’t constrain the design, your number could be slightly different.

If you add the -t option, the tool will show you the chain that is causing the highest delay which is what you’d need to work on if you wanted to increase the clock speed.

PLL Configuration

Speaking of clock speed, the Ice40 FPGA has a nice PLL onboard that can convert the clock input into nearly any frequency you want within certain limits. There are quite a few confusing configuration options, but you can use icepll to help you out. Suppose you want a 100 MHz clock from a 12 MHz input clock. Run this command:

icepll -m -f pll.v -i 12 -o 100

You’ll get a nice report and the pll.v file will look like this:


/**
* PLL configuration
*
* This Verilog module was generated automatically
* using the icepll tool from the IceStorm project.
* Use at your own risk.
*
* Given input frequency:        12.000 MHz
* Requested output frequency:  100.000 MHz
* Achieved output frequency:   100.500 MHz
*/

module pll(
input  clock_in,
output clock_out,
output locked
);

SB_PLL40_CORE #(
.FEEDBACK_PATH("SIMPLE"),
.DIVR(4'b0000),         // DIVR =  0
.DIVF(7'b1000010),      // DIVF = 66
.DIVQ(3'b011),          // DIVQ =  3
.FILTER_RANGE(3'b001)   // FILTER_RANGE = 1
) uut (
.LOCK(locked),
.RESETB(1'b1),
.BYPASS(1'b0),
.REFERENCECLK(clock_in),
.PLLOUTCORE(clock_out)
);

endmodule

Just include it in your project and create the PLL module in your top-level module. For example:


module top(input clk, output led);
wire fastclock, locked;
pll mypll(clk,fastclock,locked);
...
endmodule

Floorplanning

The output from show can be useful, but it doesn’t show you what’s happening at the chip level. One thing you couldn’t do, though, was easily view a floorplan for a design. But now thanks to [knielsen] you can do it in your browser.

A floorplan is like a map showing where on the chip your design resides and the wires that make the connections. This can often show you where you have bottlenecks, for example. You can’t actually make changes with this tool, however. In most tools, you can set constraints to move specific logic blocks around, but we don’t think arachne-pnr supports that today other than with I/O blocks, of course.

An Improved Script

In the past, I’ve used a simple shell script to drive the process. Given all these new tools, I’ve made it a little more complex. You can download the script on GitHub, but here are the highlights:

  • A library path to find modules
  • -noautowire added to the yosys command line. This has the effect of specifying default_nettype none on top of all files which is great for catching misspellings in signal names
  • Environment variables for yosys and arachne-pnr options if you need to pass extras in
  • icetime now generates a timing report (assumes hx1k)
  • Better error checking

You may want to tweak the script to your liking. You can change options in the file, in a .env file in the current directory, in the environment, and from the command line. This lets you configure the options for a folder then just issue the command (nominally ice40flow, but sometimes I alias it to go) and get a complete workflow.

Wrap Up

This is just some of what you can do with these great open source tools. Even tools like icepack and iceprog have interesting options. For example, icepack can set the bit that prevents the FPGA from putting the SPI EEPROM to sleep after configuration so you could use the unused portions in your design. Or if you ever wanted to try the FPGA’s multiple configuration option, ask for help on the icemulti tool.

If a tool works well, it is tempting to not think about it too much. However, these tools change and it is worth looking at what’s available from time to time. There’s even a new place and route tool in the works. It also doesn’t hurt to read the Ice40 datasheet, to learn what capabilities you can possibly use on this hardware.

Programming A RISC-V Softcore With Ada

$
0
0

We were contacted by [morbo] to let us know about a project on the AdaCore blog that concerns programming a PicoRV32 RISC-V softcore with Ada. The softcore itself runs on a Lattice ICE40LP8K-based TinyFPGA-BX FPGA board, which we have covered in the past.

The blog post describes how to use the Community edition of the GNAT Ada compiler to set up the development environment, before implementing a simple example project that controls a strip of WS28212b RGB LED modules. There are two push buttons changing the animation and brightness of the lights.

The source can be found at the author’s Github repository, and contains both the Ada source and the Verilog source for the PicoRV32 softcore. To build the project one needs the GNAT compiler, as well as the open-source iCE40 development tools to compile the softcore.

There is a video demonstrating the finished example project, that we’ve placed below the break.

iCEBreaker, The Open Source Development Board for FPGAs

$
0
0

The Hackaday Superconference is over, which is a shame, but one of the great things about our conference is the people who manage to trek out to Pasadena every year to show us all the cool stuff they’re working on. One of those people was [Piotr Esden-Tempski], founder of 1 Bit Squared, and he brought some goodies that would soon be launched on a few crowdfunding platforms. The coolest of these was the iCEBreaker, an FPGA development kit that makes it easy to learn FPGAs with an Open Source toolchain.

The hardware for the iCEBreaker includes the iCE40UP5K fpga with 5280 logic cells,, 120 kbit of dual-port RAM, 1 Mbit of single-port RAM, and a PLL, two SPIs and two I2Cs. Because the most interesting FPGA applications include sending bits out over pins really, really fast, there’s also 16 Megabytes of SPI Flash that allows you to stream video to a LED matrix. There are enough logic cells here to synthesize a CPU, too, and already the iCEBreaker can handle the PicoRV32, and some of the RISC-V cores. Extensibility is through PMOD connectors, and yes, there’s also an HDMI output for your vintage computing projects.

If you’re looking to get into FPGA development, there’s no better time. Joe Fitz‘s WTFpga workshop from the 2018 Hackaday Superconference has already been converted to this iCEBreaker board, and yes, the seven-segment display and DIP switches are available. Between this and the Open Source iCE toolchain, you’ve got a complete development system that’s ready to go, fun to play with, and extremely capable.

Symbiflow Open Source FPGA toolchain

$
0
0

Anyone who’s ever had the pleasure of programming FPGAs knows that it’s a land of proprietary tools that almost require marriage level commitment to a specific platform to be effective. Symbiflow hopes to solve this by becoming the GCC of FPGAs.

Rather than a tool built around a specific chip or architecture, Symbiflow will provide a more universal interface.  Users can program in Verilog; architecture definitions define how the code will be compiled for the right chip. They are currently targeting the popular Xilinx 7-series, the very affordable iCE40 series from lattice, and the ECP5 FPGAs also from Lattice.

If you’re headed to Hackaday Supercon this year, [Timothy Ansell] will be giving a talk on how Symbiflow is making this process much more approachable and much less proprietary.  Overall we’re very excited about a common interface, especially as the price of FPGAs keep dropping into micro controller territory while also increasing in capability.

(Speaking of Supercon, and maybe this is a spoiler, the badge would not have been possible without Symbiflow, Project Trellis, Yosys, and NextPNR.)

Mithro Runs Down Open Source FPGA Toolchains

$
0
0

Tim [Mithro] Ansell has a lot to tell you about the current state of open FPGA tooling: 115 slides in 25 minutes if you’re counting. His SymbiFlow project aims to be the GCC of FPGA toolchains: cross-platform, multi-platform, completely free, and all-encompassing. That means that it’s an umbrella framework for all of the work that everyone else is doing, from work on synthesis and verification tools, to placing and routing, to vendor-specific chip libraries. His talk catches you up with the state of the art at the end of 2019, and it’s embedded below. Spoiler alert: SymbiFlow has the big Xilinx 7-series FPGAs in its crosshairs, and is closing in. SymbiFlow is that close to getting a networked Linux system on the FPGA fabric in a Xilinx 7 today, completely independent of any vendor tools.

But let’s step back a sec for a little background. When you code for an FPGA, words you type get turned into a bitstream of ones and zeroes that flip perhaps a few million switches inside the chip. Going from a higher-level language to a bitstream is a lot like compiling normal programming languages, except with the twist that the resulting computational logic doesn’t map straight into a machine language, but rather into lower-level physical hardware on the FPGA. So “compilation” for FPGAs involves two steps: synthesis and place-and-routing. Synthesis takes the higher-level language that you write and turns it into a set of networks and timing requirements that represent the same logic, and can work across chip families. Yosys is the open-source synthesis tool of choice here.

Place-and-route then maps the program logic into the individual FPGA’s architecture and feature set, and it’s here that reverse engineering work has and is being done to accommodate more FPGA families. nextpnr takes the program logic and maps it into FPGA gates, and it can’t do this without detailed descriptions of the various chips’ internals. For this, SymbiFlow splits each FPGA chip family into its own bitstream documentation and tooling projects. So far, we’ve got Project IceStorm for the Lattice iCE40 chips, Project Trellis for the Lattice ECP5s that were on the Supercon badge, and Project X-Ray for the Xilinx 7s.

Mithro starts the talk off by mentioning that the goal is to cover all FPGAs with one toolchain. That’s an incredible goal that’s far, far away. But progress is being made ridiculously fast. In early 2018, for instance, only the Lattice iCE40 parts were really well understood and supported. This FPGA was picked because it’s accessible, cheap, and was easy to reverse engineer, but Lattice’s market share is approximately zero. Xilinx and Altera are the Intel and AMD of the FPGA world, and without coverage of their chips, the project can only be said to be just getting off the ground. However, within a year, Dave Shah had essentially completely documented the much more powerful Lattice ECP5, and we were able to bring you the Hackaday Supercon Badge. So much for Lattice.

As alluded to in the opening, the real story here is the tremendous progress made in 2019 on Xilinx parts. As Project X-ray got seriously underway, some parts of nextpnr turned out to be more Lattice-specific than previously thought, and a new place-and-route tool Verilog to Routing developed at the University of Toronto, got pulled into SymbiFlow.

At the same time, some of the synthesis steps in Yosys weren’t taking optimal use of some of the more advanced functionality of the Xilinx parts, like the specialized digital-signal processing blocks (DSP), and made great progress on that front in 2019. (Of course, some of the optimizations of DSP on the Xilinx 7 chips spilled over to the Lattice ECP5s, so everyone wins.)

Which brings us to the punchline. Can SymbiFlow fully replace Xilinx’s proprietary (and unwieldy) Vivado toolchain? No, because the FPGA’s high-speed peripherals don’t play nice with the open place-and-route yet. And while Mithro said in the talk that the Symbiflow consortium were working full-out to get to that point by the end of 2019, we talked to him on Dec 29th, and they were still at it. But if you’re asking us, we’d predict that we will see a full and fully open Xilinx 7 toolchain in 2020. Maybe even this summer? It’s a project that’s near and dear to our hearts, so we’ll keep you in the loop.

But while Mithro, being a Linux/software guy at heart, is focused on getting a fully open toolchain to build up a Linux system, you shouldn’t be discouraged from trying anything else on the Xilinx 7 or Lattice parts right now. Both of these flows are entirely functional for microcontrollery or IoT applications. As long as you don’t need the high-speed memory and Ethernet peripherals, you’re good to go. And if you do need those things, you can synthesize with Yosys and do place-and-route with the closed Vivado tools until SymbiFlow ticks off a couple more boxes. There’s never been a better time than NOW to get started with FPGAs, IMHO.

Viewing all 25 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>