Programming ICE40 FPGA on a board? - Page 1
Forum section: electronics / general

author: thor.lucas
author_rank: Newbie
timestamp: June 09, 2020, 09:03:01 pm
content: Hi,I've been playing around with FPGA lately. I'm trying to stay open source so I'm going with an ICE40 since open source synthesizers exist for this.Sidenote: I think it's pretty BS to charge $3k for a synthesizer. Why not just add a couple bucks to the chip to offset this cost? I truly don't understand how any sort of hobbyist could possibly ever get into using Xilinx FPGAs. You either shell out $3k or use one of the like 3 options available on the free version of Vivado, all of which the devboards for are like $200. And then you're limited to those chips forever cause that's all the programmer will do. Or am I misunderstanding things?Anyway, this seems good and all. But I was wondering how I would do this in more concrete projects. I don't want to buy a $50 tinyFPGA per every little project I do. For Atmel microcontrollers, I use the dev board to... develop, then I just use the ATTiny or ATMega chips in the final project and it's absolutely trivial to program those up, and it costs me less than $1 each.So I was looking at TinyFPGA's github (https://github.com/tinyfpga/TinyFPGA-BX) and it seems you need a lattice FPGA programmer to do this. Makes, sense, but the link is dead. So I do some searching around for "lattice fpga programmer" and I found out that lattice makes something called "IceProg". So I check out their store, and I find this:https://www.latticestore.com/products/tabid/417/categoryid/4/productid/4612/searchid/1/searchvalue/iceprog/default.aspxGreat, a programmer, but again it's $500 and nonstock. Even if I was willing to shell out the money, it's not stocked so I couldn't get it anyway (or do they make it to order?)So all in all it's looking pretty god damn impossible for any sort of hobbyist to get into FPGA. Sure I have a TinyFPGA and can program it up, but I can never use it in any real project because I'm not going to spend $50 per board just for the FPGA. It costs me literally 50¢ per atmel avr with the only initial investment being a $20 arduino that I can use as the ISP. Meanwhile to program an FPGA I'd need a $500 initial investment plus $4 per chip? It's really not looking great...Now it's very possible that I'm just missing something here. Can someone please explain how a hobbyist can get into FPGA at a reasonable price? The immense cost of the synthesizer software plus the ridiculous cost of the programmers just make it seem impossible to do anything with FPGA as a hobbyist other than play around with a dev board.

author: pigrew
author_rank: Frequent Contributor
timestamp: June 09, 2020, 09:34:14 pm
content: I've used the MachXO2 as a hobbyist, and I _think_ it's similar to the Ice40.I use a dead ispLever 4256ZE breakout board as a programmer. Its target CPLD fried. I removed it, and used its header pins for the JTAG connections. The board used to be US$30, but looks like it's been bumped to $105 recently.On their breakout boards, the programmer is actually just a FT2232H. The Lattice software should work fine with one of the generic FT2232H boards, though perhaps you'll need to program an EEPROM for it to indentify itself properly. The boards can also be programmed over SPI or I2C, but that takes a bit more work to setup.For hobbiest level, I really like the MachXO2. It comes in easily solderable packages, can operate with only a 3.3V rail (no need for 1.8V), has integrated flash, and Lattice gives away 1-year licenses for its synthesizer.The higher-end programmers would have IO voltage translation, or perhaps isolation. These wouldn't need for most situations.

author: asmi
author_rank: Super Contributor
timestamp: June 09, 2020, 11:53:05 pm
content: Quote from: thor.lucas on June 09, 2020, 09:03:01 pmWhat are you talking about? Free Vivado license allows using a ton of different FPGAs and SoCs - from smallest $12/piece Spartan-7 all the way to chips which cost several thousands of $. That includes entire Spartan-7 and Artix-7 families. They also provide a ton of useful IPs for free, including things like DDR2/3 memory controllers, Video processing system, a ton of AXI/AXI-Stream infrastructure IPs (like DMA controllers, crossbars, stream conversion, and others). No other FPGA vendor is even close to Xilinx when it comes to free stuff.There are a ton of boards for all budgets (from about $50 to multiple $1000s), and you can always build your own (like I do), for example check a project in my signature.

author: knapik
author_rank: Regular Contributor
timestamp: June 10, 2020, 12:05:26 am
content: A lot of people use the FTDI MPSSE 3.3V cable for programming the FPGAs. There's one with an FT232H and one with an FT2232H (The latter being more expensive). I'm not sure if the FT232H is supported by the project icestorm's iceprog though.

author: Bassman59
author_rank: Super Contributor
timestamp: June 10, 2020, 12:51:14 am
content: Quote from: thor.lucas on June 09, 2020, 09:03:01 pmYou completely misunderstand this.All four of the major FPGA vendors -- Xilinx, Intel, Lattice, MicroSemi -- offer free-as-in-beer tools (synthesis and of course the place-and-route) that work with any device a hobbyist will ever use, and in fact these tools work with most things the average professional uses for products.I don't use dev kits (no reason to use them) and we use the free tools for everything here. That includes the MicroSemi ProASIC-3E 3000, various Artix-7, Spartan 6 and Spartan 3A, and Intel Cyclones. I used a Lattice MachXO2 for a little side project I did.Yes, you have to spring for the programming dongles. And yes, everyone complains that they cost more than they should, and everyone complains that since they all do the same thing, why do I need to have a dozen of the fucking things?QuoteThat's a production programmer, not something you'd use for projects. Their usual HW-USBN-2B (still overpriced at $230, which seems to be more than what I paid for mine) should work. And apparently some people use an FTDI development board for the programmer.QuoteYou're missing a lot

author: ebclr
author_rank: Super Contributor
timestamp: June 10, 2020, 01:47:59 am
content: This may be one interesting and cheap boardhttps://item.taobao.com/item.htm?id=614093598737&sku=1627207:8428757998&sku_id=4542837934324

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 10, 2020, 03:28:45 pm
content: I'm not sure I got what the OP meant in this topic.iCE40 are cheap devices, Lattice provides free tools for all of them (AFAIK - only used the iCE40UP line so far), and you can embed or design your own programming "probe" for pretty cheap. Same applies to most FPGAs at least for entry- to mid-level models. Programming a Xilinx part only requires an FTDI chip, same for Lattice.

author: thor.lucas
author_rank: Newbie
timestamp: June 10, 2020, 09:42:42 pm
content: Quote from: SiliconWizard on June 10, 2020, 03:28:45 pmReally? There's no proprietary programmer I have to buy? Any generic FTDI programmer will work? I guess I haven't seen anyone do this. All the guides online show people using dev boards. I assumed you had to program some sort of bootloader in using some proprietary programmer. Does this mean theoretically I could use an existing ICE40 dev board, which would have the FTDI chip (?) as an ISP to program ICE40 chips?Also I meant that the TinyFPGA BX is an expensive device. Of course the ICE40 chips itself are cheap, but any dev board is going to be way over budget for use in a project.Quote from: Bassman59 on June 10, 2020, 12:51:14 amSo how do you test your ideas beforehand? I don't really have the balls or the patience to have a PCB manufactured before I'm sure what I'm doing is going to work.Quote from: Bassman59 on June 10, 2020, 12:51:14 amRight, this is I guess what I'm most annoyed by. Programming an atmel chip only costs me a $20 arduino, which I can use as an ISP. But the Lattice programming cable thing is like $250. Another Xilinx one would be (I assume) the same price, if not more expensive. So there's no cheaper way?Quote from: Bassman59 on June 10, 2020, 12:51:14 amHm, how? That seems like it would be the cheapest solution, but I can't seem to find anything online about it.Quote from: pigrew on June 09, 2020, 09:34:14 pmThis would be very interesting if I could find more information on it. I wonder if I could use the TinyFPGA to do the programming, then?

author: jaromir
author_rank: Unknown
timestamp: June 10, 2020, 11:08:31 pm
content: Quote from: thor.lucas on June 10, 2020, 09:42:42 pmFor ICE40 device I used (LP384) there was no FPGA programming part. The FPGA loads its configuration from an external ordinary SPI FLASH. I could use any of many solutions to program the bitstream (binary file generated by ICEstorm, I vaguely remember using ICEcube2 from Lattice too) into the FLASH, but for easy workflow I opted to massage myarduino PIC programmerto support FLASH memories. It was something like half an hour of work, later I made variant with STM32 Nucleo board acting as programming hardware. This modification was quick hack for my personal need and isn't released yet.FLASH loading can be done in "on-board-programming" way, provided all SPI signals and CRESET is brought to programming header. Programmer has to assert CRESET pin (so that FPGA doesn't touch SPI FLASH and wait for reconfiguration), perform FLASH programming and then release CRESET pin, so that new configuration is loaded into FPGA. When programmer is disconnected, FPGA loads configuration automatically after POR.I've heard of somebody using one of those cheap AVR ISP programmers (3USD delivered, from asian vendors) with alternative firmware for SPI FLASH programming. No other information available, but I believe it's perfectly possible, too.You could use one of the CH341 programmers to load bitstream into SPI FLASH, but swapping chips manually is PITA.TLDR: For ICE40 one can use ICEstorm and cheap arduino as free and open source toolchain, with total cost 2USD. Using ready-to-go devboard is more convenient, though.

author: asmi
author_rank: Super Contributor
timestamp: June 11, 2020, 03:32:42 am
content: Quote from: thor.lucas on June 10, 2020, 09:42:42 pmDigilent sells programming cables for all Xilinx devices for $59, which is still much more than what they should cost, but at least it's a one-time expense. Those who aren't concerned about IP theft and stuff can buy clones of Xilinx programmer on aliexpress for few bucks, though I heard conflicting info on their functioning.But that stuff is required if you need/want full debug experience (like live debugging, using integrated logic analyzer, ADC dashboard, transceivers status, and other stuff like that), if you only want to "program" (the right term is "configure") FPGA, there are several documented ways of achieving this - including using MCU and serial protocol, or JTAG, or simply have FPGA boot from QSPI flash and provide a way to program that flash.

author: Bassman59
author_rank: Super Contributor
timestamp: June 11, 2020, 06:16:26 am
content: Quote from: thor.lucas on June 10, 2020, 09:42:42 pmTheFT2232H Mini Module works with Lattice Diamond.QuoteWell, let's just say I've been doing this professionally for a looooong time.And with the kind of products we design, there's no point to "testing ideas beforehand" on an eval board. Not when the products have multiple high-speed LVDS DDR serial ADCs for sensor-output digitizing, a sequencer/controller for the sensor, multiple slower SPI ADCs for housekeeping, a gigabit communications channel implementing a custom protocol over fiber, a command parser, a system initializer module, a side-band serial (UART) interface, on-board non-volatile parameter storage, and etc etc. If you have to design a board (or boards) to glue onto an eval kit, well, you might as well just design the whole damn board that goes into the product.I spend a lot of time simulating the design, which means finding or writing models of the various peripherals. It means testing and functional verification of all of the low-level modules. It means scratching out timing diagrams and sequences on quadrille paper before even thinking about writing VHDL, and certainly before you synthesize and place and route. When I do get to the fitter tools, most of the time is spent closing timing. Sometimes that's easy. Sometimes it's not, so you spend time pipelining and whatnot so you meet timing, and since adding pipeline stages changes the design, you have to go back and re-verify the code to make sure you account for the latency.It's called engineering.Before we have first-article boards sent out for fab, there's enough of the FPGA design complete to say that our pinout choices will work. This means understanding the chip architecture so you can tell the layout person, "These pins can't change because they're clocks, these pins have to be on a 3.3 V bank, these pins are LVDS so they have to be on the 2.5 V bank, these pins connect to the gigabit transceiver so they can't change, these pins are for the memory interface and can't change." And when layout makes the pinout choices, those get put right into the design and checked by running the FPGA fitter tools with them.So when we get first-article boards back from assembly, a lot of the design already works. A lot of what doesn't work comes from misunderstanding the data sheet for some other part. (You've read data sheets, right? So you know that they are a fountain of correctness and completeness!) Sometimes those other parts simply don't work as advertised. I spent way too much time trying to figure out why an ADC, with the simplest of interfaces, was giving us nonsensical noise histograms. I tried all manner of control timing changes to get it to work properly, and it turns out that the ADC quantizer is broken. Well, it meets the published spec, which means the 16-bit converter is really only good for 12 bits over the full temperature range.I'm a believer in in-circuit debug tools like ChipScope, but not as a substitute for simulation and verification prior to synthesis. You want to start synthesis with the idea that your design is correct. I know there are a lot of burn-and-crash guys who pooh-pooh simulation, but when the designs get large, you end up wasting a lot of time analyzing in-system. This is exacerbated by long tool run-times. But! ChipScope is great for telling you that the peripheral connected to the FPGA doesn't behave the way you think it should. When that happens I update my models, re-simulate, then re-spin with the FPGA tools. And then you realize, like with the ADC above, that the part doesn't work ...Anyway, all of the above is the difference between the hobbyist and the professional. And we like to say, "If it was easy, everybody would be doing it."good luck.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 11, 2020, 02:40:29 pm
content: Yes. You can use FTDI chips for programming at least Xilinx parts and Lattice parts. Since this is just JTAG access and off-the-shelf parts can be used, I don't think you're even infringing on anything. You need to configure the FTDI EEPROM right in order to setup the channels correctly for JTAG access, but (at least for Lattice) I don't think you even need to put in any Lattice-specific information (TBC).As for Xilinx, same, except even OpenOCD supports many Xilinx FPGAs, so all you need really is ANY cheap JTAG probe supported by OpenOCD. Digilent sells HS2/HS3 probes which are just based on an FTDI chip as well. There's nothing more in them than in most cheap JTAG adapters or modules based on FTDI chips, even a breakout board or embedding the chip directly on your own board will work.Regarding specifically the iCE40 series, at least for the UP versions, you can also program them through SPI. Take a look at the Upduino 2 project, which just embeds an FTDI chip on board just for that as well. You can absolutely use Lattice Radiant with that.https://github.com/tinyvision-ai-inc/UPduino-v2.1

author: Cerebus
author_rank: Super Contributor
timestamp: June 11, 2020, 10:02:18 pm
content: Quote from: thor.lucas on June 10, 2020, 09:42:42 pmI really can't think of any way of putting this without sounding harsh.Have you considered bothering to read Lattice's ICE40 documentation? i.e.iCE40 Programming and Configuration.Quote from: iCE40 Programming and Configuration, page 1, paragraph 1If you had, you'd know that all that is needed to program ICE40 parts is SPI - either using the FPGA in master mode and loading the bitstream in from industry standard SPI EEPROMs, or in slave mode over SPI from a microcontroller or an in circuit programmer (slave mode is necessary if you're using the onboard flash in some of the newer ICE40 parts). How you get from bitstream file to the chip is up to you; use an expensive programmer, use a cheap clone programmer, use a cheap SPI EEPROM programmer (the one I use is a $5 Chinese throwaway), heck, you could do it from an Arduino if you really wanted to.Seriously, if you can't be bothered to read the documentation how do you expect to getanyFPGA part to do anything for you? There's a ton of things you have to get right to use one of these parts and you won't manage to do itwithout reading the documentation.Sorry to sound ratty, but your question could have been at least partially answered by actually going to Lattice's site and getting the information from the horse's mouth by reading the documentation for the product you want to use.

author: Bassman59
author_rank: Super Contributor
timestamp: June 12, 2020, 03:47:08 am
content: Quote from: Cerebus on June 11, 2020, 10:02:18 pmThis also answers the question of "how do you test your ideas beforehand [without using an evaluation kit]?"We read the documentation and we understand what the various FPGA families offer, so we choose a device that meets our needs. It's really not rocket surgery.

author: thor.lucas
author_rank: Newbie
timestamp: June 12, 2020, 05:07:09 am
content: Quote from: Cerebus on June 11, 2020, 10:02:18 pmI did, actually. It's one thing to read documentation on a topic I know a lot about (programming, etc). Reading docs on something I'm a novice at is more complicated. I'm smart enough to go to one of the top universities in this country, but I can't pretend to be smart enough to understand things like this without some help from experts.Quote from: Bassman59 on June 12, 2020, 03:47:08 amIt may not be rocket surgery for you as a professional. I can go hours programming without needing to test and being confident all unit tests will pass when I finish. I am not at all confident in my EE skills yet, certainly not enough to gamble money away by ordering a PCB before I'm positive it does what I want it to.Arduino docs, for example, are absolutely idiot proof and are good for beginners like me. The iCE40 technical documentation was written for professionals, not hobbyists, and a lot of this goes over my head.Additionally, it's not like it's something I can sit down and play experiment for a while until I get it. If there were through hole 2.54mm pin pitch iCE40s then sure, I could bread board it and run it on a slow clock. But these chips are BGA. I have to order a PCB, reflow it, and then find out what I thought was my understanding of the documentation was actually incorrect. Then I have to question whether or not it was something wrong in the programming, or in the layout of the board? Or maybe it was a timing thing? Or maybe it's something I don't even know about?Getting out and diving head first into something is always a great way to learn. It's not a big deal in programming where mistakes are free, or in art where mistakes are subjective. But false confidence and "playing professional" can cost me real money, and iteration is slow as I have to wait for chinese manufacturing and shipping.That being said, thank you all for your suggestions. Your help combined with the documentation should get me a little closer to figuring this out, so thanks. From what I gather, the Lattice software just spits out raw data that can be loaded into any external EEPROM / Flash and it will just work with the proper pin configuration? So really, it's a question of how to program the EEPROM or flash memory (for which there is a lot more beginner info on online), right?

author: Cerebus
author_rank: Super Contributor
timestamp: June 12, 2020, 02:02:46 pm
content: I think you might be trying to run before you can walk. If you're at the point where you can't garner from Lattice's documentation that this part needs to be fed its programming over an SPI interface then I don't think you're ready to start designing these parts into your own projects, not as raw parts anyway. Again, I don't want to be harsh, but I don't think one has to be a hardened professional (I'm not, I'm a self-educated code monkey that didn't go to a top university) to pick up what's needed from:Quote from: iCE40 Programming and Configuration, page 1, para 3If you don't "get it" from that it's an indication that you're so unfamiliar with the territory that designing in a raw part is beyond youat the moment.As you say, there are so many variables at play that you don't have a hope in hell of debugging why your raw part isn't working. If I were you I'd stick with dev boards for the time being and progress to designing in raw parts once you've got some more experience and accumulated some more knowledge. Then when you hit the inevitable snags you've at least got a known working FPGA subsystem.The iCE40 series are great parts with a niche of "I want an FPGA here, but i don't want a monster", also it has, as you've noted, an open tool chain. Lattice also have the MACHXO2 series which is an even more beginner friendly part, although you lose access to any idea of using an open tool chain. Lattice sell their own breakout board for the MACHXO2 (MACHXO2 7000HE Breakout Board $89 from Mouser) which has the most minimal extras necessary to make the part function and comes with a USB connected programmer on-board. All the device pins are broken out to individual connections so you can get as close to using a raw part as you like while still having the comforts of having the FPGA's supply, decoupling and programming taken care of for you and some LEDs you can use to "get to blinky" and use as status/debugging flags.As far as the iCE40 range is concerned, it's not just in BGA packaging, it's also in QFP and QFN packages and if you want to breadboard a raw device it's easy enough to mount one of these on an adapter board that can be had for a couple of dollars from the usual sources (i.e. some Chinese chappie or chapess on eBay).Whatever you do, you're not going to get there without reading hundreds, perhaps thousands, of pages of documentation and persevering until you understand it, possibly with supporting help from textbooks; it's just part of the territory.

author: asmi
author_rank: Super Contributor
timestamp: June 12, 2020, 02:25:02 pm
content: For absolute beginners in FPGA field I highly recommend Nandland's Go board:https://www.nandland.com/goboard/introduction.htmlIt's quite affordable, and the author provides great tutorials to get you started with FPGA, starting from the very basics. I'm not affiliated with that company, nor do I own this board, but I love his videos on YouTube explaining all kinds of things pertinent to FPGAs.

author: Dmeads
author_rank: Regular Contributor
timestamp: June 13, 2020, 04:49:09 am
content: Okay firstQuoteThe ICE40 can definatley be programmed using the FT232H. An open source board called the Upduino uses that chip to program the flash or the actual ICE40 FPGA (the FPGA can be itself flashed, you just need to switch some jumpers on the board). All the schematics are open source and actually really easy to understand.https://github.com/tinyvision-ai-inc/UPduino-v2.1My advice would be to take the schematics and make your own programmer using the FT232H. Then you can put your FPGA on whatever PCB you want (saldy not through hole), and as long as you have external access to the programming pins, you would be golden.Yes, a custom programmer would need a custom PCB, but the programming side of the Upduino doesnt have too many parts and you can order PCBs from JLC PCB for 2 bucks. I bet you could make a custom programmer for the ICE40 based of FT232H for under 10 bucksI was thinking about doing this a little while ago actually and I have a bunch of my own schematics and footprints and stuff. if you decide to go this route send me a message and I can help you out.