Page 1 of 1

STM32 USB

Posted: Sat Jun 13, 2020 5:28 pm
by ttmetro
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

Re: STM32 USB

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

Re: STM32 USB

Posted: Sat Jun 13, 2020 8:44 pm
by ttmetro
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.

Re: STM32 USB

Posted: Sat Jun 13, 2020 8:48 pm
by ttmetro
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?

Re: STM32 USB

Posted: Sun Jun 14, 2020 4:59 am
by ttmetro
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!

Re: STM32 USB

Posted: Fri Jun 19, 2020 8:15 pm
by czero
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?

Re: STM32 USB

Posted: Wed Dec 02, 2020 7:59 pm
by roobkishan
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

Re: STM32 USB

Posted: Thu Dec 03, 2020 7:52 pm
by dhylands
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.