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

Intermittent failure to enable the usb bus #37

Open
dgoodlad opened this issue Aug 3, 2023 · 0 comments
Open

Intermittent failure to enable the usb bus #37

dgoodlad opened this issue Aug 3, 2023 · 0 comments

Comments

@dgoodlad
Copy link
Contributor

dgoodlad commented Aug 3, 2023

Developing on an STM32F446 device, I've been seeing a 50/50 chance of the bus enable() function hanging waiting for the core soft reset to complete. It sits stuck in the loop in bus.rs:437. This happens at least 50% of the time, and it doesn't matter if the code being flashed is the same or not.

There are a number of folks complaining about similar issues around the internet, with varying causes noted:

... and more.

I have confirmed that the HSE is stable and configured correctly. I am using the f446 nucleo board, which has an on-board 8MHz external oscillator signal passed through from the st-link. My clocks are configured using the stm32f4xx-hal package's code like so:

let clocks = rcc
    .constrain().cfgr
    .use_hse(8.MHz())
    .bypass_hse_oscillator()
    .sysclk(168.MHz())
    .require_pll48clk()
    .pclk1(42.MHz())
    .pclk2(84.MHz())
    .sai1_clk(49_142_857.Hz())
    .freeze();

One consistent message in a few others' experience is that the otg core seems to need to have interrupts unmasked internally to function correctly, and that needs to happen early. This aligns with the programming model in RM0390, section 31.16.1:

image

I've given this a hacky go by doing the following before any other USB initialisation code:

// GAHBCFG.GINT = 1
cx.device.OTG_HS_GLOBAL.gahbcfg.modify(|_,w| w.gint().set_bit());
// GINTMSK.OTGINT = 1; GINTMSK.MMISM = 1;
cx.device.OTG_HS_GLOBAL.gintmsk.modify(|_,w| w.otgint().set_bit().mmism().set_bit());

I can't 100% confirm this works, but I have yet to see another stall waiting for the core soft reset to clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant