Sunday, September 29, 2013

BladeRF-python problem "ValueError: No backend available" solved and... python has no problems with bladeRF in USB3

Summary

I want to access the bladeRF-board from a Python-program. The simple program below returns an error. By changing the driver from libusbk to libusb-win32 I solved the problem and now I can also access the bladeRF-board from python using an USB3-port! However, the program bladeRF-cli still cannot access the bladeRF-board when plugged in an USB3-port.

Warning: somehow I screw up the layout, I did copy/paste from Word. I have to find out a better way.... Sorry

Running a simple python-program

The following simple python-program:


import usb.backend
import usb.legacy
import usb.core
import usb.util
import usb.control

# find our device
dev = usb.core.find(idVendor=0x1D50, idProduct=0x6066)

# was it found?
if dev is None:
    raise ValueError('Device not found')
else:
    print ('Device found')

    print 'len =', dev.bLength
    print 'bNumConfigurations =', dev.bNumConfigurations
    print 'bDeviceClass =', dev.bDeviceClass
    num = dev.idVendor
    num = "%#x"%(num)
    print 'idVendor = ', num
    #print 'idVendor = ', dev.idVendor
    num = dev.idProduct
    num = "%#x"%(num)
    print 'idProduct = ', num
    #print 'idProduct = ', dev.idProduct
    print 'bcdUSB = ', dev.bcdUSB
    print 'bcdDevice = ', dev.bcdDevice
    print 'iManufacturer = ', dev.iManufacturer
   
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
#dev.set_configuration(0)


Output:


Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>

Traceback (most recent call last):
  File "C:\Users\lonneke\python\bladeRF01.py", line 9, in 
    dev = usb.core.find(idVendor=0x1D50, idProduct=0x6066)
  File "C:\Python27\lib\site-packages\usb\core.py", line 846, in find
    raise ValueError('No backend available')
ValueError: No backend available
>>> 

Trying to solve the problem with environment-variables


Changes to the environment-variables PATH and PYTHONPATH did not solve this problem.

Research on the Internet:


PyUSB should run on any platform with Python >= 2.4, ctypes and at least one of the supported builtin backends.

Do I have ctypes?
Yes: I found a directory C:\Python27\Lib\ctypes


I am using Python 2.6.5, libusb-win32-device.bin-0.1.12.1 and pyusb-1.0.0-a0 on a windows XP system and kept receiving ValueError: No backend available.
Since there wasn't any real help on the web for this problem I spent a lot of time finding that ctypes util.py uses the Path variable to find the library file. My path did not includewindows\system32 and PYUSB didn't find the library. I updated the path variable and now the USB is working.

NOTE: I use libusbk, NOT libusb-win32!!

Here is the libusb wiki:


USB 3.0 support

libusb 1.0 supports USB 3.0 controllers and devices on Windows, from 1.0.9 release onwards. Because of the large number of USB 3.0 controllers, the lack of official USB 3.0 support from Microsoft in Windows 7 and earlier as well as limited testing, be mindful that USB 3.0 support should be considered experimental. Also, if you are using a NEC/Renesas USB 3.0 controller, such as the fairly widespread uPD720200/uPD720200A, you please make sure that your controller drivers are ​version 2.1.16.0 or later. Older versions of the drivers have a bug that prevents access to USB devices when using libusb.

Install a different driver, replace libusbk by libusb-win32


Use zadig.exe to install a different driver, libusb-win32:








Now my bladeRF is a libusb-win32-device

Try bladeRF-cli

What about bladeRF-cli???
Microsoft Windows [versie 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. Alle rechten voorbehouden. 

C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -p 

Backend: libusb 
Serial: b436de8c8212b9aeaaeba852246866e7 
USB Bus: 2 
USB Address: 3 
C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -l hostedx115.rbf 
[INFO] Using libusb version 1.0.16.10774 
[INFO] Found a bladeRF 
[INFO] Claimed all inferfaces successfully 
[INFO] Change to alternate interface 2 
[INFO] Change to alternate interface 2 
Loading fpga... 
[INFO] Change to alternate interface 0 
[INFO] Change to alternate interface 1 
[INFO] Setting integer sample rate: 1000000 
[INFO] Found r value of: 4 
[INFO] MSx a + b/c: 316 + 4/5 
[INFO] MSx a + b/c: 316 + 4/5 
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5) 
[INFO] Calculated samplerate: 1000000 + 0/1 
[INFO] Set actual integer sample rate: 1000000 
[INFO] Setting integer sample rate: 1000000 
[INFO] Found r value of: 4 
[INFO] MSx a + b/c: 316 + 4/5 
[INFO] MSx a + b/c: 316 + 4/5 
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5) 
[INFO] Calculated samplerate: 1000000 + 0/1 
[INFO] Set actual integer sample rate: 1000000 
Done. 

C:\bladeRF-master\host\build\output\Debug> 
And all LEDs are blinking!!
 Try the python-program Now try the same python-program as above:
 

And the output is: 

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 
Type "copyright", "credits" or "license()" for more information. 
>>> ================================ RESTART ================================ 
>>> 
Device found 
len = 18 
bNumConfigurations = 1 
bDeviceClass = 0 
idVendor = 0x1d50 
idProduct = 0x6066 
bcdUSB = 528 
bcdDevice = 0 
iManufacturer = 1 
>>> 

Now try USB3 instead of USB2 with bladeRF-cli

But what about plug bladeRF in an USB3-port with this driver?
BladeRF in USB2-port:


Microsoft Windows [versie 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle rechten voorbehouden.
C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -l hostedx115.rbf
[INFO] Using libusb version 1.0.16.10774
[INFO] Found a bladeRF
[INFO] Claimed all inferfaces successfully
[INFO] Change to alternate interface 2
[INFO] Change to alternate interface 2
Loading fpga...
[INFO] Change to alternate interface 0
[INFO] Change to alternate interface 1
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
Done.
C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -p
Backend:        libusb
Serial:         b436de8c8212b9aeaaeba852246866e7
USB Bus:        2
USB Address:    3

Now unplug and plug in USB3-port:


C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -l hostedx115.rbf
[INFO] Using libusb version 1.0.16.10774
[ERROR] No devices available on the libusb backend.
Failed to open device (NULL): No devices available
Could not open device

bladeRF-cli cannot handle the USB3-port on my laptop.
Unplug and replug in USB2-port:


C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -l hostedx115.rbf
[INFO] Using libusb version 1.0.16.10774
[INFO] Found a bladeRF
[INFO] Claimed all inferfaces successfully
[INFO] Change to alternate interface 2
[INFO] Change to alternate interface 2
Loading fpga...
[INFO] Change to alternate interface 0
[INFO] Change to alternate interface 1
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
Done.

C:\bladeRF-master\host\build\output\Debug>

Now try USB3 instead of USB2 with bladeRF-cli

And what about python?
First bladeRF in USB2-port:
Run python-program. 
Output:
>>>
Device found
len = 18
bNumConfigurations = 1
bDeviceClass = 0
idVendor =  0x1d50
idProduct =  0x6066
bcdUSB =  528
bcdDevice =  0
iManufacturer =  1
Now unplug and put in USB3-slot:
>>> ================================ RESTART ================================
>>>
Device found
len = 18
bNumConfigurations = 1
bDeviceClass = 0
idVendor =  0x1d50
idProduct =  0x6066
bcdUSB =  768
bcdDevice =  0
iManufacturer =  1
>>> 

Conclusion

YES!!
Python has no problems with USB3 on my laptop!!
The program bladeRF-cli cannot access the bladeRF-board from USB3, so I cannot flash the
FPGA. I should be able to do that from python in this situation. But how?
Anyway, with bladeRF plugged in an USB2-port I can solve this problem for the moment.
December 2012 in Spain, Santiago.
View on the world from within our caravan.
This weather is perfect for programming but
not so pleasant for a long walk with our dog...


Friday, September 27, 2013

At last: my bladeRF is up and running on my laptop in Windows 7

Finally, I succeeded in getting my bladeRF into life! It was alive a long time ago, i.e. it showed a green LED when powered up by USB. It did not mind USB2 of USB3, the LED was on.

But seen from the laptop there was not much life.

At nuand.com there was new software. First there was a https://github.com/nuand/bladerf/wiki with some info to get the beast alive in Windows. And now there is new software at github. Look for the 'host' directory (https://github.com/Nuand/bladeRF/tree/master/host).

I used cmake to make a project-file for Visual Studio. In Visual Studio I found a button 'build all'. And that was about it. Soo simple!!

In the meantime my bladeRF thought it was a 'West-Bridge'. I solved that problem using the recover-function of bladeRF-cli:

I downloaded the latest 1.2 FX3 image and renamed it to latest.img

C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -i
[INFO] Using libusb version 1.0.16.10774
[WARNING] Found FX3 bootloader device libusb:device=2:7, could be bladeRF.
[WARNING] Use "recover libusb:device=2:7 <FX3 firmware>" to boot bladeRF.
[ERROR] No devices available on the libusb backend.
Failed to open device (NULL): No devices available
Could not open device
bladeRF> recover libusb:device=2:7 latest.img
[INFO] Device: 2:7
[INFO] Attempting load with file latest.img
[INFO] open firmware image latest.img for RAM upload
[INFO] normal FW binary executable image with checksum
[INFO] FX3 bootloader version: 0x000000A9
[INFO] writing image...
[INFO] transfer execution to Program Entry at 0x40013818
Loaded! An open is now required
bladeRF> open
[INFO] Using libusb version 1.0.16.10774
[INFO] Found a bladeRF
[INFO] Claimed all inferfaces successfully
[INFO] Change to alternate interface 2
[INFO] Change to alternate interface 2
bladeRF> exit

At this point you have to remove power and reapply power again. So, unplug and plug in again.

C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -p

    Backend:        libusb
    Serial:         b436de8c8212b9aeaaeba852246866e7
    USB Bus:        2
    USB Address:    7

I did not know which FPGA-file to take. I simply downloaded the latest one. 

C:\bladeRF-master\host\build\output\Debug>bladeRF-cli -l hostedx115.rbf
[INFO] Using libusb version 1.0.16.10774
[INFO] Found a bladeRF
[INFO] Claimed all inferfaces successfully
[INFO] Change to alternate interface 2
[INFO] Change to alternate interface 2
Loading fpga...
[INFO] Change to alternate interface 0
[INFO] Change to alternate interface 1
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
[INFO] Setting integer sample rate: 1000000
[INFO] Found r value of: 4
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx a + b/c: 316 + 4/5
[INFO] MSx P1: 0x00009c66 (40038) P2: 0x00000002 (2) P3: 0x00000005 (5)
[INFO] Calculated samplerate: 1000000 + 0/1
[INFO] Set actual integer sample rate: 1000000
Done.

C:\bladeRF-master\host\build\output\Debug>


Some issues

There is a problem with USB3. My bladeRF does not function in the USB3 slot. However in the USB2 slot it is OK. I have a Renesas Electronics USB 3.0 host controller and hub. I'll send nuand an email about this issue. It was mentioned by them as a problem.

I had a Python-program that could 'see' the bladeRF. Now it barks that it cannot find the backend. I have to solve that problem.

I still have a problem with GNUradio in Windows. The waterfall-display is frozen. It is a problem with openGL I think.

I want to use my bladeRF to decode GPS-signals (please don't tell me there are cheaper solutions with SIRF III chips etc. I know!). So I need to connect a GPS-antenna. I have one, an active antenne. Active means that I have to become active to build something to feed the antenna with DC over the same line that carries the sub-micro-volts of GNSS-info. It is called phantom-supply.

I need a protective case to protect the bladeRF to the real world of metal things on my desk. Elektor sells a project case, that might be a solution.

Future steps

I want a program written in Python to access the bladeRF. So, I will have to write an FX3-program too and I will have to build some VHDL-code. In the past I did some experiments with a java-program to access an SDR-board. I'll dig up that attempts and build upon that.


This picture was taken in March this year in
Castrojeriz, Spain while we were on vacation.

I love cats. My wife loves cats. And our dog loves
cats too, but in a different manner...



Wednesday, September 11, 2013

bladeRF, too many options for building the software?

To control the bladeRF-board you have to deal with two  areas:
·         Outside of the bladeRF-board is a system with Windows or linux
·         Inside the bladeRF-board there are two sub-systems:
o   The FX3 Cypress USB subsystem to be programmed in C
there is a non-volatile flash-memory for an initial program
o   The FPGA subsystem to be programmed in VHDL or Verilog
the FPGA is empty at startup, so has to be loaded to perform its virtual hardware function

To use the bladeRF you have to boot the whole system:
1.       The outside system: a laptop, a PC or perhaps a Raspberry Pi connected by USB3 to the bladeRF
2.       The bladeRF has a flash memory with the software for the FX3 USB subsystem
3.       The bladeRF gets a new FX3 program
4.       The bladeRF gets a fresh FPGA image
5.       From now on the bladeRF is able to communicate with the controlling program: bladerf.cli
the bladeRF command line interpreter

·         The bladeRF-board has a JTAG-interface-connector. So it is possible to program the FPGA more or less independent form the remaining hardware.
·         With a suitable program in the FX3-USB-Cypres-chip, the programming of the FPGA can be done without the JTAG-interface, directly from the FX3-chip.
·         On the outside of the board is the bladeRF.cli. This program takes care of loading the FX3-program and the program for the FPGA.

‘Everybody’ seems to use linux for the outside system. So, may be it is better for me to follow the crowd if I want support and results.

To connect the bladeRF to a Windows system there are in fact two possibilities:
1.       Use the Cypress FX3 system with the wizard that generates the INF-file. From then on you can use the FX3-Cypres diagnostic tools to load programs
2.       Use the libusb-system. There seem to be a few flavors of that. Anyway version 0.1 or 1.0. The Zadig software seems to be a keystone for success.

Whether linux or Windows the bladeRF-board can be controlled by a program written in java, python or C. The bladeRF.cli is written in C.

There is also gnu radio, either in Windows or in linux. There is a module, OsmoSDR, that can be used to connect a bladeRF-board.

The above ramblings are sort of start-point-issues.

Now about my dream, my ultimate goal, my ultimate process:

I want to understand GNSS (Global Navigation Satellite Systems) by building a GPS-receiver. Perhaps also a GPS-simulator or a GPS-spoofer. In the past I did some experiments, programming in java, with a file with a few minutes GPS-signal from a wideband receiver. I built a function to read the samples. I built a correlator and could ‘see’ the satellites. I built a phase-locked-loop and got stuck in this very PLL. I did not manage to get the loop stable, but did  manage to recover some almanac-data.

For me, it is not the end-result that counts, but the process itself. By doing, experimenting, programming, testing, debugging and reading I get a deep understanding of GNSS’s. Furthermore a system containing an RF-subsystem, an FPGA and an FX3—USB-system controlled by a program on a laptop is really fascinating. A high level language like python, the C-program in the FX3-chip and VHDL on an FPGA. This is a piece of hardware that should be able to do anything you can imagine. Cognitive radio for example. Combined with an inertial system and Kalman filtering one can do miracles with GNSS. The boys and girls of Pentex have the real stuff! But the bladeRF-board is such a marvelous piece of hardware!

I am very confused which route to take:
·         I have a laptop, an old but usable one, I could replace Windows and put genuine Ubuntu on it.
·         I might try to solve the  Windows gnuradio opengl problem and go for the gnuradio solution
·         I might stubbornly stay with Windows and python
·         I might try to go on with Ubuntu in VMware under Windows 7 professional (64 bit)


So far I tried almost everything a little bit, but I don’t yet know which route to take!


a painting, a reproduction, whatever?
This beautiful picture we found in VilaCha, Portugal.