esp-rs / esp-pacs

Peripheral Access Crates for Espressif SoCs and modules
Apache License 2.0
103 stars 29 forks source link

esp32s3 USB0 register block issues #212

Closed simpkins closed 4 months ago

simpkins commented 4 months ago

I'm playing around with possibly implementing an embassy-usb driver for esp32s3, and while doing so I noticed a few things that look like typos or transcription errors in the esp32s3 SVD file (an also in the esp32s2 one too).

As an aside, the fact that all of the endpoint registers (DIEPCTLn, DOEPCTLn, DIEPINTn, DOEPINTn, etc) have different types for each endpoint makes the code much more awkward to use. The endpoint 0 registers are slightly different from the others, but it would be nice if endpoints 1 through 5 all used the same types.

Also, very minor, but I wonder if the USB0.GINTSTS.RXFLVI name was a typo in the SVD and should have been RXFLVL instead?

simpkins commented 4 months ago

Also, the MPS field looks incorrect in USB0.DIEPCTLn. I believe this should be bits 0:2 in diepctl0, but bits 0:10 in diepctl1 through diepctl6. However, it is listed as just 2 bits wide for all endpoints.

The DOEPCTLn registers to appear to be correct.

simpkins commented 4 months ago

I guess there are two separate aspects to this issue:

I'm not sure how much appetite there is to do the larger cleanup. From a cursory search I didn't really see any downstream crates that seem to be using the USB0 register block much, so it possibly wouldn't disrupt too many things downstream. That said, I'm not sure how much you want to avoid deviating from the base SVD.

If we did clean things up I would suggest:

MabezDev commented 4 months ago

Thanks for the issue @simpkins! We very much have an appetite to do the cleanup, particularly in this case where there isn't a driver to update. It's much nicer write drivers when the PAC is in a good spot.

We really appreciate the PR, and any subsequent PRs you may file (the clean up suggestions look good to me!). Most of the Rust team will be on vacation till next week, and we'll get to reviewing your PR then :).

MabezDev commented 4 months ago

Oh and seeing as you're interested in async USB in the end, cc: @dominazzz and https://github.com/embassy-rs/embassy/issues/2494.

I also have a personal use for async USB coming up, so I'd be more than happy to help the both of you work through the issues :).

simpkins commented 4 months ago

Thanks for the feedback. I've got some code that is close to working (I think) for using embassy-usb on esp32s3; I'll try to make some more progress on it in the next few days and then upload it to github. It isn't really based on the embassy-stm32 implementation--I looked at how they did some stuff, but it is largely from scratch with a few different design choices. (I also looked at how tinyusb does things, plus the STMicro documentation, given that Espressif docs cite an NDA and don't include USB register documentation.)

I'll try to make a few more pull requests with SVD patches when I have made more progress.

Having a combined embassy-usb-driver implementation for both STM32 and ESP32 chips would be nice in the long run. That said, I think it would take quite a bit of refactoring to make this work with esp-pacs--the USB0 API exposed by esp-pacs is rather different than the one used by the embassy-stm32 ral, even though the register block layout is nearly the same.

As an aside, I did notice one more SVD bug: the PKTCNT fields in DOEPTSIZn is listed as just 1 bit, while I believe it should be 10 bits in endpoints 1-6. (At least, it's 10 bits in the STMicro docs.)

MabezDev commented 4 months ago

Having a combined embassy-usb-driver implementation for both STM32 and ESP32 chips would be nice in the long run. That said, I think it would take quite a bit of refactoring to make this work with esp-pacs--the USB0 API exposed by esp-pacs is rather different than the one used by the embassy-stm32 ral, even though the register block layout is nearly the same.

I agree, having completely different peripheral access mechanisms makes this probably more effort than it's currently worth. Let's just focus on getting the pac in good shape for your upcoming driver, merging the two can be a longer term stretch goal if we wish.

MabezDev commented 4 months ago

Closed via https://github.com/esp-rs/esp-pacs/pull/213