insane-adding-machines / unicore-mx

UniCore-MX | Universal Core for ARM Cortex-M0/0+/3/4/7/X
GNU General Public License v3.0
50 stars 8 forks source link

USBD add core-power and Vbus handle #50

Open alexrayne opened 7 years ago

alexrayne commented 7 years ago

here provided enhances on usbd-driver for: 1) Vbus sensing - method and callback. This helps to detect cable plug in/out, or it can be USBpowering detection 2) USBcore power/clock domain control - method and backend implementation for STM32F4xxx. This intends to power-saving by usb-core and PHY stops.

kuldeepdhaka commented 7 years ago
alexrayne commented 7 years ago

various session callback ...

in my version of unicoremx there no callback concected/disconected - what you talk about? imho control over usbcore power mode should be delegated to user, or must be noted by usbd_conf features.

... we can drop usbd_disconnect(). ...

imho this function made an different thing, vs power control - it initiates session disconnect. but your proposal well - this function can be followed by disable call, that powerdown usbcore after session disconnects. imho this functionality should be denoted by a feature set in usbd_conf_xx structure, to provide backport compatibility with existing code.

kuldeepdhaka commented 7 years ago

Yes, there are no connected/disconnected callback. (dont exists), they need to be implemented.

I think, we should do things transparently for user till they make sense (ie don't get in their way). for example: if user has requested to disable communication with host, it is a good thing that the stack should put the periph in power down mode [saves power]. i see no point in providing a function to put periph in powerdown mode manually (instead of automatically doing it for user).

alexrayne commented 7 years ago

there s possible problem with powerdown - no event generates,no callbacks invokes. Therefore if i powerdown usbcore, suspend callback not affected!

in y board when i plugoff USBcable, session callback invokes and powerdown core. That is all. IMHO here colud be suspend action notified too.

alexrayne commented 7 years ago

i see no point in providing a function to put periph in powerdown mode manually (instead of automatically doing it for user).

IMHO, user should no bruteforces against library for control over periferia. library should provide API as smart as uer requests. If somebody need manual control - publish this functions not a bad. Maybe automatic power downing is good for default, and it can be disabled by a feature . but i`m aware about code that alredy writen with old library. maybe should be defined some macro, like USBD_FEATURE_POWERDOWN_DEFAULT, that choose behaviour. can you imagine some good name for this macro?

kuldeepdhaka commented 7 years ago

What are the possible usecases of manually controlling power down of usb periph?

The stack can provide an abstraction over power down mode via session management {connected, disconnected, suspended, resumed}. For example, after suspend, application code can either either save power (or not save power) but the stack can do [power down] (mundane task) transparently.

alexrayne commented 7 years ago

Ta present i misunderstand differense between suspend/resume and connect/disconnect operations. can you explain? what happen on invoking suspend and disconnect?

kuldeepdhaka commented 7 years ago

@alexrayne USB 2.0 specs (usb_20.pdf) page 240 screenshot_2017-02-09_21-45-20

alexrayne commented 7 years ago

Thank you for this picture. There almost see that suspended is surely not an powerdown mode. but where threr is an mode whre Vbus down - maybe it is "attached" ?

As i remember we discuss about enable vs [dis]connect semantic of usbd api? i agree about that functionality of this methods are close. but here is aspects. disconnect in current implementation makes an logical bus disconnection, after that we can reconfigure usb OTG (or not) for say - host mode, and reconnect again. But if we make power-down in disconnection, usbcore comes not accesible, until powerup. So for reconfigure, we need power enable without connection?

kuldeepdhaka commented 7 years ago

afaiu, Taking power from VBUS dont not mean that a device is connected [ ie self power device]. (yea, Inrush current could be a hint for "something attached"). the actual detection occur via D+ and D- pull-{up/down}.

USB Host control (master) the suspend and resume process. device only have to make sure that it implement the protocol correctly (reduce power consumption and wait for a SOF to detect resume signal).

usbd_disconnect() -> dont communicate with Host. usbd_enable() - disable clocking of periph etc.. (ultimately lead to loss of communicate with host) i would vote for usbd_disconnect() because of (my) intution with function name and its already in api.

I haven't though on reconfiguring api (host mode -> device mode and vice versa - OTG Mode) yet :)

alexrayne commented 7 years ago

because of (my) intution with function name

my intuition - disconnect say nothing about device operational mode, its about connection status. enable(false) says that device should turnoff, and therefore disconnects all connections.

should we fight about names? why this semantics both cant be present?

kuldeepdhaka commented 7 years ago

should we fight about names? why this semantics both cant be present?

But oh boy, bike shedding is fun!

Requirement for the API

alexrayne commented 7 years ago

Kuldeep: 1) about backend api - one contain method <disconnect (bool )> - but this name confusing me. is it same as <connect(!bool)>?

2) about handling power on\off on session disconect - in wich sequence should be called on_session callback and backend.power_control(usbd_paActivate)? have you any mention on it?

alexrayne commented 7 years ago

kuldeep, enums was rewrites with your prefered style

danielinux commented 7 years ago

@kuldeepdhaka any input on this?