Showing posts with label icebreaker. Show all posts
Showing posts with label icebreaker. Show all posts

Sunday, August 9, 2020

Sigrok on WSL for iua: ice40 USB Analyzer

In my previous post on the iCEBreaker Bitsy FPGA - early adopter version, I mentioned the interesting iua: ice40 USB Analyzer project that I learned about on the iCEBreaker discord channel in the context of troubleshooting the odd problem I was seeing on my "Power Share" USB3.0 port.

There's minimal documentation on Getting Started, so here I am creating my notes.

The iua is meant for the iCEBreaker, not the Bitsy (although I wonder if it would still work on the Bisty? another rabbit hole for another day...)

As with all prior posts, I'm a Visual Studio developer at the day job, and continue that with my FPGA learning on the weekends... thus I use Windows, WSL, and Visual Studio here.


cd /mnt/c/workspace/
git clone https://github.com/smunaut/iua.git
cd iua/hdl
make

As reminder, if you have a VM running, make sure you are not having problems with a prompt awaiting device connection:

Also, even if you've used iceprog before and it decides to not find the icEBreaker today, check the drivers with Zadig. Windows seems to like to replace the drivers during updates. The iCEBreaker needs the libusbK drivers.

Unlike the Bitsy that needs to have bootloader boot set by holding the button at power-on time for dfu-util, the iCEBreaker does NOT need that when using iceprog

As there's no native USB support in my WSL, I use the DOS exe to send the binary to the device either from DOS:

C:\workspace\ulx3s-toolchain\bin\iceprog.exe 

or from WSL:

/mnt/c/workspace/ulx3s-toolchain/bin/iceprog.exe iua_icebreaker_top.bin
When successful, there should be output that looks something like this:

init..
cdone: high
reset..
cdone: low
flash ID: 0xEF 0x40 0x18 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
file size: 104090
erase 64kB sector at 0x000000..
erase 64kB sector at 0x010000..
programming..
reading..
VERIFY OK
cdone: high
Bye.


So that was the easy part. (The easy part is always the thing you already know). The next part - sigrok - is something that I've wanted to learn more about for quite some time. There's another smunaut/libsigrok project needed, which is a modified fork of sigrokproject/libsigrok and needs to be built like this:

git clone git://sigrok.org/libsigrok
cd libsigrok
./autogen.sh
./configure
make


People often ask why I deal with the annoyances of Windows. Well, Linux has plenty as well, imho. I had most of the dependencies already installed, but receieved this error diring make
configure: error: Package requirements (glib-2.0 >= 2.32.0 libftdi1 >= 1.0 libusb-1.0 >= 1.0.16 gio-2.0 >= 2.24.0 libzip >= 0.10) were not met:

No package 'libzip' found


And so what's the first thing to try? Well, sudo apt-get install libzip, right? Nope. :/

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libzip


grumble, grumble, google, grumble....

There's only one reference on the wiki, and it only notes I need libzip >= 0.10. But where to find it? Ah yes, it is just the development code library, not a tool, so we need the -dev suffix:

sudo apt-get install libzip-dev


Ok, now to run ./configure again...

Closer this time; I am still missing some things:

Enabled language bindings:
 - C++............................. no (missing: glibmm, Doxygen)
 - Python.......................... no (missing: C++ bindings, PyGObject, SWIG)
 - Ruby............................ no (missing: C++ bindings, SWIG)
 - Java............................ no (missing: C++ bindings, SWIG, JavaC, JNI headers)

===============================================================================
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
===============================================================================
===                                                                         ===
===         The libsigrok C++ bindings are not being built since you        ===
===             are missing one or more dependencies (see above)!           ===
===                                                                         ===
===      This means you won't be able to compile frontends that require     ===
===  the C++ bindings (such as PulseView)! You also won't be able to build  ===
===     other bindings and frontends using those (such as sigrok-meter)!    ===
===                                                                         ===
===============================================================================
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
===============================================================================


ugh.
gojimmypi:/mnt/c/workspace/libsigrok
$ sudo apt-get install glibmm
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package glibmm
gojimmypi:/mnt/c/workspace/libsigrok
$ sudo apt-get install glibmm-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package glibmm-dev
gojimmypi:/mnt/c/workspace/libsigrok


grumble, grumble, google, grumble....

This one requires a version number in the name. Of course it does. So onward to install: glibmm. I'll grab doxygen too, and then one more ./configure as well:

sudo apt-get install libglibmm-2.4-dev
sudo apt-get install doxygen
./configure


No warnings! Hurray!! So on to a (very long running) make, then:

  
$ make check
make
make  all-am
make  check-TESTS
============================================================================
Testsuite summary for libsigrok 0.6.0
============================================================================
# TOTAL: 0
# PASS:  0
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================


$ sudo make install
 /bin/mkdir -p '/usr/local/lib'
 /bin/bash ./libtool --silent  --mode=install /usr/bin/install -c   libsigrok.la bindings/cxx/libsigrokcxx.la '/usr/local/lib'
libtool: warning: relinking 'bindings/cxx/libsigrokcxx.la'
 /bin/mkdir -p '/usr/local/include/libsigrokcxx'
 /usr/bin/install -c -m 644 bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp '/usr/local/include/libsigrokcxx'
 /bin/mkdir -p '/usr/local/include/libsigrok'
 /usr/bin/install -c -m 644 include/libsigrok/libsigrok.h include/libsigrok/proto.h '/usr/local/include/libsigrok'
 /bin/mkdir -p '/usr/local/share/mime/packages'
 /usr/bin/install -c -m 644 contrib/vnd.sigrok.session.xml '/usr/local/share/mime/packages'
 /bin/mkdir -p '/usr/local/share/icons/hicolor/48x48/mimetypes'
 /usr/bin/install -c -m 644 contrib/libsigrok.png '/usr/local/share/icons/hicolor/48x48/mimetypes'
 /bin/mkdir -p '/usr/local/share/icons/hicolor/scalable/mimetypes'
 /usr/bin/install -c -m 644 contrib/libsigrok.svg '/usr/local/share/icons/hicolor/scalable/mimetypes'
 /bin/mkdir -p '/usr/local/include/libsigrokcxx'
 /usr/bin/install -c -m 644 bindings/cxx/include/libsigrokcxx/enums.hpp '/usr/local/include/libsigrokcxx'
 /bin/mkdir -p '/usr/local/include/libsigrok'
 /usr/bin/install -c -m 644 include/libsigrok/version.h '/usr/local/include/libsigrok'
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 libsigrok.pc bindings/cxx/libsigrokcxx.pc '/usr/local/lib/pkgconfig'  


Next is to install decoder:
git clone https://github.com/sigrokproject/libsigrokdecode.git
cd libsigrokdecode
./autogen.sh
./configure
make
sudo make install


Next is to install Pulseview! (see also build info). Despite having the requirements installed, I also needed:

sudo apt-get install qttools5-dev


  
git clone https://github.com/sigrokproject/pulseview.git
cd pulseview
cmake .
make
sudo make install


Still following along? After all this, it is time to actually run pulseview! Alas on WSL we have an extra challenge: X-Windows. I'm using vcxsrv from the ad-spam-ridden sourceforge. (it is really a shame to see what that site has become).

C:\Program Files\VcXsrv\vcxsrv.exe


See building libsigrok, but use the smunaut/libsigrok

sudo apt-get install git-core gcc make autoconf automake libtool
git clone https://github.com/sigrokproject/libserialport.git  
cd libserialport
./autogen.sh
./configure
make
sudo make install 


git clone https://github.com/smunaut/libsigrok.git smunaut-libsigrok
cd smunaut-libsigrok
./autogen.sh  
./configure
make
sudo make install


See build failure for smunaut/libsigrok #2

If after doing a make clean for pulseview, and an error like this is enountered:
$ make
[  1%] Automatic MOC for target pulseview
[  1%] Built target pulseview_autogen
make[2]: *** No rule to make target 'l10n/de.qm', needed by 'qrc_translations.cpp'.  Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pulseview.dir/all' failed
make[1]: *** [CMakeFiles/pulseview.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2


The problem seems to be that make clean improperly deletes a couple of files:

gojimmypi:/mnt/c/workspace/pulseview
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    l10n/de.ts
        deleted:    l10n/es_MX.ts

no changes added to commit (use "git add" and/or "git commit -a")
gojimmypi:/mnt/c/workspace/pulseview


So simply put them back:

git checkout master
git checkout l10n/de.ts
git checkout l10n/es_MX.ts  


Despite
gojimmypi:/mnt/c/workspace/smunaut-libsigrok
$ ./configure
...
Detected libraries (optional):
 - libserialport >= 0.1.1.......... 0.1.1


I still saw wthis error:
pulseview: error while loading shared libraries: libserialport.so.0: cannot open shared object file: No such file or directory  


sudo apt-get install libserialport-dev 


Saturday, August 8, 2020

iCEBreaker Bitsy FPGA - early adopter version

A couple of weeks ago, I ordered the early adopter iCEBreaker bitsy FPGA board. It arrived promptly just a few days later!


Key details:
  • Use dfu-util to upload binary files to the Bitsy (see Windows binaries)
  • The board needs to be in DFU boot mode to upload FPGA bin file
  • Hold button down when powering on device to enter DFU boot mode
  • Click button while in DFU boot mode to exit boot mode
  • FPGA Toolchain needs to be installed.

Note that I am using WSL on Windows. All the FPGA synthesis stuff happens in WSL. However, there is no native USB support in my WSL 1, so I use the DOS executables (either from WSL or Windows DOS prompt) for the actual device programming. Although I have several blog entries that mention this topic, I have a summary for Programming FPGA Devices from WSL.

For open source toolchain, you can install everything from GitHub, or use Multi-platform nightly builds of open source FPGA tools. I also have a Visual Studio FPGA Extension that will soon build and upload from the comfort of the VS IDE. (currently, the release only does syntax highlighting)

Unlike the similarly named iCEBreaker, this board does NOT use iceprog to upload binaries.
 
If when running dfu-util.exe -l, the device cannot be seen:

dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/


Make sure you are using a known good USB cable. Recall the button needs to be pressed before power is applied. There's apparently an issue with USB3.0 PowerShare ports. Try using a different port, or perhaps a USB hub.

 
If when running dfu-util.exe -l, the device cannot be opened:

Cannot open DFU device 1d50:6146

C:\Users\gojimmypi>C:\Download\dfu-util\dfu-util.exe -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Cannot open DFU device 1d50:6146


This typically means the Windows drivers are not installed. Zadig to the rescue:



If when running dfu-util.exe -l, the device is working properly:

dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [1d50:6146] ver=0004, devnum=12, cfg=1, intf=0, path="1-1.3", alt=1, name="RISC-V firmware", serial="your serial"
Found DFU: [1d50:6146] ver=0004, devnum=12, cfg=1, intf=0, path="1-1.3", alt=0, name="iCE40 bitstream", serial="your serial"

We can proceed to actually programming the FPGA.

From what I can tell, it seems the Bitsy is iCEBreaker compatible:
cd /mnt/c/workspace
git clone https://github.com/icebreaker-fpga/icebreaker-examples.git
cd icebreaker-examples/blink_count_shift
make

To program the Bitsy, as there are multiple, identical DFU numbers, the "alt" needs to be specified:

dfu-util.exe -a 0 -D blink_count_shift.bin

Beyond blinky, a pinout is useful: 

iCEBreaker Bitsy Pinout by 0xdec

There's a main repo: https://github.com/icebreaker-fpga/icebreaker-examples but I learned on the discord channel that the code for the Bitsy has not yet been pushed there.

That repo will likely at some point have all the latest code. For now it is still in esden/icebreaker-examples
git clone https://github.com/esden/icebreaker-examples.git esden-icebreaker-examples  
cd esden-icebreaker-examples
git branch --all
git checkout bitsy
cd blink_count_shift  
make clean
make BOARD=bitsy1  
Note the `make` will be expecting parameters:

$ make
../board.mk:18: *** Please specify BOARD, options are "icebreaker", "bitsy0" or "bitsy1".  Stop.


then upload:
dfu-util.exe -a 0 -D C:\workspace\esden-icebreaker-examples\blink_count_shift\blink_count_shift.bin

Here we should be able to press the Bitsy button to get the green LED to illuminate.

Beyond blinky, I learned there's a DFU UART on FPGA pin 44 (aka IOB_4a, aka P2).

Hookup a USB Serial Port and at DFU boot time at 1000000 baud, a message is displayed:
  
Booting DFU image..
Flash Manufacturer : ef 40 18
Flash Unique ID    : e4 69 98 d2 43 59 15 2f
Command>  

I also learned on discord that USB signals-D/+D are actually 3.3V, even though the supply voltage is 5V

There's this interesting iua: ice40 USB Analyzer that is meant to run on an iCEBreaker FPGA that can apparently be used to "dump all the USB traffic". Note there's an minor problem building, but I have a PR to fix that. (thanks to @tnt on discord for the info). Basically just needed to add a magic parameter --placer sa to run nextpnr like this:

nextpnr-ice40 --placer sa  --up5k --package sg48 --json iua_icebreaker_top.json --pcf ../impl/iua_icebreaker_pins.pcf --asc iua_icebreaker_top.asc --freq 50  

This will happen during make.

Also from @tnt on discord:
There are debug pads on the bity bottom where you can easily solder a header.
set_io -nowarn usb_dp_pad 31
set_io -nowarn usb_dn_pad 34

 Those are the fpga pins where to connect on the icebreaker side.


To be continued in my next post... Sigrok on WSL for iua: ice40 USB Analyzer
 



Saturday, June 6, 2020

Programming FPGA Devices from WSL

Today I received a DM on Twitter asking for help to program an FPGA (specifically the 1bitsquared iCEBreaker) from WSL. I realized that most of the useful information is buried in my long (and admittedly sometimes rambling) prior blogs. So this is a summary for just that topic.

The first thing to do, is plug in your device. In the case of the iCEBreaker, make sure the drivers are set to libusbk using Zadig as noted here:


Note that native USB drivers are not supported in WSL (well, WSL1, anyhow; I've not been able to install WSL2 just yet)

If after changing the drivers the board is *still* not recognized by iceprog, try unplugging, waiting a few seconds and plugging the iCEBreaker back into the USB port. I've also seen mixed results with hubs, so perhaps try connecting directly if it still does not work.

Next, make sure you have the DOS version of the programmer on the Windows filesystem. I have mine in my C:\workspace\ulx3s-toolchain\bin\ directory:



The really crazy thing about WSL, is that not only is the Windows file system available in the /mnt/ directory such as /mnt/c for c:\ ... but Windows executables can be launched from the WSL prompt as well! And of course there's plenty of native USB driver support in Windows.

Here's an example in /mnt/c/users/gojimmypi/source/repos/Verilog12/Verilog12 - a WSL directory which is C:\users\gojimmypi\source\repos\Verilog12\Verilog12 (created by Visual Studio)

Calling the DOS executable to program the iCEBreaker:


That's it!

Links:



Find gojimmypi at gojimmypi.github.io

I'm currently working on my new blog home at  gojimmypi.github.io After implementing a variety of features such as dark mode , syntax hi...