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

The USB set address request failed in debug build #21

Open
vklachkov opened this issue Jan 2, 2022 · 3 comments
Open

The USB set address request failed in debug build #21

vklachkov opened this issue Jan 2, 2022 · 3 comments
Assignees

Comments

@vklachkov
Copy link

Hi!

I used usb cdc in my project for STM32F411CEU and noticed that sometimes Windows shows error 43 in Device Manager. If reconnect device, then everything works as it should. To reproduce the issue, I plugged and popped the device several times

I found that the problem is reproduced less frequently if the frequency of sysclk is increased. And it completely goes away build project in release mode

Code:

Just poll and read, nothing more

static mut EP_MEMORY: [u32; 1024] = [0; 1024];

#[entry]
fn main() -> ! {
    rtt_init_print!();
    rprintln!("Hello!");

    let dp = pac::Peripherals::take().unwrap();

    let rcc = dp.RCC.constrain();

    let clocks = rcc
        .cfgr
        .use_hse(25.mhz())
        .sysclk(48.mhz())
        .require_pll48clk()
        .freeze();

    let gpioa = dp.GPIOA.split();
    let usb = USB {
        usb_global: dp.OTG_FS_GLOBAL,
        usb_device: dp.OTG_FS_DEVICE,
        usb_pwrclk: dp.OTG_FS_PWRCLK,
        pin_dm: gpioa.pa11.into_alternate(),
        pin_dp: gpioa.pa12.into_alternate(),
        hclk: clocks.hclk(),
    };

    let mut usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });

    let mut serial = SerialPort::new(&usb_bus);

    let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
        .product("Serial port")
        .device_class(USB_CLASS_CDC)
        .build();

    loop {
        if !usb_dev.poll(&mut [&mut serial]) {
            continue;
        }

        let mut buf = [0u8; 64];

        match serial.read(&mut buf[..]) {
            Ok(count) => {}
            Err(UsbError::WouldBlock) => {}
            Err(err) => {}
        };

        match serial.write(&[0x3a, 0x29]) {
            Ok(count) => {}
            Err(UsbError::WouldBlock) => {}
            Err(err) => {}
        };
    }
}

I was unable to get dump using wireshark, but I recorded what was happening on usb using a logic analyzer:

Rust Usb Bug LA Dump.zip

I use a ready-made black pill board from the Chinese

image

The problem is not reproducible on a project written in C using CubeMX

@vklachkov
Copy link
Author

My friend sent me such a link when I described my problem to him: https://community.st.com/s/question/0D50X0000B8jzZL/why-does-the-stm32f407-send-a-stall-on-usbfs

@ajxville
Copy link

Is there any hope of getting this remedied?

@ajxville
Copy link

Just checking in on this again. Any hope for a fix?

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

3 participants