device-os
device-os copied to clipboard
[Gen4] fixes deadlock in USB hal
Problem
Device may reside in blocked state after reset or waking up from hibernate mode.
HAL_USB_Init()in main.cpp setsinitialized_totrueand usb thread starts to run withOS_THREAD_PRIORITY_NETWORK - 1priorityUSB_USART_LineCoding_BitRate_Handler()in main.cpp orSerial.begin()in app thread with lower priority ->HAL_USB_USART_Begin()->HAL_USB_Detach()setinitialized_tofalse- usb thread continues to run and keeps waiting for
initialized_to betruein a busy loop - app thread is blocked and
HAL_USB_Attach()won’t be executed andinitialized_won’t be settruegoto #3
Solution
Add a minimum delay within the usb busy loop to allow other threads to call into HAL_USB_Attach()
Steps to Test
Device running the attached app should behave as expected for a long mount of time
Example App
#include "application.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
SerialLogHandler l(115200, LOG_LEVEL_ALL);
void setup() {
}
void loop() {
Particle.connect();
waitFor(Particle.connected, 60000);
Log.info("Start sleep test");
SystemSleepConfiguration config;
config.mode(SystemSleepMode::HIBERNATE)
.gpio(D8, FALLING)
.duration(10s);
Log.info("going to sleep");
delay(10);
System.sleep(config);
}
References
N/A
Completeness
- [x] User is totes amazing for contributing!
- [x] Contributor has signed CLA (Info here)
- [x] Problem and Solution clearly stated
- [ ] Run unit/integration/application tests on device
- [ ] Added documentation
- [ ] Added to CHANGELOG.md after merging (add links to docs and issues)