-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USB Host with a SAMD21: receiving and sending data issues #28
Comments
Hi iKK001, I was wondering how you progress was going? We are trying to do the same type of communication using a SAMD21 based board (currently Adafruit Feaather M0 Proto) as a USB Host to configure another SAMD21 based board (our custom built controller). I wrote a simple CLI on our custom board so I could change some parameters via the serial monitor on arduino without re-programming. Now we want to allow customers to do the same but not need a full computer. We have been successful in creating a link between the two and the USB host sends data and we see on the receiver 100% of data sent from host to slave is received. Where we see issues is missing data sent from slave to host. this is our HOST code:
Our setup is nearly identical to yours with some debug being displayed on a I2C screen since the usb serial is occupied. We got some OTG micro usb to micro usb cables that work for this purpose as I read you needed to OTG cable to work with this setup. Just scanning your code it looks like you are setting rcvd to 32 each time rather than using the receive buffer to see if something is received so you'd always be receiving when you check and not aligned with an actual received packet. This could be the issue of jumbled received data? When we get data it is always as intended, the issue is we either get it all or nothing, never partial. As for sending data it looks as if you are using the SndData() function same as we are. Maybe you are not using an OTG cable? Or maybe you've figured it out by now and maybe you can help us figure out the receive issues? Cheers |
I have it working in both directions. Mostly, on the receiving side, I had to introduce a 75ms delay !! (otherwise it would not work) - see code below and search for the delay(75) to find it. And in my case, I made a second mistake: I had confused So make sure you have the "easy" ports set up correctly everywhere - sometimes one is hunting too far for the mistake. And, you are right, in my original post, I did not care about exact receiving-buffer-length and only set it to 32 (since I knew that my cmds would be shorter than that). It is probably best if I give you here my working example: Example : The loop contains both, sending and receiving methods to make it work bi-directional.
Hope that helps you with your problem. |
Thank you @unltdltd , for your deep-dive ! I will need a bit more time to thoroughly look at this (since very busy with day-job, this might take a few days). In the meantime, let's hope for other folks to explain what is going on exactly with these package-delays. |
hmmm - really hard problem. I did not find anything. And quite frankly, my knowledge is not enough to really debug this USBHost-code. |
@iKK001 Thank you for your help. I had to take a break from this and move onto other projects but I had some time in the last couple days to do a VERY deep dive to better understand what is going on and if maybe someone will see this that can shed some light. I dug into the library and found the functions that put the data on the bus. In cdcacm.cpp ins the function to receive data: This function then calls Phew! Anyway, I added some flags to try and see where the code is when the data is coming in on the bus. I can see the 2 blips inside Then there's a delay while the data it transferred off the bus and then I see more blips after it has completed the data reception process inside As expected I don't know if this is a hardware configuration issue or what, but as you can see in the image the NAK signals happen as the 2nd unexpected packet is coming in and was requested by the HOST while dealing with the 1st packet. |
I am still struggling with using the SAMD21 as USB Host:
As @unltdltd already described, I have now also huge problems in getting the
IMPORTANT OBSERVATION: With the following steps, I can get it to work: a) plug the 3rd-party Controller to my Computer (i.e. Computer is now the USB-Host) However, after power-up, if I never connect the 3rd-party Controller to my Computer in the first place, THEN IT NEVER WORKS !! --> The Computer Connection must do something that the ACM.Init() does not !!!!!!!!!! But what is it ??????
Problem Nr 1 is a killer !! I have the following example-code: What is wrong with it ? Why is the And why is it suddenly working if I connect the 3rd-party Controller to a Computer first ??
|
Hi, Sorry it's been a while since I've commented on this. After extensive debugging and gaining a better understanding of how USB Host works we found our issue to be that the SAMD21 (M0) is not fast enough. When the pipe is unfrozen to receive the next packet it does not always re-freeze the pipe fast enough so another packet gets sent that the library does not know about and overwrites the data that was received. We tried experimenting freezing the pipe sooner but too soon and you kill the current transaction. So we upgraded to a SAMD51 (M4) and have had much better success. I don't know if there some optimization where the freezing can be interrupt driven to accommodate using the slower SAMD21 as it's got plenty of horsepower for the task, it's just a timing issue. Just thought I'd share our results for someone else who may come across this. Cheers |
Thank you - it all makes sense now. Thanks a lot for explaining this here ! |
I am using an Seeed Xiao SAMD21 controller as an USB Host.
The USB counter part I would like to read and write to is a custom Controller from a 3rd-party company that normally connects via USB-FTDI COM port to a computer.
I would like to directly connect this 3rd-party Controller to my Xiao SAMD21 USB-Host.
By the below code example1, I achieved to read from the 3rd-party controller !!
I used the existing example for a PL2303 from the given USB_Host_Library_SAMD library. And this PL2303 example seemed to work best to interact with my 3rd-party Controller.
However, there are still two problems:
As for the first problem: erroneous readings:
Some readings are cut-off parts of the receiving string. Most receiving-communication works. There is just about every 10th cmd from the 3rd-party controller that is only partially transmitted (i.e. partially received). I tried to change the delay in the receiving routine as can be seen in example1 below. But without success.
Do you have any idea what I could do in order to get 100% successful data readings ?
Example1: Receiving data from the 3rd-party Controller to a SAMD21 USB-Host:
Also, I tried to write to the 3rd-party Controller - but this did not work at all. See code-example 2
Example2: Sending data to the 3rd-party Controller from a SAMD21 USB-Host:
There was no data transmission at all. What could be improved ??
Questions:
Here is a complete printout of the 3rd-party USB chip that my 3rd-party Controller contains:
The text was updated successfully, but these errors were encountered: