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

nrf52840 usbd problems

Hi,

I use nrf52840, I meet some problems about the USBD, Can you help me?

We know that the usb device send data to host(such as PC) by EPIN:

(1) The host send IN event, But devie send NAK to host, because  LOCAL BUFFER do not have any data, So many IN-NAK is happening.

(2) Then I send some data to the local buffer by DMA,  when the next IN is come, the device send DATA to host, and then host send ACK to device, and then the EPDATASTATUS will be set.

My question:

Sometimes, when the device send DATA to host, I capture that the last CRC byte is missing, the host receive just one CRC byte(it must CRC16, is two bytes), The previous data is normal, I do not know the reason, maybe some hardware problems becauce of BLE modle.  and then, the host don't send ACK to device. Actually, the host don't send anything, and the EPDATASTATUS will not be set. The device USBD is now mark this EPIN as error status , because When PC send next IN event, the device resend the same data+crc, but this time , it's normal.

My question is that:

When the device USBD mark the EPIN as error status, is there any way that i can clear the status , because i don't need the device resend the right data+crc when the next IN come. It will mess up my application logic. 

Looking forward to your reply, thanks!

  • Hi

    What kind of  host device are you using?

    Are you able to provide a log of the USB communication that we can take a look at?

    According to one of the USB developers we have never seen any issues with missing CRC bytes being sent from the USBD interface in the nRF52840. This is handled by dedicated hardware in the USBD interface, and will not be affected by other activities in the nRF52840 device. 

    Best regards
    Torbjørn

  • The host device that I used is a desktop computer(PC).

    I can't provide a log , because I develop it in a special place, I can't take anything out from that place , Because of the high level of security of my company.

    But I can provide more details about the scene:

    As a ble master device, I use the nRF52840 scan and connect 10 slave ble devices, And the connect interval is 7.5ms, And I let it continue with a permanent scan. And the scan interval is 80ms

    Meanwhile It is also a ble slave device, It broadcasts at 50ms advtisement intervals.

    Under the above working conditions, I also develop nrf52840 as a USB BOT protocol device, I connect it with a computer by USB.

    And then I developed a desktop tool which call the windows USB API function on computer. The tool can send USB BOT protocal data to nrf52840 device .

    The style of USB data transfer by end point is :

    Host -> Slave : The procedure of  the host sends data to nrf52840 is EPOUT[4] -> EPOUT[4](maybe more than one pack blongs to the data size that you want to send) -> EPIN3],

    Slave -> Host : while the procedure  of nrf52840 send data to host is EPOUT[4] -> EPIN[3](maybe more than one pack blongs to the data size that you want to send -> EPIN3].

    I repeat the procedure of Host -> Slave  and Slave -> Host  quickly as possible. Maybe some minutes later , nrf52840 can't receive the EPDATASTATUS being set at EPIN[3] . And I Found that the last byte of CRC of the data is not sent by the USB protocol analyzer. And then the computer don't send ACK to nrf52840.

    If I don't enable BLE master and slave function, Just let USB work, It's not going to be like that, It will be normal even some hours later.

    I search the source code of "nrfx_usbd_errata.h" ,And I searched the 《nRF52840_Rev_2_Errata_v1.2.pdf》, Finally , I can't find the answer.

  • Hi

    That's indeed a lot of activities happening at the same time. 

    Have you done any benchmarking to see how high the CPU utilization is?
    Or maybe more importantly, how much of the time is the CPU busy handling interrupts or events from the Bluetooth softdevice?

    I can check with the developer how much the USB interrupts can be delayed before it starts affecting the USB operation, as this is probably an issue in this case. 

    Best regards
    Torbjørn

  • Hi

    Thanks for your reply!

    I haven't done any benchmarking to see how high the CPU utilization is.

    But I don't use the USB intterrupts method during the procedure of communication stage which uses EP[3] and EP[4].  I only used the USB interrupt method during procedure of USB enumeration which uses EP[0].

    Because I've found that if I use USB interrupts during communication , the  interrupts are often lost, probably because the USB interrupt priority is too low. The interrupt priority for my USB is 6 .  I don't want to use the priority of 2 or 3. because I don't allow that the ble SVC CALL is delayed by the USB intterupts.So finally, I give up the style of USB intterrupt.

    • Here's an example of how I use it:

    For example, if I want to send data to the computer via EPIN[3], I will first send the RAM data to the USB local buffer by DMA, and then I will wait and check if the corresponding bit of EPIN[3]  in EPDATASTATUS register is set. If it has been set, I will clear this bit and complete this procedure.

    In a similar way , If I want to receive some data from computer via EPOUT[4], I will wait and check if the corresponding bit of EPOUT[3]  in EPDATASTATUS register is set, If it has been set, I will read back the data from local buffer to data RAM by DMA. And then I clear the bit and complete this procedure.

    while my question is that:

    If EPIN[3] send incomplete data(miss CRC last byte) to computer, the computer will not send ACK to nrf52840,  and then the corresponding bit of EPIN[3]  in EPDATASTATUS register of nrf52840 will not be set. And the error status will be remember by nrf52840. when next IN event is coming, nrf52840 automatically send the previous data instead of the data I update by DMA in the local buffer .So my software logic got messed up.

    Could you tell me that is there any way I can clear the error status of EPIN[3]?

    I know that re-enumerate USB devices will clean up all the error states. But It cost much time.

    Is stalling the EPIN[3] by EPSTALL register will clear the error status ?

    Could you help me to find some way , or ask for the developer ?

Related