Adsense HTML/JavaScript

Friday, January 22, 2021

Flash CircuitPython to STM32F411, and install Thonny IDE on Ubuntu 20.10

This post show the steps to flash CircuitPython 6.1.0 to STM32F411 dev. board, and install Thonny IDE on Ubuntu 20.10. Tested on VirtualBox 6.1/Windows 10.

The target board is a STM32F411CEU6 minimum development board, it should be compatible with STM32F411CE Black Pill, I guess.

Visit CircuitPython Download page to download CircuitPython match your board. It's "STM32F411CE Black Pill" in my case.

Install dfu-util:
dfu-util is a program that implements the host (computer) side of the USB DFU (Universal Serial Bus Device Firmware Upgrade) protocol. DFU is intended to download and upload firmware to/from devices connected over USB. It ranges from small devices like micro-controller boards to mobile phones. Using dfu-util you can download firmware to your DFU-enabled device or upload firmware from it.

$ sudo apt install dfu-util

You can list the currently attached DFU capable USB devices with -l option:

$ sudo dfu-util -l

Flash downloaded CircuitPython bin to STM32F411:

$ sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D <circuitpython bin file>

After flashed, in my try, have to un-plug and re-plug the USB of the STM32F411 Dev.board, to make it recognized. A new driver "CIRCUITPY" appear.

Install Thonny IDE:

$ sudo apt-get install python3-pip
$ sudo pip3 install thonny
$ sudo apt install python3-tk

And add yourself to the 'dialout' group:

$ sudo usermod -a -G dialout <user>

After installed, you can run thonny by enter "thonny" in Terminal.

cpyHelloSTM32F411.py, the testing circuitpython code run in the video.
import os
import microcontroller
import board
import digitalio
import time

print(os.uname())
print()
print("microcontroller.cpu.frequency:\t\t" + str(microcontroller.cpu.frequency))
print("microcontroller.cpu.temperature:\t" + str(microcontroller.cpu.temperature))
print("microcontroller.cpu.voltage:\t\t" + str(microcontroller.cpu.voltage))

print("\ndir(board):")
print(dir(board))

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(0.3)
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(0.3)
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(1.5)


Extra remark about using USB Device Filters for VirtualBox:

You can create filters for specified USB devices. Matched USB devices will be automatically passed to the guest once they are attached to the host. Such that you need not manually pass to guest everytime the USB device attached.





Example of STM32F411/CircuitPython: 

More Exercise of STM32F411/CircuitPython 7:

No comments:

Post a Comment