DCD SAM3U Support
Signed-off-by: Rafael Silva [email protected]
Describe the PR Implementation of a DCD driver for the SAM3U.
Additional context The SAM3U seems to have a similar USB core to the SAMx7x family, for which support is being added in #693, but the register map seems to be completely different. That said, thanks to that it should be easier to port.
Datasheet for reference.
- [x] Port dcd based on SAM7X;
- [x] Successful build;
- [ ] Working examples (cdc_msc, hid_composite);
if it is the same controller, it should be merged together, instead of having 2 different dcds. I have done something similar even across family line for LPC, iMXRT https://github.com/hathach/tinyusb/blob/master/src/portable/nxp/transdimension/dcd_transdimension.c#L30 It is more work initially, but much less work later on when maintaining and fixing bugs.
I have to look further into it, the register map seems very different but it still might make sense to join them
yeah, I really prefer to join them if possible, or at least extract/abstract transfer handling into common API.
After reading SAM3U's manual, it seems they are very similar in functionality.
But there are too much differences in register map, I'm afraid we need to spam #ifdef in order to merge them.
After reading SAM3U's manual, it seems they are very similar in functionality.
But there are too much differences in register map, I'm afraid we need to spam
#ifdefin order to merge them.
It is doable with by extracting function to common API and/or some other works. There is no rush to support SAM3U, we do it little by little.
The reason I added this is because I actually need a usb driver for the sam3u (as well as the sams70), so im planning on working on this
The reason I added this is because I actually need a usb driver for the sam3u (as well as the sams70), so im planning on working on this
If you feel adding new dcd is quicker, feel free to do so in this PR to test with your board. Once it is ready, I could help with the merging.
PS: just placed an order for SAM3U to help with this PR, the official EK board from atmel is out of stock everywhere. https://vi.aliexpress.com/item/4001163149713.html?spm=a2g0o.store_pc_groupList.8148356.2.41612820wy8Fks
how do i approach the cmsis @hathach ? should i merge into the microchip driver repository? right now I'm relying on this https://github.com/cmsis-packs/cmsis-dfp-sam3u
I ported the initial driver from the samx7x, without dual port and dma implementation to reduce complexity, I have yet to test compile, but everything should be more or less ready.
I'm going to be out for a week, I won't pick this up again until then.
@perigoso #693 is finally merged, I've added several fixes later on mostly focused on EP0. I can help review but since I don't have the board I can't test with.
Waiting on #985 to redo this
This is still something I want and have to do, but I don't have time right now (due to new job) so If anyone can pick this up for me I would appreciate it (should be only needed to write the header with the registers)
Started to look at this again, unfortunately, the USB cores are very similar, but just different enough to make it quite hard to make compatible, so I just forked the original samx7x driver and made the necessary changes.
I simply translated as best I could the register from the samx7x to the 3u, but there are a couple features that apparently have slightly different implementations, so I don't believe this is going to work out of the box.
also unfortunately, I don't have any boards with this MCU assembled at the moment. @hathach did you ever get the SAM3U development board?
Any help testing this and finalizing the port would be very appreciated.
cmsis PR: hathach/microchip_driver#9
Board driver is a todo
also unfortunately, I don't have any boards with this MCU assembled at the moment. @hathach did you ever get the SAM3U development board?
I got the board, and would love to help but I am way behind my work schedule now, and couldn't have the time. I will revisit this whenever I could.
I understand, i the meantime I'll try to assemble some boards with it
@HiFiPhile you think you could take a look? I am certain there are things that beed to be done differently, i recall a couple flags to trigger things in the endpoints status register are very different, i did a naive translation so far
@HiFiPhile you think you could take a look?
Yes I could help you if you are going to do some testing, but I haven't used sam3u so my assumption won't be accurate :)
finally tried running this
when I connected in high speed I got constant bus resets to high speed
USBD init on controller 0
sizeof(usbd_device_t) = 47
CDC init
MSC init
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
when forcing full speed i got this from sam:
USBD init on controller 0
sizeof(usbd_device_t) = 47
CDC init
MSC init
USBD Bus Reset : Full Speed
USBD Setup Received 80 06 00 01 00 00 40 00
Get Descriptor Device
Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed
USBD Setup Received 00 05 52 00 00 00 00 00
Set Address
USBD Xfer Complete on EP 80 with 0 bytes
dcd_edpt0_status_complete: complete set address
USBD Setup Received 80 06 00 01 00 00 12 00
Get Descriptor Device
Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 06 00 00 0A 00
Get Descriptor Device Qualifier
Queue EP 80 with 10 bytes ...
USBD Xfer Complete on EP 80 with 10 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 09 00
Get Descriptor Configuration[0]
Queue EP 80 with 9 bytes ...
USBD Xfer Complete on EP 80 with 9 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 62 00
Get Descriptor Configuration[0]
Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
Queue EP 80 with 34 bytes ...
USBD Xfer Complete on EP 80 with 34 bytes
Queue EP 00 with 0 bytes ...
USBD Bus Reset : Full Speed
USBD Setup Received 80 06 00 01 00 00 40 00
Get Descriptor Device
Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed
USBD Setup Received 00 05 53 00 00 00 00 00
Set Address
USBD Xfer Complete on EP 80 with 0 bytes
USBD Setup Received 80 06 00 01 00 00 12 00
Get Descriptor Device
Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 06 00 00 0A 00
Get Descriptor Device Qualifier
Queue EP 80 with 10 bytes ...
USBD Xfer Complete on EP 80 with 10 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 09 00
Get Descriptor Configuration[0]
Queue EP 80 with 9 bytes ...
USBD Xfer Complete on EP 80 with 9 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 62 00
Get Descriptor Configuration[0]
Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
Queue EP 80 with 34 bytes ...
USBD Xfer Complete on EP 80 with 34 bytes
Queue EP 00 with 0 bytes ...
from pc:
[ter jun 28 23:56:29 2022] usb 1-3: new full-speed USB device number 122 using xhci_hcd
[ter jun 28 23:56:29 2022] usb 1-3: not running at top speed; connect to a high speed hub
[ter jun 28 23:56:29 2022] usb 1-3: unable to read config index 0 descriptor/all
[ter jun 28 23:56:29 2022] usb 1-3: can't read configurations, error -71
[ter jun 28 23:56:29 2022] usb usb1-port3: unable to enumerate USB device
after usb high speed reset it doesnt seem to get any endpoint interrupts, while it does on full
anyone think tthey can help me diagnose this?
The host seems to be requesting more data than expected for config descriptos, 0x8d/141 vs 77 for dual cdc, curiously on hid_composite it enumerated
Full speed HID composite
USBD init on controller 0
sizeof(usbd_device_t) = 47
HID init
USBD Bus Reset : Full Speed
USBD Setup Received 80 06 00 01 00 00 40 00
Get Descriptor Device
!USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed
USBD Setup Received 00 05 7D 00 00 00 00 00
Set Address
USBD Xfer Complete on EP 80 with 0 bytes
dcd_edpt0_status_complete: complete set address
USBD Setup Received 80 06 00 01 00 00 12 00
Get Descriptor Device
!USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 06 00 00 0A 00
Get Descriptor Device Qualifier
!USBD Xfer Complete on EP 80 with 10 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 09 00
Get Descriptor Configuration[0]
Queue EP 80 with 9 bytes ...
USBD Xfer Complete on EP 80 with 9 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 02 00 00 22 00
Get Descriptor Configuration[0]
!USBD Xfer Complete on EP 80 with 34 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 00 03 00 00 FF 00
Get Descriptor String[0]
Queue EP 80 with 4 bytes ...
USBD Xfer Complete on EP 80 with 4 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 02 03 09 04 FF 00
Get Descriptor String[2]
USBD Xfer Complete on EP 80 with 30 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 01 03 09 04 FF 00
Get Descriptor String[1]
!USBD Xfer Complete on EP 80 with 16 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 80 06 03 03 09 04 FF 00
Get Descriptor String[3]
!USBD Xfer Complete on EP 80 with 14 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 00 09 01 00 00 00 00 00
Set Configuration
� �
S� HID opened
Bind EP 81 to driver id 0
Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes
USBD Setup Received 80 06 03 03 09 04 FF 00
Get Descriptor String[3]
USBD Xfer Complete on EP 80 with 14 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Setup Received 21 0A 00 00 00 00 00 00
HID control request
Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes
USBD Setup Received 81 06 00 22 00 00 EF 00
Get Descriptor HID control request
!)
( !� USBD Xfer Complete on EP 80 with 64 bytes
Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
Queue EP 80 with 47 bytes ...
USBD Xfer Complete on EP 80 with 47 bytes
HID control complete
Queue EP 00 with 0 bytes ...
[qua jun 29 00:47:01 2022] usb 1-3: new full-speed USB device number 85 using xhci_hcd
[qua jun 29 00:47:01 2022] usb 1-3: not running at top speed; connect to a high speed hub
[qua jun 29 00:47:01 2022] usb 1-3: New USB device found, idVendor=cafe, idProduct=4004, bcdDevice= 1.00
[qua jun 29 00:47:01 2022] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[qua jun 29 00:47:01 2022] usb 1-3: Product: TinyUSB Device
[qua jun 29 00:47:01 2022] usb 1-3: Manufacturer: TinyUSB
[qua jun 29 00:47:01 2022] usb 1-3: SerialNumber: 123456
[qua jun 29 00:47:22 2022] usbhid 1-3:1.0: can't add hid device: -110
[qua jun 29 00:47:22 2022] usbhid: probe of 1-3:1.0 failed with error -110
@hathach / @HiFiPhile Do you have any tips on what to look for?
on high speed it seems to get stuck on the event bus reset on the queue, like it doesnt clear, it did not get more that the first interrupt for the bus reset
I'm suspecting some hardware issue, which board are you using ? Which board is Russian Woodpecker ?
It's a board by me, i don't have access to any dev boards or premade hardware with one, but it should be good, in theory
https://github.com/openinput-fw/russian-woodpecker
It's a board by me
Okay, could you share a pdf version ? I don't have kicad :)
Which ESD diode are you using ?

There's a PDF in the releases https://github.com/openinput-fw/russian-woodpecker/releases/tag/r0.1
the ESD is a USBLC6-2SC6
Nice layout :) When I have time I'll compare with ASF3 to see if there is any difference.
What do you mean by that? the asf code for the USB peripheral? do you know of an example by them relatively ready to go for this device? I can't find one suitable
the asf code for the USB peripheral
Yes ASF3 udphs driver.
I can't find one suitable
Yes they lack a basic example !
When I wrote the driver for SAMx7x I found its USB signal is weaker than other MCUs, @hathach had to use a 30cm cable to let USB work. I don't know if it is the same for SAM3U.
Hm, actually, when i used a longer cable it showed a different behavior, didn't even get to a bus reset, but I'm using a rather short cable right now, could look for something shorter