STM32 USB

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
ttmetro
Posts: 85
Joined: Mon Jul 31, 2017 12:44 am

STM32 USB

Post by ttmetro » Sat Jun 13, 2020 5:28 pm

I have a custom board with an STM32F401. I can flash micropython with DFU, but cannot connect to the REPL over USB (the computer - a MAC - won't even "see" the USB port).

The wiring of the USB connector could be the problem: only DP (1.5k pullup to 3.3V) and DM are connected (and 5V). ID is NC (and A10 unused), and A9 on the mcu is connected to an LED. Is it possible to communicate with micropython with this setup?

For reference: mpconfigboard.h (8MHz crystal on the board):

Code: Select all

#define MICROPY_HW_ENABLE_USB       (1)
#define MICROPY_HW_HAS_FLASH        (1)

// HSE is 8MHz
#define MICROPY_HW_CLK_PLLM (8)
#define MICROPY_HW_CLK_PLLN (336)
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7)
#define MICROPY_HW_CLK_LAST_FREQ (1)

// LEDs
#define MICROPY_HW_LED1             (pin_A9) // Green LED
#define MICROPY_HW_LED_ON(pin)      (mp_hal_pin_high(pin))
#define MICROPY_HW_LED_OFF(pin)     (mp_hal_pin_low(pin))

// USB config
#define MICROPY_HW_USB_FS              (1)
// #define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
// #define MICROPY_HW_USB_OTG_ID_PIN      (pin_A10)
Thanks,
Bernhard
Bernhard Boser

SpotlightKid
Posts: 420
Joined: Wed Apr 08, 2015 5:19 am

Re: STM32 USB

Post by SpotlightKid » Sat Jun 13, 2020 8:05 pm

What kind of board is this? Does it have a ST Link interface, maybe? Do you have MICROPY_HW_ENABLE_USB enabled?

ttmetro
Posts: 85
Joined: Mon Jul 31, 2017 12:44 am

Re: STM32 USB

Post by ttmetro » Sat Jun 13, 2020 8:44 pm

This is a custom board with an STM32F401CEU cpu (uqfn48 package) and minimal additional hardware:

- no SDLink
- an 8MHz crystal with 20pF loads,
- the aforementioned USB connector with just DP and DN connected to the cpu,
- Boot1 tied to gnd
- Boot0 0 or 1 to put into DFU mode
- a few GPIO pins wired out

Since DFU works I assume the USB port is connected correctly (at least DP and DN). Flashing micropython also works fine (with make deploy for the particular board configuration). However, when not in DFU mode the device won't be recognized by the computer (just won't show up in /dev).

Perhaps the REPL isn't working, or the USB is not configured, or there is an issue with the clock. I'm not sure how to diagnose the problem and am hoping for suggesions.
Bernhard Boser

ttmetro
Posts: 85
Joined: Mon Jul 31, 2017 12:44 am

Re: STM32 USB

Post by ttmetro » Sat Jun 13, 2020 8:48 pm

SpotlightKid wrote:
Sat Jun 13, 2020 8:05 pm
What kind of board is this? Does it have a ST Link interface, maybe? Do you have MICROPY_HW_ENABLE_USB enabled?
Yes, also MICROPY_HW_USB_FS.

MICROPY_HW_USB_VBUS_DETECT_PIN and MICROPY_HW_USB_OTG_ID_PIN are not defined since they are not connected to the usb port.

I inadvertently have an LED on PA9 (to gnd through a resistor). Could this be an issue if the USB port is used?
Bernhard Boser

ttmetro
Posts: 85
Joined: Mon Jul 31, 2017 12:44 am

Re: STM32 USB

Post by ttmetro » Sun Jun 14, 2020 4:59 am

ttmetro wrote:
Sat Jun 13, 2020 5:28 pm

Code: Select all

#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
This line needs to be

Code: Select all

#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV4)
Then all is well!
Bernhard Boser

czero
Posts: 1
Joined: Thu May 07, 2020 4:23 pm

Re: STM32 USB

Post by czero » Fri Jun 19, 2020 8:15 pm

Hello,
I'm currently creating a board with a stm32f401re too, and I saw this note in the datasheet https://www.st.com/resource/en/datashee ... f401re.pdf, page 105:
"When VBUS sensing feature is enabled, PA9 should be left at their default state (floating
input), not as alternate function."

Is your led ok when the board is connected to usb?

roobkishan
Posts: 3
Joined: Wed Dec 02, 2020 5:17 pm

Re: STM32 USB

Post by roobkishan » Wed Dec 02, 2020 7:59 pm

Did you get it running i am also getting same problem but the board is stm32f765. it is blinking at start but no fs usb detected

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

Re: STM32 USB

Post by dhylands » Thu Dec 03, 2020 7:52 pm

I recently updated the board definition files for a board my brother and I designed.

It's using a 401 and has an 8 MHz crystal with a 32K LSE crystal. You can find the updated board definition here:
https://github.com/dhylands/BIOLOID_POW ... figboard.h

You don't need to use PA9 or PA10 for USB, just make sure you have the definitions commented out in the board definition file.

I see my definitions for the PLL are different than yours. The 401 has a lower max frequency than the 405.

Post Reply