Wednesday, August 14, 2019

MicroPython on a cheap STM32F4 board

Hi folks.

It's been awhile.

And this post will have very little to do with SDR.

I made the cross-country move a year ago and we've settled into our new home. We've started up a combat robotics club ( Angry Rooster Robotics ) and held out first combat event. I'm currently working on some robots that will require a bit more computational power than my previous bots based around Arduino systems, but a Raspberry Pi is overkill. So I've taken the blue pill...


...a STM32F103 featuring a 32 bit Cortex-M3 running at 72 MHz. It's programmable with Arduino, so my existing code ports over somewhat painlessly. I also splurged and bought a "black board"




to play around with MicroPython. Which is the crux of this post. Here's how to get microPython working on a black board. I didn't do the heavy lifting to figure this out but I'd like to piece together a few different sources to help you be successful.

Quick aside - my primary desktop machine is Ubuntu. My laptop is Windows 10. I've recently been playing with Windows Subsystem for Linux (WSL) and I've been very happy with it for light development work. With the latest updates to Windows 10 it works seamlessly with Windows Explorer and the VS Code extension is fantastic. Aside aside...

1. Install Micropython. The wiki instructions are spot-on.
2. Install pyusb "pip install pyusb"
3. Set udev rules for the black board
3.1. Put the black board in DFU Mode by jumping BTO to 3v3
3.2. Look for the output from lsusb (first call, below). You are looking for "STMicroelectronics STM Device in DFU Mode. You need the manufacturer ID, mine is "0483"




3.3. Add the following udev rule to file "99-stm32.rules" in /etc/udev/rules.d/

SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", MODE="0666"

3.4. Restart udev rules. In a console,

sudo udevadm control --reload
sudo udevadm trigger

4. Install the board definitions, build and deploy the black board firmware. 
5. Remove the jumper from BT0 to 3v3 and connect it from BTO to GND. Note now that a fresh "lsusb" will show an unlabeled device (second output, above).
6. Enjoy MicroPython!

It is important to note that the full Python feature set is not supported, by design and by limitations. This wiki article does a good job of enumerating the differences.