Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A STM32. What should be done in firmware for VBUS detection through a GPIO pin?

What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared? I'm not familiar with the STM32 USB library, and have only dealt with th...

posted 5mo ago by Olin Lathrop‭  ·  edited 5mo ago by Olin Lathrop‭

Answer
#3: Post edited by user avatar Olin Lathrop‭ · 2024-06-12T14:54:51Z (5 months ago)
  • <blockquote> What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?</blockquote>
  • I'm not familiar with the STM32 USB library, and have only dealt with this on PICs using my own USB library. I'll therefore answer the generic case.
  • The most important thing for the USB library to know is when a logical USB connection is opened and closed. Particularly when a new connection is opened, it needs to start with empty buffers.
  • Depending on how the hardware works, there may not be a need to know when a connection is closed. Something might be waiting for new packets that never come without any harm caused. In some cases there may be efficiency advantages to knowning there is no connection. For example, my USB library discards data the app tries to send when it knows there is no logical connection.
  • In this context, detecting V<sub>bus</sub> is not strictly necessary. If the USB is not physically connected, the firmware should already know there is no logical connection.
  • Detecting lack of physical connection might be a convenient shortcut to absolutely knowing there is no logical connection, but ultimately it is the logical connection that you need to know is open or not. You already have to deal with that when the host does enumeration and establishes a logical connection.
  • Depending on how the hardware works, it may be necessary or desirable to reset it when a new physical connection is detected.
  • <blockquote> What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?</blockquote>
  • I'm not familiar with the STM32 USB library, and have only dealt with this on PICs using my own USB library. I'll therefore answer the generic case.
  • The most important thing for the USB library to know is when a logical USB connection is opened and closed. Particularly when a new connection is opened, it needs to start with empty buffers.
  • Depending on how the hardware works, there may not be a need to know when a connection is closed. Something might be waiting for new packets that never come without any harm caused. In some cases there may be efficiency advantages to knowning there is no connection. For example, my USB library discards data the app tries to send when it knows there is no logical connection.
  • In this context, detecting V<sub>bus</sub> is not strictly necessary. If the USB is not physically connected, the firmware should already know there is no logical connection.
  • Detecting lack of physical connection might be a convenient shortcut to absolutely knowing there is no logical connection, but ultimately it is the logical connection that you need to know is open or not. You already have to deal with that when the host does enumeration and establishes a logical connection.
  • Depending on how the hardware works, it may be necessary or desirable to reset it when a new physical connection is detected. Note that detecting V<sub>bus</sub> is not the only way to do that. Another scheme is detecting no sync packets for some minimum time. They are sent every 1 ms when the USB connection is intact. If you don't see a sync packet for 100 ms, for example, something is definitely very wrong with the connection, whether power voltage is present or not.
#2: Post edited by user avatar Olin Lathrop‭ · 2024-06-12T14:52:29Z (5 months ago)
  • <blockquote> What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?</blockquote>
  • I'm not familiar with the STM32 USB library, and have only dealt with this on PICs using my own USB library. I'll therefore answer the generic case.
  • The most important thing for the USB library to know is when a logical USB connection is opened and closed. Particularly when a new connection is opened, it needs to start with empty buffers.
  • Depending on how the hardware works, there may not be a need to know when a connection is closed. Something might be waiting for new packets that never come without any harm caused. In some cases there may be efficiency advantages to knowning there is no connection. For example, my USB library discards data the app tries to send when it knows there is no logical connection.
  • In this context, detecting V<sub>bus</sub> is not strictly necessary. If the USB is not physically connected, the firmware should already know there is no logical connection.
  • Detecting lack of physical connection might be a convenient shortcut to absolutely knowing there is no logical connection, but ultimately it is the logical connection that you need to know is open or not. You already have to deal with that when the hosts does enumeration and establishes a logical connection.
  • Depending on how the hardware works, it may be necessary or desirable to reset it when a new physical connection is detected.
  • <blockquote> What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?</blockquote>
  • I'm not familiar with the STM32 USB library, and have only dealt with this on PICs using my own USB library. I'll therefore answer the generic case.
  • The most important thing for the USB library to know is when a logical USB connection is opened and closed. Particularly when a new connection is opened, it needs to start with empty buffers.
  • Depending on how the hardware works, there may not be a need to know when a connection is closed. Something might be waiting for new packets that never come without any harm caused. In some cases there may be efficiency advantages to knowning there is no connection. For example, my USB library discards data the app tries to send when it knows there is no logical connection.
  • In this context, detecting V<sub>bus</sub> is not strictly necessary. If the USB is not physically connected, the firmware should already know there is no logical connection.
  • Detecting lack of physical connection might be a convenient shortcut to absolutely knowing there is no logical connection, but ultimately it is the logical connection that you need to know is open or not. You already have to deal with that when the host does enumeration and establishes a logical connection.
  • Depending on how the hardware works, it may be necessary or desirable to reset it when a new physical connection is detected.
#1: Initial revision by user avatar Olin Lathrop‭ · 2024-06-12T14:50:58Z (5 months ago)
<blockquote> What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?</blockquote>

I'm not familiar with the STM32 USB library, and have only dealt with this on PICs using my own USB library.  I'll therefore answer the generic case.

The most important thing for the USB library to know is when a logical USB connection is opened and closed.  Particularly when a new connection is opened, it needs to start with empty buffers.  

Depending on how the hardware works, there may not be a need to know when a connection is closed.  Something might be waiting for new packets that never come without any harm caused.  In some cases there may be efficiency advantages to knowning there is no connection.  For example, my USB library discards data the app tries to send when it knows there is no logical connection.

In this context, detecting V<sub>bus</sub> is not strictly necessary.  If the USB is not physically connected, the firmware should already know there is no logical connection.

Detecting lack of physical connection might be a convenient shortcut to absolutely knowing there is no logical connection, but ultimately it is the logical connection that you need to know is open or not.  You already have to deal with that when the hosts does enumeration and establishes a logical connection.

Depending on how the hardware works, it may be necessary or desirable to reset it when a new physical connection is detected.