-
Notifications
You must be signed in to change notification settings - Fork 49
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-otg does not work for STM32L476ZGTx #64
Comments
Oh interesting. Of note, the CRS register block, and enable bit in RCC is supported in most STM32 families. It's supported in this lib on L4, for example. Probably all families that have an HSI48. I haven't ops tested it on L4, but I use it on G4, and it compiles in the PAC. I'm a bit surprised it's part of the OTG package; I have it as an optional-enable flag in the clock config. ie: // Enable the Clock Recovery System, which improves HSI48 accuracy.
#[cfg(feature = "h7")]
clocks::enable_crs(CrsSyncSrc::OtgHs);
#[cfg(feature = "g4")]
clocks::enable_crs(CrsSyncSrc::Usb); Of note |
So, I think the core is this: The PAC and SVDs are divided by the final number in L4 series. There are a few exceptions re features that use the second. For example, I had to add a new PAC branch for L412 and 422 that use the RTC from newer series. I'm not sure the proper way to handle this. Some combo of changes to PAC and usbotg lib? What do you think? If you get a chance, could you skin the CRS section of this lib's baseline clock section? I think it blanket allows CRS for all L4, which is evidently not correct. Not a huge deal since you can just choose not to enable if you know yours doesn't have it. Thoughts? In general, the L4 line is a bit of a pain because diff models have diff versions of periphs! Ie some L4s have the newer periphs for RTC, USB, DMA etc you see on G4/L5/H7, while some have various combos of the old ones. Sounds like, for example, if you tried to enable CRS via the HAL fn on your board, weird stuff might happen. |
I definitely think there should be a change at the PAC. Looking at the memory map and comparing the L476 to the other variants, its clear that the CRS register is not meant to be accessed for the L476 variant. Looking at modifying the synopsys-usb-otg to get it working for my board.
Definitely in favor of adding some conditional compilation to get rid of the usb::enable_crs as an option for boards that don't support it. My first priority is to get usb working for my board. Once I have that working I will try to circle back on this library and do some polishing. |
Sounds good. Of note, I caught the RTC thing after swapping what I thought were equivalent MCUs (L432 vice L412), and the RTC broke. Sounds like a similar case here. The fix was a pain because how the PAC broke down L4 variants wasn't compatible with which ones used the new RTC. With that in mind... I'm not sure how to feature gate the |
So I commented out the following lines in synopsys-usb-otg/src/bus.rs // ...
// Perform core soft-reset
// while read_reg!(otg_global, regs.global(), GRSTCTL, AHBIDL) == 0 {}
// modify_reg!(otg_global, regs.global(), GRSTCTL, CSRST: 1);
// while read_reg!(otg_global, regs.global(), GRSTCTL, CSRST) == 1 {} // <- Hanging on this line
//... In my example, I am making it to the |
Hmm. Of note, one thing that can get you is if the MCU doesn't respond to the host very quickly, the host will permanently drop the connection. So the USB poll needs to be on an interrupt (or blocking loop to test), and there can't be any long blocking delays anywhere on the program after it's initialized. Or, relevant to prev discussion here, if the 48mhz clock isn't set up correctly. My goto is HSI48 with CRS synced to USB, but it sounds like you can't do that. |
Managed to get this working using a different clock. See #65. There are compiler warnings within the hal. I thought the example could help chase down and get rid of those warnings. |
Sweet |
Here's the code I am running.
Digging into the build function, it looks like synopsys-usb-otg dependency is trying to modify a register that is not supported for l476 chips.
synopsys-usb-otg/src/bus.rs
Section 7 of reference manual
The text was updated successfully, but these errors were encountered: