2016-02-04 05:21 AM
Hi all:
I am developing a device with an STM32F407. The device will always be powered by its own power supply. It will have a USB socket so that it can act as a ''USB device'' (a USB slave) that shows up as a serial port on the host PC.
I am using Ethernet, CAN2 and almost all UARTs and I cannot spare pin PA9 for the VBUS sensing option. The other USB interface has similar pin conflicts.
I found this thread about VBUS sensing on another STM32 family:
''STM32F207 USB device with no VBUS monitoring''
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSTM32F207%20USB%20device%20with%20no%20VBUS%20monitoring&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CD...
However, the answers are not conclusive. I also looked at the reference manual etc., and I couldn't find a final statement on the subject. Therefore I am asking these questions again:
1) Is it possible to design a USB device without VBUS sensing?
2) If I do VBUS sensing manually on another pin, will that work with the USB driver?
Many thanks,
R. Diez
2016-02-04 05:52 AM
Yes you can do it without VBUS at all, only using DP and DM.
You'll have to be sure that the USB library isn't messing with the PA9 pin. I don't have experience with USB programming with the new HAL library, but in the old USB library pay attention to these definitions: VBUS_SENSING_ENABLED USB_OTG_INTERNAL_VBUS_ENABLED USB_OTG_EXTERNAL_VBUS_ENABLED And comment out the initializing of GPIO pins in usb_bsp.c's USB_OTG_BSP_Init function:/* Configure SOF ID DM DP Pins */
GPIO_InitStructure.GPIO_Pin =
/*GPIO_Pin_8 | */
// commented out by me
GPIO_Pin_11 |
GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;*/
// commented out by me
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
/* Configure VBUS Pin */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
//GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure ID pin */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
//GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;
2016-02-04 07:27 AM
First of all, thanks for your answer.
Out of curiosity, do you know how USB works then? I mean, does the hardware keep listening for any incoming connection from a USB master all the time? Or does the software driver simply keep telling the USB hardware controller to try to establish a connection, in case a USB master is there now?2016-02-04 09:11 AM
Please use the proper terms. The Host hardware monitors the D+ D- signal lines. When a HighSpeed, FullSpeed, or LowSpeed USB device attaches to the Host port, it will pull on one of the signal lines to indicate the a specific device is now physical attached. The Host hardware does some signal line manipulation to verify the device speed and then sets out to Enumerate the device.
2016-02-05 01:24 AM
> The Host hardware monitors the D+ D- signal lines.
> [...] Thanks for your answer. I am worried about the USB Device (my device), and not so much about the USB Host. If my USB Device does not have VBUS recognition, it would be interesting to know how the USB handshake still works. I mean, will the USB Device pull the right signal line all the time, in case a USB Host is now there? Will the USB Device always respond automatically to the USB Host signal manipulation? Or do I have to keep telling the USB software driver on the USB Device side in say 1 second intervals ''please try now to recognise the connection to the USB Host''? That would be the case for example if there is some timeout on the connection recognition and you have to rearm it somehow. I think I'll find a spare pin for USB VBUS sensing, but it is not PA9 (USB_OTG_FS_VBUS), so I would have to do that manually. Is it worth trying to implement this? I mean, if a self-powered USB Device always reacts to a just-connected USB Host, why should I bother with VBUS sensing? I wish I knew more, but I am at an early evaluation phase and I have not had the time yet to learn more about USB.2016-02-05 08:45 AM