cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 USB SOF and ID Disable/Reuse (Mbed)

LLawr.1
Associate II

I am trying to use the Mbed USBSerial class on an STM32F767VI and it works fine. I also have CAN3 RX setup on pin PA8 (USB SOF) and a GPIO on PA10 (USB ID). I am not using the SOF or ID functionality, but initializing the USB makes it so those pins don’t do anything else. I tried setting “target.usb_speed�? to “USE_USB_NO_OTG�?, because I am under the impression that SOF and ID are mostly related to OTG, and this is device only, but then I get a whole raft of other compile errors. I also tried using STM32Cube to make my own drivers where the USB is initialized as being device only and it compiles, but changes nothing. Is there any way in the current Mbed USB implementation that I can actually use the SOF and ID pins?

1 ACCEPTED SOLUTION

Accepted Solutions
LLawr.1
Associate II

So in the Mbed USBPhy_STM32.cpp file, there is this code that initializes the pins:

while (map->pin != NC) {
        pin_function(map->pin, map->function);
        map++;
    }

This takes all of the pins that are in the pinmap for the USB and initializes them to be used for USB, which are in your targets PeripheralPins.c file, like so:

MBED_WEAK const PinMap PinMap_USB_FS[] = {
//  {PA_8,      USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF // Connected to USB_SOF [TP1]
    {PA_9,      USB_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS // Connected to USB_VBUS
    //{PA_10,     USB_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID // Connected to USB_ID
    {PA_11,     USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM // Connected to USB_DM
    {PA_12,     USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP // Connected to USB_DP
    {NC, NC, 0}
};

I have commented out the ID and SOF parts of the pinmap as shown and now the pins work for whatever else they're being used for. No need for a HAL_PCD_MspInit() function!

View solution in original post

4 REPLIES 4

I don't know mbed and don't use Cube either, but isn't the STM32 mbed just a wrapper around Cube? In that case, Cube expects the GPIO settings of related pins to be set in HAL_PCD_MspInit() function which is something you are supposed to write (or CubeMX to generate perhaps?), again I don't know what's the procedure in mbed.

So perhaps try to find that function and modify it accordingly. Cube and mbed are open source.

JW

Yeah Mbed is more or less a wrapper for the CubeMX generated code from what I can tell. I've been digging around in the driver code and the MCU manual but I am having no luck finding anything about disabling the USB ID/SOF functionality. The HAL_PCD_MspInit() function is supposed to be implemented by a user, but I have no idea what I would do to go about disabling the ID/SOF

​HAL_PCD_MspInit() is the place where those two pins are set as AF for USB in GPIO, do simply remove that piece of code.

JW​

LLawr.1
Associate II

So in the Mbed USBPhy_STM32.cpp file, there is this code that initializes the pins:

while (map->pin != NC) {
        pin_function(map->pin, map->function);
        map++;
    }

This takes all of the pins that are in the pinmap for the USB and initializes them to be used for USB, which are in your targets PeripheralPins.c file, like so:

MBED_WEAK const PinMap PinMap_USB_FS[] = {
//  {PA_8,      USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF // Connected to USB_SOF [TP1]
    {PA_9,      USB_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS // Connected to USB_VBUS
    //{PA_10,     USB_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID // Connected to USB_ID
    {PA_11,     USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM // Connected to USB_DM
    {PA_12,     USB_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP // Connected to USB_DP
    {NC, NC, 0}
};

I have commented out the ID and SOF parts of the pinmap as shown and now the pins work for whatever else they're being used for. No need for a HAL_PCD_MspInit() function!