Skip to content
10 changes: 5 additions & 5 deletions include/unicore-mx/usbd/usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ typedef enum usbd_speed usbd_speed;

/** Optional features */
enum usbd_backend_features{
USBD_FEATURE_NONE = 0,
USBD_PHY_EXT = (1 << 0),
USBD_VBUS_SENSE = (1 << 1),
USBD_VBUS_EXT = (1 << 2)
USBD_FEATURE_NONE = 0
, USBD_PHY_EXT = (1 << 0)
, USBD_VBUS_SENSE = (1 << 1)
, USBD_VBUS_EXT = (1 << 2)
//* provide usb-core auto power-up/down on connect/disconnect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"//*" (IMO) Please C style comment only (code consistancy).
@danielinux @brabo what do you think?

, USBD_USE_POWERDOWN = (1<<3)
, USBD_USE_POWERDOWN = (1 << 3)
};

struct usbd_backend_config {
Expand Down
8 changes: 6 additions & 2 deletions lib/usbd/backend/usbd_stm32_otg_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,20 @@ static usbd_device *init(const usbd_backend_config *config)
_usbd_dev.backend = &usbd_stm32_otg_fs;
_usbd_dev.config = config;

//* stm32f4 use FS CID=0x1100, HS CID=0x02000600
//* stm32f7 0x3000, CID=0x00003100
const unsigned otg_hs_cid_boundary = 0x3000;

if (config->feature & USBD_VBUS_SENSE) {
if (OTG_FS_CID >= 0x00002000) { /* 2.0 HS core*/
if (OTG_FS_CID >= otg_hs_cid_boundary) { /* 2.0 HS core*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTG_FS_CID >= 0x00003000 leads to running 1.0 HS core init code on 2.0 HS core init

/* Enable VBUS detection */
OTG_FS_GCCFG |= OTG_GCCFG_VBDEN;
} else { /* 1.x FS core*/
/* Enable VBUS sensing in device mode */
OTG_FS_GCCFG |= OTG_GCCFG_VBUSBSEN;
}
} else {
if (OTG_FS_CID >= 0x00002000) { /* 2.0 */
if (OTG_FS_CID >= otg_hs_cid_boundary) { /* 2.0 */
/* Disable VBUS detection. */
OTG_FS_GCCFG &= ~OTG_GCCFG_VBDEN;
REBASE(DWC_OTG_GOTGCTL) |= DWC_OTG_GOTGCTL_BVALOEN |
Expand Down
2 changes: 1 addition & 1 deletion lib/usbd/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool usbd_is_vbus(usbd_device *dev){

void usbd_enable(usbd_device *dev, bool onoff){
if (!onoff)
usbd_disconnect(dev, false);
usbd_disconnect(dev, true);
if (dev->backend->power_control)
dev->backend->power_control(dev, (onoff)? usbd_paActivate : usbd_paShutdown );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application code
= usbd_disconnect(dev, true)
== dev->backend->disconnect(dev, true);
== usbd_enable(dev, false);
=== usbd_disconnect(dev, false);
==== usbd_enable(dev, true);
===== dev->backend->power_control(dev, usbd_paActivate);
==== dev->backend->disconnect(dev, false);
=== dev->backend->power_control(dev, usbd_paShutdown );

Look at the flow of control.
At the end, NOT disconnected with SHUTDOWN power control.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t understand you - enable(false) MUST not shutdown?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i see, thank you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for your new code.

=usbd_disconnect(dev, true)   <----------------\
==dev->backend->disconnect(dev, true);         | RECURSIVE CALL! STACK OVERFLOW!
==usbd_enable(dev, false);                     |
===usbd_disconnect(dev, true)   ---------------/
===dev->backend->power_control(dev, usbd_paShutdown);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, see alredy. more trouble now bother me - cantt understand how to wake up FS from powerdown, cause it want normaly detect online and reset after ungating core clock

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, resolve it. but not preferable way - not like what i write

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When usbd_enable(dev, false) is called, it disconnect and shutdown. but when usbd_enable(dev, true) is called, it only power-up (it remove the disconnect condition).

Copy link
Author

@alexrayne alexrayne May 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this was confused me too. disconnection MUST be provided before powerdown. but fro stm DWC core it is mean that USB enter to non-connectable state. imho, name 'disconnect' - not very suitable for this operation.
i`ll change behaviour to restore disconnection state on powerdown complete.
i not sure, is it good to place disconnection before powerdown into backend->power_control, instead of botherig it on frontend?

Expand Down