Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB superspeed peripherals Forum Discussions

Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

How CyAPI recovers data transmission after accidental USB reconnection

我们当前的解决方案是手动触发CYAPI通过Control End Point通道向CYUSB3014发送一条命令,CYUSB3014固件执行CyU3PDeviceReset函数。这个解决方案存在2个问题。

Our current solution is to manually trigger the CyAPI to send a command to CYUSB3014 through the EP0(Control End Point) channel. The CYUSB3014 firmware executes the CyU3PDeviceReset function. There are two problems with this solution.

第1个:USB连接恢复后的第一次传输异常(后续的传输是成功的)。我们的分析认为CYUSB3014没有清空上次传输失败的数据。如果不调用CyU3PDeviceReset函数,我们就不知道有什么办法恢复CYUSB3014的数据传输。我们尝试过调用CyU3PUsbResetEndpointMemories函数和CyU3PUsbResetEp函数,都没有解决问题。

First: The first transmission fails after the USB connection is restored (the subsequent transmission is successful). Our analysis shows that CYUSB3014 does not clear the data that failed in the last transmission. If the CyU3PDeviceReset function is not called, we do not know how to recover the data transmission of CYUSB3014. We tried to call the CyU3PUsbResetEndpointMemories function and CyU3PUsbResetEp function, but they didn't solve the problem.

第2个:Windows设备管理器会再次刷新。USB连接重连造成Windows设备管理器第1次刷新,CYUSB3014固件执行CyU3PDeviceReset函数后Windows设备管理器发生第2次刷新。我们不希望Windows设备管理器第2次刷新。

Second: Windows Device Manager will refresh again. The reconnection of the USB connection caused the first refresh of the Windows Device Manager, and the second refresh of the Windows Device Manager occurred after the CYUSB3014 firmware executed the CyU3PDeviceReset function. We do not want Windows Device Manager to refresh for the second time.

请指点。谢谢!

Please point out. Thank you!

0 Likes
1 Solution
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello Flute,

Please try my previous suggestion for the original issue and let me know if it helps.

Best Regards,
Jayakrishna

View solution in original post

0 Likes
12 Replies
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

Based on my understanding, you are accidentally disconnecting and reconnecting the USB device from the host and want to restart the data transmission once the device is reconnected to the host. Please correct me if my understanding is wrong.

Also, please let me know the following information:

1. Is the device self powered or bus powered?

2. The boot mode used. Is it SPI or I2C boot?

3. Wireshark traces containing the disconnection and reconnection for us to check.

We also understand that you are using a custom host application based on CyAPI.lib for communicating with the device. In this case, are you opening the device again after the reconnection? Or are you communicating with the previous handle itself? It would be helpful if you can share the source code of the host application too.

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2
  1. Device is self powered always.  Power supply will not be interrupted. 
  2. It's boot by SPI.
  3. Our customer requires that. I think that we needn't to check the reason of reconnection. It maybe that USB cable is plugged and unpluged manually..
  4. The handle is created again.
  5. I'll write a example specifically for this problem and upload it to Github.

Best Regards,

Flute

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello Flute,

If the device is bus powered, and if the device is disconnected and reconnected, then there will be power interruption. Please correct me if my understanding is wrong.

If my understanding is correct, then the device will undergo a power off and power on upon disconnection and reconnection. This will make the device to re-boot from flash again. The device will then enumerate freshly at the host side (endpoint, DMA etc will be initialized again and will be clean). All the previous transfers will be cancelled by the host as the device was disconnected. As mentioned in your previous response, when the device is reconnected, a new handle is created for communication. In this case, the subsequent requests to the new handle should not fail.

Can you please share the Wireshark traces when the issue is seen so that we can understand the issue better?

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

I'll write a example specifically for this problem and upload it to Github and share Wireshark traces.

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

Sure, please share the requested information so that we can debug further.

Also, may I know why CyU3PDeviceReset (CyFalse) was used? Because, as I mentioned in my previous response, the device will restart freshly when it is unplugged and re-plugged. So, there is no need to call an API to perform a software reset again as the device will be reset already upon disconnection and reconnection.

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

I'm sorry about call CyU3PDeviceReset function. We just try to recover data transmission. And I should correct me. CYUSB3014 is self powered, not bus powered. I have modified my first reply.

Best Regards,
Flute

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

As the device is self powered, you need to clean the DMA, endpoint etc upon disconnection of the device. Once the device reconnects to the USB host, you need to configure the DMA, endpoints etc for subsequent transfers.

Can you please try the following and let me know if it helps:

1. When a CY_U3P_USB_EVENT_DISCONNECT even is received,  stop all the transfers, reset the dma channels used for communication and flush the endpoints. If your application is based on AN75779, then you can use the function CyFxUvcApplnStop () in AN75779 project as a reference to understand the procedure. If it is based on Slave fifo, then you can make use of the function CyFxSlFifoApplnStop () in Slave FIFO project as a reference to understand the procedure.

2. Upon reconnection, based on my understanding, you will be calling the API CyU3PConnectState () to connect the device to the USB host again.

3. This will trigger enumeration of the device on the host side which will result in obtaining the event CY_U3P_USB_EVENT_SETCONF in firmware. As part of this event handling, you can restart the application again by configuring the endpoints, DMA etc. You can make use of the function CyFxSlFifoApplnStart () in Slave FIFO project as a reference to understand the procedure. 

Please try this and let me know if it helps.

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

Hi,

I already push my code to xuesongshu/ht3: this is a test (github.com)

I encountered the problem of creating end point failed. Please help me to resolve this problem first.

Best Regards,
Flute

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello Flute,

Can you please let me know which source file is referred to in the github repository for which the problem is seen?

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

Hello Jayakrishna,

Sorry, first of all, I request help to resolve another problem that's stuck in front. I'll close this post.

Best Regards,
Flute

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello Flute,

Please try my previous suggestion for the original issue and let me know if it helps.

Best Regards,
Jayakrishna
0 Likes
Flute
Level 2
10 replies posted First solution authored 25 sign-ins
Level 2

Hello Jayakrishna,

Sure. I have simplified my problem to another project that's based on USBBulkSourceSink example. Guthub address: xuesongshu/ht1: Learn and study CYUSB3014 (github.com)

Please help me at post Create multi DMA channel fail base on USBBulkSourc... - Infineon Developer Community. Thanks.

Best Regards,
Flute

 

0 Likes