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

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

Closed
antonok-edm opened this issue Jan 14, 2023 · 2 comments
Closed

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

antonok-edm opened this issue Jan 14, 2023 · 2 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.

Comments

@antonok-edm
Copy link
Contributor

antonok-edm commented Jan 14, 2023

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

@antonok-edm antonok-edm added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jan 14, 2023
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Jan 14, 2023
@adamgreig
Copy link
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
Copy link
Contributor Author

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

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

4 participants