Skip to content

Embedded projects using synopsys-usb-otg are hanging in Beta/Nightly #106830

Closed
@antonok-edm

Description

@antonok-edm
Contributor

Code

I tried this code:

Cargo.toml

[dependencies]
stm32f4xx-hal = { version = "0.13", features = ["rt", "stm32f401", "usb_fs"] }
embedded-hal = "^ 0.2.6"
cortex-m = { version = "^ 0.7" }
cortex-m-rt = { version = "^ 0.7", features = ["device"] }
usb-device = "^ 0.2"

toolchain: thumbv7em-none-eabihf

main.rs

#![no_main]
#![no_std]
 
use stm32f4xx_hal::{
    otg_fs::{ USB as Peripheral, UsbBus },
    pac::Peripherals,
    prelude::*,
};
 
use usb_device::{
    bus::UsbBusAllocator,
    prelude::*,
};
 
#[entry]
fn main() -> ! {
    const SYS_CLOCK_MHZ: u32 = 84;
 
    const VID: u16 = 0x1337;
    const PID: u16 = 0x1337;
    const MANUFACTURER_NAME: &str = "test";
    const PRODUCT_NAME: &str = "test";
 
    static mut EP_MEMORY: [u32; 1024] = [0; 1024];
 
    let device = Peripherals::take().unwrap();
    let rcc = device.RCC.constrain();
 
    let clocks = rcc.cfgr
        .use_hse(25.MHz())
        .sysclk(SYS_CLOCK_MHZ.MHz())
        .require_pll48clk()
        .freeze();
    assert!(clocks.is_pll48clk_valid());
 
    let gpioa = device.GPIOA.split();
 
    let usb = stm32f4xx_hal::otg_fs::USB {
        usb_global: device.OTG_FS_GLOBAL,
        usb_device: device.OTG_FS_DEVICE,
        usb_pwrclk: device.OTG_FS_PWRCLK,
        pin_dm: gpioa.pa11.into_alternate(),
        pin_dp: gpioa.pa12.into_alternate(),
        hclk: clocks.hclk(),
    };
 
    let usb_allocator: UsbBusAllocator<UsbBus<Peripheral>>;
 
    usb_allocator = UsbBus::new(usb, unsafe { &mut EP_MEMORY });
 
    // Any code following this assignment never runs on Beta or Nightly
    let usb_bus = UsbDeviceBuilder::new(&usb_allocator, UsbVidPid(VID, PID))
        .manufacturer(MANUFACTURER_NAME)
        .product(PRODUCT_NAME)
        .device_class(0x00)
        .build();
 
    // activate a peripheral of your choice here to demonstrate
}

I expected to see this happen: the peripheral activation at the end should occur

Instead, this happened: the program hangs indefinitely

Version it worked on

It most recently worked on: Rust 1.66.1

Version with regression

rustc --version --verbose:

rustc 1.67.0-beta.7 (275123cf6 2023-01-11)
binary: rustc
commit-hash: 275123cf608aad2c3b48c7a53b019430244e4574
commit-date: 2023-01-11
host: x86_64-unknown-linux-gnu
release: 1.67.0-beta.7
LLVM version: 15.0.6

More details

See also @hacknus's provided examples, investigation, and debugger output at stm32-rs/synopsys-usb-otg#33. I don't have the ability to run a debugger on my hardware, unfortunately.

cc @adamgreig who has also reproduced the issue.

Some bisecting

nightly-2022-11-09 does not have the issue
nightly-2022-11-19 does not have the issue
nightly-2022-11-21 does not have the issue
nightly-2022-11-22 does not have the issue
nightly-2022-11-24 does have the issue

Activity

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
and removed
regression-untriagedUntriaged performance or correctness regression.
on Jan 14, 2023
adamgreig

adamgreig commented on Jan 14, 2023

@adamgreig
Member

I'm pretty sure this is #102750 and a bug in https://github.com/stm32-rs/synopsys-usb-otg which should be using repr(C) and isn't.

antonok-edm

antonok-edm commented on Jan 14, 2023

@antonok-edm
ContributorAuthor

Indeed, looks like this is related to #102750, and thus a bug in synopsys-usb-otg rather than rust. Sorry for noise!

removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @adamgreig@apiraino@antonok-edm@rustbot

        Issue actions

          Embedded projects using `synopsys-usb-otg` are hanging in Beta/Nightly · Issue #106830 · rust-lang/rust