[stm32f411] using USB pins

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

[stm32f411] using USB pins

Post by nesergen » Mon Jul 05, 2021 12:49 pm

Good day!
I am doing a project on the STM32f411 board. I check the code errors through a computer via a USB cable and a serial monitor. As development progresses, so does the need for pins. Do I understand correctly that if I connect the board to the computer via USB, then I can no longer use some pins (PA8-PA12)?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [stm32f411] using USB pins

Post by dhylands » Mon Jul 05, 2021 4:05 pm

You only need PA11 and PA12 (D+ and D-) as a minimum for USB functionality.

None of the ports that I'm aware of use PA8 (USB_FS_SOF).

The use of PA9 (USB_FS_VBUS) and PA10 (USB_FS_ID) needs to match your configuration found in the mpconfigboard.h file.

For example the PYBV11 uses both VBUS and ID for their USB functionality:
https://github.com/micropython/micropyt ... #L100-L103

whereas the NUCLEO_F411RE doesn't (so you won't find the definitions for MICROPY_HW_USB_VBUS_DETECT_PIN and MICROPY_HW_USB_OTG_ID_PIN in its mpconfigboard.h file:
https://github.com/micropython/micropyt ... figboard.h

You could also employ a GPIO expander chip (often I2C to GPIO). There are LCD Backpacks that use the PCF8574 or the MCP23008 to get character based LCD interfaces to work on the I2C bus.

nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

Re: [stm32f411] using USB pins

Post by nesergen » Mon Jul 05, 2021 5:50 pm

There is a line like this in my settings:

Code: Select all

// USB config
#define MICROPY_HW_USB_FS (1)
As I understand it, it includes support for USB. But the pins used are not listed. Maybe they are listed in another firmware file?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [stm32f411] using USB pins

Post by dhylands » Mon Jul 05, 2021 7:57 pm

Generally speaking, if the defines for MICROPY_HW_USB_VBUS_DETECT_PIN and MICROPY_HW_USB_OTG_ID_PIN aren't in your mpconfigboard.h then the functionality for those pins isn't used.

If you really want to verify the setting for your board, then you can modify https://github.com/micropython/micropyt ... .c#L80-L88

change the #ifdef to look like (i.e. add the 2 #error and the #else):

Code: Select all

        #if defined(MICROPY_HW_USB_VBUS_DETECT_PIN)
        #error VBUS DETECT is defined
        // USB VBUS detect pin is always A9
        mp_hal_pin_config(MICROPY_HW_USB_VBUS_DETECT_PIN, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0);
        #else
        #error VBUS DETECT is NOT defined
        #endif
Then when you try to build you'll get one of the 2 errors. Which one will tell you whether MICROPY_HW_USB_VBUS_DETECT_PIN

Repeat for the MICROPY_HW_USB_OTG_ID_PIN after removing the #error for MICROPY_HW_USB_VBUS_DETECT_PIN

Post Reply