rust-embedded-community / usbd-serial

Work-in progress minimal CDC-ACM (USB serial port) class for usb-device
MIT License
118 stars 35 forks source link

Doesn't work when not building in release mode #18

Closed Lukas-Sturm closed 3 years ago

Lukas-Sturm commented 3 years ago

Hey not sure if it is usbd-serial or usb-device or maybe even the stm32f4xx-hal

but after much testing if found that when I build without the release flag Windows can't read the address of the device. Usbdeview shows me "Unknown USB Device (Device Descriptor Request Failed)"

Using poormans debugging with semihosting I saw that it gets stuck in the SerialPort::new call. Trying to debug using gdb it just land in asm/lib.rs (I also have no idea what I am doing never used gdb before :) )

I am totally new to embedded and rust, so this might just be a complete fail on my side. Also my instincts tell me that the compiler optimizing stuff should not be the reason for the code to work. But then it's super low level stuff I guess maybe optimizations change some register interactions. (But again shouldn't optimizations break code)

Editing the Release Profile:

just adding debug = true works while debug = true playing with opt-level: opt-level=0 - does not work opt-level=1 - does not work opt-level=2 - does work opt-level=2 - also works didn't test "z" and "s"

That are my findings :) I still have the feeling it's just some stupid setting I added and totally my fault (Or I missed some note in the documentation) :)))

Config:

Disasm commented 3 years ago

Probably you missed a warning during the build: https://github.com/stm32-rs/synopsys-usb-otg/blob/master/build.rs#L6 The reason behind it is a combination of low opt-level (that makes your code really slow) and high expectations of USB re: response time for requests during the device enumeration process. If the firmware is not fast enough, USB device fails to enumerate.

Lukas-Sturm commented 3 years ago

Thanks, that makes total sense, didn't think about timing constrains. But I didn't get the build warning, my cargo.lock states that I am using the 0.2.4 which should include your change. (atleast the github tagged version does)

Adding them to my build.rs for testing shows me the warning

mvirkkunen commented 3 years ago

As explained this isn't directly related to usbd-serial so I'm closing this. Please open a new issue at the relevant repository if the problem persists.