This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Simple interface between USBD and PyUSB

Dear Nordic,

I am trying to create a simple interface between my PC with Windows and using PyUSB (since it is a simple wrapper, using libUSB as backend) and the nRF52840 DK.

The idea is to use the communicacion much a faster version of a Serial, since Serial goes top 1 Mbps and an ISO endpoint more than 8 Mbps.

So far I have not been able to establish the connection. I can detect the nrf52 board as an USB device and read its descriptors, but I cannot read or write any endpoints. Do I need any special permissions to access the board? Also, which of the examples would be the easiest to establish a super trivial communication with the PC? Unfortunately there are no examples featuring an isochronous transfer. 

Bests,

Fran89

Parents
  • Hi Fran89,

    You are correct in that maximal supported UART baudrate is 1Mbps, as documented here
    I am not familiar with PyUSB, but if you are seeking to achieve 8 Mbps serial communication I suggest that you instead use the provided SPI interface. As you read about see here, SPI supports 8 Mbps, but you will then need a USB-SPI converter, to easily connect with you computer.

    So far I have not been able to establish the connection. I can detect the nrf52 board as an USB device and read its descriptors, but I cannot read or write any endpoints. Do I need any special permissions to access the board?

    What application do you have running on your nRF52 DK when you try to establish this connection? Are you running one of the examples provided in the SDK? Could you also detail what you mean by read or write any endpoints - do you mean that you are trying to input to a running application, or do you mean that you are unable to flash the device with new code?

    Also, which of the examples would be the easiest to establish a super trivial communication with the PC? Unfortunately there are no examples featuring an isochronous transfer. 

    A good starting point for communication between your nRF52 DK and computer is the UART example, located in the /examples/peripheral/uart directory of the SDK. I am unsure what you mean by the last sentence "there does not exist any examples featuring isochronous transfer".

    Best regards,
    Karl

  • Thank you for the answer.

    SPI seems like a good idea, I have not thought of it because I am already using one SPI interface (SPI3) to drive an ADC and get the data. Then I need to take the data out of the microcontroller to the computer. If both peripherals work independently, i.e. transfering data to the computer through USB will not compromise the sampling rate of SPI3. Could I just load a variable with say 1 KB of data, trigger it to be sent to the PC and continue running the code, therefore not skipping any sample from SPI3? That would be a solution. 

    What application do you have running on your nRF52 DK when you try to establish this connection? Are you running one of the examples provided in the SDK? Could you also detail what you mean by read or write any endpoints - do you mean that you are trying to input to a running application, or do you mean that you are unable to flash the device with new code?

    At that time I was running the usb_cdc_acm example. By reading or writing endpoints I meant trying to input a running application. So far I have been using the SEGGER JLINK port for flashing.

    A good starting point for communication between your nRF52 DK and computer is the UART example, located in the /examples/peripheral/uart directory of the SDK. I am unsure what you mean by the last sentence "there does not exist any examples featuring isochronous transfer".

    Sorry, I did not explain myself clearly here. Right now I am using the UART peripheral to retrieve the data from the microcontroller, but I want to go faster, that is why I wanted to turn to USB. The trivial example I requested refers to the USB protocol, a simple application to read or write individual endpoints (ideally the isochronous endpoints 0x01 and 0x81). The last sentence means that the USB examples provided cover Control, Bulk and Interrupt transfers, but not the Isochronous type, which in another post in the forum I read achieves 8,184 Mbps.

    Bests,

    Fran

Reply
  • Thank you for the answer.

    SPI seems like a good idea, I have not thought of it because I am already using one SPI interface (SPI3) to drive an ADC and get the data. Then I need to take the data out of the microcontroller to the computer. If both peripherals work independently, i.e. transfering data to the computer through USB will not compromise the sampling rate of SPI3. Could I just load a variable with say 1 KB of data, trigger it to be sent to the PC and continue running the code, therefore not skipping any sample from SPI3? That would be a solution. 

    What application do you have running on your nRF52 DK when you try to establish this connection? Are you running one of the examples provided in the SDK? Could you also detail what you mean by read or write any endpoints - do you mean that you are trying to input to a running application, or do you mean that you are unable to flash the device with new code?

    At that time I was running the usb_cdc_acm example. By reading or writing endpoints I meant trying to input a running application. So far I have been using the SEGGER JLINK port for flashing.

    A good starting point for communication between your nRF52 DK and computer is the UART example, located in the /examples/peripheral/uart directory of the SDK. I am unsure what you mean by the last sentence "there does not exist any examples featuring isochronous transfer".

    Sorry, I did not explain myself clearly here. Right now I am using the UART peripheral to retrieve the data from the microcontroller, but I want to go faster, that is why I wanted to turn to USB. The trivial example I requested refers to the USB protocol, a simple application to read or write individual endpoints (ideally the isochronous endpoints 0x01 and 0x81). The last sentence means that the USB examples provided cover Control, Bulk and Interrupt transfers, but not the Isochronous type, which in another post in the forum I read achieves 8,184 Mbps.

    Bests,

    Fran

Children
  • No problem at all, I am glad to help.

    Are you just forwarding the raw data from the peripheral, through the microcontroller, to your computer, or are you processing the data before sending it to the computer? It sounds to me like it is the former you want to achieve. In that case, you should consider having them all on the same SPI bus - by doing this the data will not have to pass through the microcontroller first. In the case that you want it to pass through the microcontroller first, you could look into using the EasyDMA feature of the SPIM peripheral.

    Is there a particular transfer speed you are referring to, when you say that you would like to go faster?
    You have probably seen the documentation for the nRF52840 that the SPIM3 supports frequencies up to 32 Mbps(while SPIM0-2 maximally supports 8 Mbps).
    Additionally, you could also look into the QSPI feature, which also supports up to 32 Mbps. If this is more suitable to your application?

    You are right, there are no specific examples demonstrating Isochronous transfer yet, but you can read more about using the feature here
    The endpoints are however fixed to 0x88 and 0x08.

    Best regards,
    Karl

  • Are you just forwarding the raw data from the peripheral, through the microcontroller, to your computer, or are you processing the data before sending it to the computer? It sounds to me like it is the former you want to achieve. In that case, you should consider having them all on the same SPI bus - by doing this the data will not have to pass through the microcontroller first. In the case that you want it to pass through the microcontroller first, you could look into using the EasyDMA feature of the SPIM peripheral.

    Right now I am trying to send the raw data, but later I will have to process it a bit first. In any case, benchmarking using the data on the same SPI bus is something I would try. By "same bus" you mean physically sharing the SPI paths connecting the microcontroller and the ADC with the SPI to USB converter, right?

    Is there a particular transfer speed you are referring to, when you say that you would like to go faster?
    You have probably seen the documentation for the nRF52840 that the SPIM3 supports frequencies up to 32 Mbps(while SPIM0-2 maximally supports 8 Mbps).
    Additionally, you could also look into the QSPI feature, which also supports up to 32 Mbps. If this is more suitable to your application?

    My theoretical maximum would be 1,5 Mbps per ADC, but possibly the design will require more ADCs, each requiring extra 1,5 Mbps, so I want to know what is the maximum possible throughput to define the maximum amount of ADCs possible. The QSPI feature requires an external memory, but this option is not possible.

    You are right, there are no specific examples demonstrating Isochronous transfer yet, but you can read more about using the feature here
    The endpoints are however fixed to 0x88 and 0x08.

    I will give USB a try, as I would spare the SPI2USB converter for now, thus removing complexity. Whenever I get stuck, I will come back for advice.

    Bests and until then,
    Fran89

  • Hi Fran89,

    By "same bus" you mean physically sharing the SPI paths connecting the microcontroller and the ADC with the SPI to USB converter, right?

    Yes, this is what I meant. By using the Chip Select line of the SPI, the master can select which devices should be active on the bus at any time. This is a very useful feature of SPI, and sounds like it could be apt to your application.

    My theoretical maximum would be 1,5 Mbps per ADC, but possibly the design will require more ADCs, each requiring extra 1,5 Mbps, so I want to know what is the maximum possible throughput to define the maximum amount of ADCs possible. The QSPI feature requires an external memory, but this option is not possible.

    Yes, the QSPI feature requires external memory, sorry for not pointing that out immediately.
    The maximal throughput using the above discussed peripherals is 32 Mbps.

    I will give USB a try, as I would spare the SPI2USB converter for now, thus removing complexity.

    That could be a good way to begin the development, and as you scale up and require more throughput you can move to SPI if necessary.

    Whenever I get stuck, I will come back for advice.

    Absolutely, come back anytime!

    Best regards,
    Karl

Related