stm32f4xx-hal
stm32f4xx-hal copied to clipboard
Deadlock in Delay
Board: 'Adafruit Feather STM32F405'
I am currently stuck debugging why my program loop gets stuck while during executing a delay.
loop {
feather.led.set_low();
let c = block!(feather.usb.read()).unwrap();
feather.usb.write(c).unwrap();
feather.led.set_high();
delay.delay_ms(50_u32);
}
This loop is supposed to be a simple echo server. I access it via the screen command and it properly sends all keypresses back.
It gets stuck, however, when I press two keys pretty much simultaneously. Then, the LED stays on and there is no output any longer.
Note that when I remove the delay, this problem is gone.
In this code snippet, Feather (type of the variable feather) is my abstraction struct that initializes all the peripherals:
struct Feather {
clocks: rcc::Clocks,
syst: Option<peripheral::SYST>,
pub log: PanicHandlerWriter,
pub led: gpioc::PC1<Output<PushPull>>,
pub usb: UsbIoToken,
}
and delay is of the type Delay and gets initialized from the Feather struct, taking ownership of the peripheral::SYST.
The only interrupt I have enabled is the pac::Interrupt::OTG_FS, which polls into a static usbd_serial::SerialPort, which is accessible via the UsbIoToken in the Feather struct.
I have a panic handler that writes to the USART3 serial port that prints panic messages (using the panic-write crate), so I'm fairly sure that the program doesn't panic.
Since I'm unable to figure this out, I hope that one of you might have an idea what could cause the problem. I will happily provide more information if necessary, I tried to keep this issue short :)
Try handling the 2 unwrap() calls you have in the code and run the program under debugger. You are probably hitting a error condition somewhere which causes the unwrap() to panic.