Skip to content

Commit 8ffbe5c

Browse files
committed
Lock sleep when USB is initialized
None of the USB drivers currently support entering deep sleep mode while USB is active. To protect USB from malfunctioning lock deep sleep in USBPhyHw::init.
1 parent 0e7f112 commit 8ffbe5c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ USBPhy *get_usb_phy()
106106
return &usbphy;
107107
}
108108

109-
USBPhyHw::USBPhyHw()
109+
USBPhyHw::USBPhyHw(): events(NULL)
110110
{
111111

112112
}
@@ -117,6 +117,9 @@ USBPhyHw::~USBPhyHw()
117117

118118
void USBPhyHw::init(USBPhyEvents *events)
119119
{
120+
if (this->events == NULL) {
121+
sleep_manager_lock_deep_sleep();
122+
}
120123
this->events = events;
121124

122125
// Disable IRQ
@@ -183,6 +186,11 @@ void USBPhyHw::deinit()
183186
disconnect();
184187
NVIC_DisableIRQ(USB0_IRQn);
185188
USB0->INTEN = 0;
189+
190+
if (events != NULL) {
191+
sleep_manager_unlock_deep_sleep();
192+
}
193+
events = NULL;
186194
}
187195

188196
bool USBPhyHw::powered()

usb/device/targets/TARGET_NXP/USBHAL_LPC17.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ USBPhy *get_usb_phy()
369369
return &usbphy;
370370
}
371371

372-
USBPhyHw::USBPhyHw(void)
372+
USBPhyHw::USBPhyHw(void): events(NULL)
373373
{
374374

375375
}
@@ -381,6 +381,9 @@ USBPhyHw::~USBPhyHw(void)
381381

382382
void USBPhyHw::init(USBPhyEvents *events)
383383
{
384+
if (this->events == NULL) {
385+
sleep_manager_lock_deep_sleep();
386+
}
384387
this->events = events;
385388

386389
// Disable IRQ
@@ -440,6 +443,11 @@ void USBPhyHw::deinit()
440443
NVIC_DisableIRQ(USB_IRQn);
441444
events = NULL;
442445
opStarted = 0;
446+
447+
if (events != NULL) {
448+
sleep_manager_unlock_deep_sleep();
449+
}
450+
events = NULL;
443451
}
444452

445453
bool USBPhyHw::powered()

usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void USBPhyHw::init(USBPhyEvents *events)
128128
{
129129
volatile uint8_t dummy_read;
130130

131+
if (this->events == NULL) {
132+
sleep_manager_lock_deep_sleep();
133+
}
131134
this->events = events;
132135

133136
/* registers me */
@@ -174,6 +177,11 @@ void USBPhyHw::deinit()
174177
#endif
175178
dummy_read = CPG.STBCR7;
176179
(void)dummy_read;
180+
181+
if (events != NULL) {
182+
sleep_manager_unlock_deep_sleep();
183+
}
184+
events = NULL;
177185
}
178186

179187
bool USBPhyHw::powered()

usb/device/targets/TARGET_STM/USBPhy_STM32.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ void USBPhyHw::init(USBPhyEvents *events)
168168
{
169169
NVIC_DisableIRQ(USBHAL_IRQn);
170170

171+
if (this->events == NULL) {
172+
sleep_manager_lock_deep_sleep();
173+
}
171174
this->events = events;
172175
sof_enabled = false;
173176
memset(epComplete, 0, sizeof(epComplete));
@@ -333,6 +336,11 @@ void USBPhyHw::deinit()
333336
{
334337
HAL_PCD_DeInit(&hpcd);
335338
NVIC_DisableIRQ(USBHAL_IRQn);
339+
340+
if (events != NULL) {
341+
sleep_manager_unlock_deep_sleep();
342+
}
343+
events = NULL;
336344
}
337345

338346
bool USBPhyHw::powered()

0 commit comments

Comments
 (0)