Skip to content
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

DCD SAM3U Support #892

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

DCD SAM3U Support #892

wants to merge 11 commits into from

Conversation

perigoso
Copy link
Collaborator

@perigoso perigoso commented Jun 11, 2021

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.

  • Port dcd based on SAM7X;
  • Successful build;
  • Working examples (cdc_msc, hid_composite);

@hathach
Copy link
Owner

hathach commented Jun 12, 2021

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.

@perigoso
Copy link
Collaborator Author

I have to look further into it, the register map seems very different but it still might make sense to join them

@hathach
Copy link
Owner

hathach commented Jun 14, 2021

yeah, I really prefer to join them if possible, or at least extract/abstract transfer handling into common API.

@HiFiPhile
Copy link
Collaborator

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.

@hathach
Copy link
Owner

hathach commented Jun 14, 2021

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.

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.

@perigoso
Copy link
Collaborator Author

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

@perigoso perigoso added the Porting Adding new mcu/board/os support label Jun 14, 2021
@hathach
Copy link
Owner

hathach commented Jun 15, 2021

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

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 10, 2021

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

@perigoso perigoso force-pushed the dcd_sam3u branch 5 times, most recently from 894488d to a8b4b88 Compare July 16, 2021 20:22
@perigoso
Copy link
Collaborator Author

perigoso commented Jul 16, 2021

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.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned previously, #693 should be merged first, then we will generalize that driver to also support sam3u. Same driver should share a same dcd, that is hard at first but pay off later since it helps maintaining and fixing bug afterwards

btw, my order for sam3u board here has arrived, just haven't time to check it out https://vi.aliexpress.com/item/4001163149713.html?spm=a2g0o.store_pc_groupList.8148356.2.41612820wy8Fks

@HiFiPhile
Copy link
Collaborator

@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.

@perigoso
Copy link
Collaborator Author

perigoso commented Aug 4, 2021

Waiting on #985 to redo this

@perigoso
Copy link
Collaborator Author

perigoso commented Dec 2, 2021

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)

@perigoso perigoso force-pushed the dcd_sam3u branch 2 times, most recently from 60abab4 to 5d88621 Compare April 14, 2022 16:15
@perigoso
Copy link
Collaborator Author

perigoso commented Apr 14, 2022

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.

@perigoso perigoso marked this pull request as ready for review April 14, 2022 16:21
@perigoso
Copy link
Collaborator Author

cmsis PR:
hathach/microchip_driver#9

Board driver is a todo

@hathach
Copy link
Owner

hathach commented Apr 16, 2022

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.

@perigoso
Copy link
Collaborator Author

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
Copy link
Collaborator

@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 :)

@perigoso
Copy link
Collaborator Author

perigoso commented Jun 28, 2022

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

@perigoso
Copy link
Collaborator Author

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?

@perigoso
Copy link
Collaborator Author

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

@perigoso
Copy link
Collaborator Author

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

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 1, 2022

@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

@HiFiPhile
Copy link
Collaborator

I'm suspecting some hardware issue, which board are you using ?
Which board is Russian Woodpecker ?

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 2, 2022

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

@HiFiPhile
Copy link
Collaborator

HiFiPhile commented Jul 2, 2022

It's a board by me

Okay, could you share a pdf version ? I don't have kicad :)

Which ESD diode are you using ?
image

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 4, 2022

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 4, 2022

the ESD is a USBLC6-2SC6

@HiFiPhile
Copy link
Collaborator

Nice layout :) When I have time I'll compare with ASF3 to see if there is any difference.

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 5, 2022

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

@HiFiPhile
Copy link
Collaborator

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.

@perigoso
Copy link
Collaborator Author

perigoso commented Jul 6, 2022

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

@perigoso
Copy link
Collaborator Author

I made a really short cable, 5 cm, and I did not have much luck, always showing different symptoms though

@perigoso
Copy link
Collaborator Author

@hathach how is your time? would you be able to take a look at this and try your dev board?

@hathach
Copy link
Owner

hathach commented Mar 17, 2023

Thank you, sorry for super delay. will test this out as soon as I could. I need to find my own SAM3U board, I think it is delivered already.

@HiFiPhile
Copy link
Collaborator

Hi @perigoso , how's it going the project ? Did you made it work ?

@perigoso
Copy link
Collaborator Author

Hi, i never got back to this project, so there are no updates that I recall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Porting Adding new mcu/board/os support
Projects
Status: 📋 Backlog
Development

Successfully merging this pull request may close these issues.

3 participants