How to make headless program

Discussions related to embedded firmware, driver, and user mode application software development

Moderator: robert.ghilduta

Post Reply
steve_j
Posts: 2
Joined: Mon Jun 22, 2015 1:09 pm

How to make headless program

Post by steve_j » Tue Jun 23, 2015 2:51 pm

Hi there,

I am familiar with the GNU radio environment, but I don't know the steps to produce a simple software which can run 'headless' in the bladerf, so that only 5V power is needed to make it run indefinitely.

Here's the task I want to solve: I need a simple CW signal generator which changes the frequency (800, 900, 1800, 2400, 2600MHz) every 1 second. Can anybody tell me how to do this...?

Thanks for every contribution.
Steve J

jynik
Posts: 455
Joined: Thu Jun 06, 2013 8:15 pm

Re: How to make headless program

Post by jynik » Wed Jun 24, 2015 7:58 am

Hi Steve,

In the background we've been trying to get some content together that we'll try to steadily release and post to a nuand-papers repository. (Once we have a few items in there, we'll make a more public announcement.) As I think it'd be worthwhile to get a paper up there that details the entire process from start to finish, I've registered an issue tracker item for this.

In the meantime, we can try to give you some high-level starting points...

First, you'll need to develop a block in the FPGA to implement your CW generator. Instead of having IQ samples come from the Cypress FX3's GPIF interface (via the fifo reader block), you'll want to supply samples from your custom block.

I would start out by working on and verifying only that, and using the host to load your custom FPGA and configure the device. (The point here is to isolate the scope of changes to a single area.) You can then just use the bladeRF-cli to transmit /dev/zero or something just to get libbladeRF to enable the TX module and let samples start flowing. You should be able to manually retune in the CLI and see your carrier change.

Next, I would look to modify the NIOS II code to configure the device as you need, and to ignore requests coming from the USB interface (if desired). Specifically, you'll need to understand what libbladeRF is doing when you open a device, enable/disable a modules, and configure the sample rate, and bandwidth. I just pushed a commit that adds some debug output for each access to the FPGA. An easy way to understand what's going on in libbladeRF is to enable verbose output in the bladeRF-cli, observe what's being written when you make a change, and then dive into the code. I'd even recommend using GDB to run the CLI, so that you could set breakpoints and use a backtrace to see how a particular line got called.

Currently the NIOS II code builds a subset of the lms.c functionality to support retuning. If you have fixed set of frequencies, you can use the verbose output of libbladeRF to determine the LMS6002 values (see the lms_freq structure in lms.h) computed for each frequency. You could put these into a table of in your modified NIOS II code, and then use the lms_set_precomputed_freq() function that's currently being compiled into the NIOS II code to change the frequency.

You could add a timer to the NIOS system and register an interrupt to set a flag once a second. In the main loop, you could check for that flag and update to the next frequency in your table. Don't call functions that interact with the device from an interrupt.

Currently, we don't have si5338 code being built into the NIOS II code. However, this won't be too bad and I can help make the minor changes needed for this.

You'll need to store the FPGA bitstream in flash, so that it can be loaded when the board is powered on. This is document here on the wiki.

Note that the FX3 firmware is involved in enabling features in the FPGA, which it does via few I/O pins. You can modify the FX3 firmware to set these appropriately at boot, or modify the FPGA to ignore those pins and instead use internal logic. You might want to check how the PCLK from the FX3 is used by the FPGA -- I'm not sure if drives anything other than the GPIF handler, or perhaps other logic. bpadalino might be able to elaborate more on that.

This is a lot of information, and I suspect it'll take some time to get up to speed on the codebase and devices on the board. Let us know if you have further questions, and please do keep us all updated with your progress, if possible.

Cheers,
Jon

steve_j
Posts: 2
Joined: Mon Jun 22, 2015 1:09 pm

Re: How to make headless program

Post by steve_j » Wed Jun 24, 2015 1:09 pm

Dear Jon

Thanks very much indeed for this information, which is really helpful. However, it will take me a while to get familiar with all the aspects and get my task fully running.

I was just thinking if it would be more easier to add a 'host' board in mini format, and I am thinking of the Arduino YUN which has also a small LINUX kernel, and nice interfaces as well. Maybe I would then use this board to make a little display (touchscreen) in order to watch status etc. If haven't lookend into the forum yet - maybe somebody has done this before (like the Raspberry Pi, but a bit more extensive).

I will post any progress here.

Best regards and thanks again
Steve

jynik
Posts: 455
Joined: Thu Jun 06, 2013 8:15 pm

Re: How to make headless program

Post by jynik » Wed Jun 24, 2015 8:34 pm

Hi Steve,

For embedded hosts, I'd recommend using Yocto (manual) to build a barebones linux build. The meta-sdr layer contains support for GNU Radio and the bladeRF. For a decent signal, you'll need a platform that can sustain a sample rate of 2 Msps, so that you can set the LMS6002D's antialiasing filters to 1.5MHz (which roll off into full rejection around 2MHz).

As I get some time, perhaps I'll add a Wiki page on building just a basic barebones images for a few popular platforms, with just some items such as libbladeRF, the bladeRF-cli, and a simple program or two.

When you said CW, did you mean just output a tone (e.g., 1 + 0j)? If so, the libbladeRF_test_scheduled_retune program actually might do exactly what you need, or pretty close to it, out of the box.

With the embedded platforms, you need to be wary of the limits of the platform's processor and interfaces. I'm not familiar with the Arduino platform you mentioned, by my kneejerk reaction is "ehh... that might not have a enough juice." With systems like the Raspberry Pi, you aren't going to be running GNU Radio or doing much in the way of signal processing. (If it gets your i7 toasty, you won't have a good time on a little ARM.) Furthermore, on the RPi, the bandwidth on the USB interface is pretty limited. (I believe it has something to do with there being a shared bus between that and the network interface?)

I have however, used the bladeRF-cli on the Raspberry Pi for modest sample rates. To do this, you'd need to use external power or a powered USB 3.0 hub, since its USB 2.0 port may not supply sufficient power with FPGA running.

As far as capability versus cost, the Wandboard Quad isn't too bad. Using this and the bladeRF, I've run GNU Radio with GQRX on this and was decoding audio at modest sample rates (USB 2.0).

Ideally, I'd get my hands on something with a USB 3.0 interface, such as NVIDIA Jetson TK1 or one of those ODroid platforms.

Someone on these forums mentioned trying the Intel Edison and finding that they weren't getting much in the way of USB throughput, so be aware of that.

In an effort to replicate someone else's experience, I tried a Beaglebone Black at one point. Back then, the musb driver was misbehaving and causing kernel OOPSes, so I didn't really play with that much more.

I just got a Raspberry Pi 2 and am baking a Yocto-based image right now. (Twiddling my thumb waiting for the bcm2835 bootfiles to download... :roll: )
I'll try testing this out with the blade and touch back here by this weekend. I see this blog post covers how to use Yocto to build an image for the Raspberry Pi 2 -- you might want to check that out!

Again... massive response. Hopefully something was useful. :wink:

Cheers,
Jon

jehangir
Posts: 6
Joined: Thu Jun 11, 2015 4:58 am

Re: How to make headless program

Post by jehangir » Fri Jun 26, 2015 3:28 am

Hi Jon,

In my current work I've been asked to get a handle on the bladerf for some upcoming projects, so I've to refresh my NIOS II bearings after working purely hardware, for a long time. Reading this post reminds me of the days when I was working on a NIOS II based MPSOC. If I remember correctly, one had to download the FPGA bitstream (i.e. the hardware) first and then the NIOS executables into the flash. From what I've been reading on the forum, it seems to me that the bladerf .rbf file somehow combines the fpga bitstream and the NIOS .elf, similar to what the xilinx folks do with the microblaze. Am I missing something here? If I'm right, I would like to know how to generate such a .rbf file after I do some modifications to the HW and the Nios II SW.

Thanks.

Jehangir

jynik
Posts: 455
Joined: Thu Jun 06, 2013 8:15 pm

Re: How to make headless program

Post by jynik » Fri Jun 26, 2015 7:36 am

Hi Jehangir,

You're correct that NIOS II executable is rolled up into the RBF.

When I was recently working on the NIOS II code, I would usually just build the NIOS II executable from in the bladeRF/hdl/fpga/ip/altera/nios_system/bladeRF_nios/ directory, and then load and execute over JTAG.

I know there's a program or utility somewhere in the Quartus II 15.0 that one could run after updating the NIOS II executable to bake it into the RBF without doing a full build. Admittedly, I haven't bothered to track down where it is or how to use it.

On my i7 machine, the entire FPGA build takes just 5-10 minutes, so I usually just re-run the build_bladerf.sh script.

Hope that helps,
Jon

jehangir
Posts: 6
Joined: Thu Jun 11, 2015 4:58 am

Re: How to make headless program

Post by jehangir » Fri Jun 26, 2015 10:43 am

Hi Jon,

Thanks for this info. In quartus the rbf file generation utility is under file/covert programming files... and then one can choose .rbf from the "programming file type" drop down.
It takes .sof as input file, I'm not sure if one can provide a combination of .sof and .elf as input to convert into .rbf. Any idea?

Cheers

Jehangir

jynik
Posts: 455
Joined: Thu Jun 06, 2013 8:15 pm

Re: How to make headless program

Post by jynik » Fri Jun 26, 2015 11:16 am

Hi Jehangir,

I don't know the answer to that. Perhaps it's worth asking around on the Altera forums? Please do let me know what you figure out!

- Jon

jehangir
Posts: 6
Joined: Thu Jun 11, 2015 4:58 am

Re: How to make headless program

Post by jehangir » Fri Jun 26, 2015 4:35 pm

Hi Jon,

I finally ended up using build_bladerf.sh by modifying it to point to my nios_system repo. If I manage to find appropriate quartus GUI option, i'll post it here.

bests.

Jehangir

Post Reply