Page 1 of 1

STM32 [NUCLEO_F411RE] - Missing pyb.usb_mode function

Posted: Mon Jan 13, 2020 3:41 am
by esologic
Hi everyone!

Spent the day getting MicroPython running on my NUCLEO_F411RE dev board. Everything has gone smooth so far, and I can access the repl no problem.

I would like to enable USB MSC to drag and drop libraries and programs onto the device. Reading the docs, I think I should use the:

Code: Select all

pyb.usb_mode
Function, but when I go to use it in the repl I see:

Code: Select all

>>> import pyb 
>>> pyb.usb_mode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'usb_mode'
Any ideas?

Thanks.

Re: STM32 [NUCLEO_F411RE] - Missing pyb.usb_mode function

Posted: Mon Jan 13, 2020 4:28 am
by jimmo
For reasons that aren't quite clear to me, many of the Nucleo 4xx boards do not have a USB port on them connected to the 4xx chip (despite the chips supporting USB).

So the MicroPython firmware for these boards disables USB support by default.

The MSC device you see when you connect it to a computer is actually the ST-Link -- the USB port on these boards is only for the ST-Link, which connects to the 411 via UART only.

You could possibly wire a USB cable to DM PA11 / DP PA12, but there's no connector on the board.

Re: STM32 [NUCLEO_F411RE] - Missing pyb.usb_mode function

Posted: Mon Jan 13, 2020 4:34 am
by esologic
Ah bummer. Makes sense, that's what googling for a few hours kind of got me thinking.
jimmo wrote:
Mon Jan 13, 2020 4:28 am
by default.
If I were to add a usb connector for this, do you know what I would have to change in compilation to enable usb support?

Hardware-wise, would I need level shifters or pullup/down resistors anywhere? Or could I directly wire in the usb connector?

Probably could look at some schematics to answer this question...

Thanks so much for the quick response.

Re: STM32 [NUCLEO_F411RE] - Missing pyb.usb_mode function

Posted: Mon Jan 13, 2020 4:49 am
by jimmo
It's mostly just a matter of adding MICROPY_HW_ENABLE_USB to ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.h

The board is otherwise almost identical to the Pyboard Lite 1.0, so take a look at ports/stm32/boards/PYBLITEV10/mpconfigboard.h (and the pyblite schematics). http://micropython.org/resources/PYBLIT ... matics.pdf has exactly the wiring.

Re: STM32 [NUCLEO_F411RE] - Missing pyb.usb_mode function

Posted: Mon Jan 13, 2020 1:02 pm
by esologic
Amazing! Thank you so much. I'll report back w/how surgery goes :D .