# LimeSDR-USB - Implement custom USB Commands

**URL:** <https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201>\
**Category:** LimeSDR\
**Created:** [12 June 2020 14:16 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201 "2020-06-12T14:16:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomlib](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tomlib](https://discourse.myriadrf.org/u/tomlib)\
**Post date:** [12 June 2020 14:16 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/1 "2020-06-12T14:16:39Z")

</div>

Hello everyone,  
First of all, I just want to precise that I am kind of a newbie to FPGA and all. I’ve been struggling in understanding some part of the designs so I do believe you’ll find easy answers to my question.

I would like to implement a custom USB interface with commands that will change values of some FPGA signals. For this, I was planning on developing my own program in C using libusb. However, I have some doubts on how to do it properly.

First I thought using the FX3 SPI interface but I found out it was not possible to use it as there is a 32-bit wide FX3 data bus. Then I thought passing the data through USB directly but I have some issues understanding how I can achieve this as the NIOS IP directly manages that (I would have to override to implement my own block, is that it ?).

Mainly, I barely understand what is usable and what is already used as means of communication between the PC and the FPGA. What are the possibilites

Thanks in advance,  
Tom

---

<div class="post-metadata">

**Author:** ![tomlib](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tomlib](https://discourse.myriadrf.org/u/tomlib)\
**Post date:** [8 July 2020 08:31 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/2 "2020-07-08T08:31:05Z")

</div>

Well, after some researches, here’s what I am planning on doing :

- Modify FX3 firmware by adding two endpoints for bidirectional control (such as EP0F or EP8F), and update Slave FIFO Interface by adding sockets for my new endpoints ;

- Update gateware and FX3\_SlaveFifo component to match the firmware

- Therefore I’ll have my new functionnalities without losing LMS7002M or waveform control.

If anyone tried that, I would be glad to hear about it. In theory, it seems possible but you never know what problems you’re gonna get so…

Tom

---

<div class="post-metadata">

**Author:** ![Zack](https://yyz2.discourse-cdn.com/flex034/user_avatar/discourse.myriadrf.org/zack/32/89_2.png) [@Zack](https://discourse.myriadrf.org/u/Zack)\
**Post date:** [9 July 2020 07:53 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/3 "2020-07-09T07:53:03Z")

</div>

Hi @tomlib,

> [@tomlib](#):
>
> I would like to implement a custom USB interface with commands that will change values of some FPGA signals.

Could you elaborate this, please.  
I do not think you need to make these changes, while everything is there already.  
This document could be useful for you I think:

> **[LimeSDR-USB\_GW/doc at master · myriadrf/LimeSDR-USB\_GW](https://github.com/myriadrf/LimeSDR-USB_GW/tree/master/doc)**
>
> Altera Cyclone IV FPGA project for the USB 3.0 LimeSDR board - myriadrf/LimeSDR-USB\_GW

---

<div class="post-metadata">

**Author:** ![tomlib](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tomlib](https://discourse.myriadrf.org/u/tomlib)\
**Post date:** [9 July 2020 08:29 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/4 "2020-07-09T08:29:03Z")

</div>

Hello @Zack,  
Thanks for your answer.

> [@Zack](#):
>
> Could you elaborate this, please.

I am planning on adding custom blocks to the design and I need USB communication to configure some of the registers of my new blocks.

> [@Zack](#):
>
> I do not think you need to make these changes, while everything is there already

Well as far as I have understood, there are two endpoints used for stream (EP01 and EP81), and two endpoints used for control data (EP0F and EP8F). I believe all these endpoints are driven to the NIOS CPU, which is something I want to avoid. So by adding two endpoints (and updating firmware accordingly) driven to my own components, I won’t lose any functionalities.

Please correct me if I’m wrong and if I can use already existing endpoints.

Tom

---

<div class="post-metadata">

**Author:** ![Zack](https://yyz2.discourse-cdn.com/flex034/user_avatar/discourse.myriadrf.org/zack/32/89_2.png) [@Zack](https://discourse.myriadrf.org/u/Zack)\
**Post date:** [9 July 2020 11:51 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/5 "2020-07-09T11:51:11Z")

</div>

Hi @tomlib,

> [@tomlib](#):
>
> Well as far as I have understood, there are two endpoints used for stream (EP01 and EP81), and two endpoints used for control data (EP0F and EP8F). I believe all these endpoints are driven to the NIOS CPU, which is something I want to avoid.

NIOS CPU is not involved in data stream communications (i.e.EP01 and EP81). But yes, NIOS CPU communicates via control endpoints EP0F and EP8F with the software running on PC.

Now I am confident that you do not need to change FX3 firmware, everything you need is there already. What you need to do is do create your blocks in FPGA, define control registers accessible via SPI interface and implement additional commands to read/write these registers in PC software and NIOS CPU firmware.

And yes, you should study document I’ve provided earlier. It will explain everything you need to implement your application.

---

<div class="post-metadata">

**Author:** ![tomlib](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tomlib](https://discourse.myriadrf.org/u/tomlib)\
**Post date:** [9 July 2020 12:33 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/6 "2020-07-09T12:33:44Z")

</div>

@Zack,

> [@Zack](#):
>
> NIOS CPU is not involved in data stream communications (i.e.EP01 and EP81).

Indeed, I got confused.

> [@Zack](#):
>
> and implement additional commands to read/write these registers in PC software and NIOS CPU firmware.

I’ve never heard about NIOS CPU firmware ? Do you mean by editing the “LMS64C\_protocol.h” file ?  
To be fair, I thought about doing that and I went in another direction, because I guess I got confused by the fact that the package was named “spi”.

> [@Zack](#):
>
> And yes, you should study document I’ve provided earlier.

Well I have always used this gateware document but I still have trouble seeing what has to be done in my case. As I said in the initial post, I am kinda new to these technologies so yeah I am struggling.

Tom

---

<div class="post-metadata">

**Author:** ![JTAG](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@JTAG](https://discourse.myriadrf.org/u/JTAG)\
**Post date:** [9 July 2020 13:45 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/7 "2020-07-09T13:45:04Z")

</div>

Hey @tomlib,

> [@tomlib](#):
>
> I am planning on adding custom blocks to the design and I need USB communication to configure some of the registers of my new blocks.

you can easily use the internal SPI bus to add your own configuration registers. Maybe this helps you:

> [@Building a simple command line app for the LimeSDR](https://discourse.myriadrf.org/t/building-a-simple-command-line-app-for-the-limesdr/2853/2):
>
> Hey Ed, unless you share some code it will be quite difficult to help you. Also you could mabye add a bit on your plans to use the LimeSDR as a periphal. Is it just GPIO access? Then probably you don’t even need to change gateware or LimeSuite, as GPIO accesses can handeled through the APIs. Maybe you could have a quick look at my current project. I am implementaing a small DDS core inside the LimeSDR written in VHDL. The configuration is also done using registers accesed by the NIOS. One can …

I use this to control my custom DDS/CIC decimator core inside the FPGA. By using the SPI configuration registers (see link) you do not need to modify any firmware/driver. The entire configuration can then be done in the user application using the “write register” functions, already existing in the Lime/Soapy API 🙂

---

<div class="post-metadata">

**Author:** ![tomlib](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tomlib](https://discourse.myriadrf.org/u/tomlib)\
**Post date:** [9 July 2020 14:03 UTC](https://discourse.myriadrf.org/t/limesdr-usb-implement-custom-usb-commands/6201/8 "2020-07-09T14:03:25Z")

</div>

Hey @JTAG,

I eventually found out the way to go with the last chapters of the gateware document, and your message confirms that I am now heading for the right solution. So I thank you and @Zack for helping me out !

Tom
