Difference between revisions of "STM32"

From RevSpace
Jump to navigation Jump to search
(Setting up the tool chain)
(Platform IO)
Line 63: Line 63:
  
 
=== Platform IO ===
 
=== Platform IO ===
 +
Platformio allows you to build/upload/monitor Arduino programs without using the Arduino IDE (and more).
 +
All settings (which target, which libraries, etc) are stored in a platformio.ini file (instead of existing only as selections in the Arduino IDE).
 +
 
Below is an example platformio configuration for a blue pill with the USB bootloader.
 
Below is an example platformio configuration for a blue pill with the USB bootloader.
 
Save this to a file named platformio.ini in the directory where the .ino file is, and run it with 'pio run'.
 
Save this to a file named platformio.ini in the directory where the .ino file is, and run it with 'pio run'.
Line 70: Line 73:
 
src_dir = .
 
src_dir = .
  
[env:bluepill_f103c8]
+
[env:default]
 
platform = ststm32
 
platform = ststm32
 
board = bluepill_f103c8
 
board = bluepill_f103c8

Revision as of 11:02, 28 February 2019

Project STM32
HTB1PemDJpXXXXXHXpXXq6xXFXXXM.jpg
STM32 setup guide
Status In progress
Contact bertrik
Last Update 2019-02-28

Introduction

Bluepill.jpg

This page is about inexpensive microcontroller boards containing an STM32 processor and how to get them to work.

You can find these boards on AliExpress for less than €2,- if you search for "stm32f103c8t6". Yet they have nice specifications, see also http://www.st.com/en/microcontrollers/stm32f103c8.html

To name a few:

  • 32-bit ARM Cortex-M3 processor running at up to 72 MHz
  • 128 kB flash memory, 20 kB SRAM
  • USB and CAN controllers
  • 32 kHz crystal for RTC
  • dual 1 us A/D converter, DMA controller
  • the usual stuff like SPI, UART, I2C

They are even Arduino compatible, see:

Another, very similar, guide to getting started with STM32 and Arduino.

Although it is possible to program the board over the serial port for every iteration of your application, I recommend to install the STM32duino bootloader. This way, you only need to wire up a USB/serial conversion board and set/reset jumpers only once for bootloader installation and from that point on you can program the board over USB.

Setting up the tool chain

This describes the steps I did to get a "blue pill" board to work on Debian Jessie.

Linux specific

Some things I suspect may make things more smooth:

  • the usual stuff to add your user to the 'dialout' group so you have permission to access the serial port
 sudo adduser <username> dialout
  • uninstall the 'modemmanager' package, it suspect it interferes with the serial port device created by the STM32duino bootloader
 sudo apt-get autoremove modemmanager
  • it may help you to install 32-bit libraries if you're on a 64-bit OS but using the 32-bit binaries
 sudo apt-get install libc6-i386

Arduino IDE

Steps to set up the IDE:

  • get and install the latest Arduino IDE from here.
  • under menu Tools / Board / Board Manager, search for "zero" and install the Arduino Zero toolchain
  • get the Arduino_STM32 source code, for example, run in the console:
cd ~/code
mkdir stm32
cd stm32
git clone https://github.com/rogerclarkmelbourne/Arduino_STM32
  • create a symlink to the Arduino_STM32 source tree in your ~/Arduino/hardware directory, for example:
cd ~/Arduino/hardware
ln -s ~/code/stm32/Arduino_STM32 .
  • restart the Arduino IDE.

Platform IO

Platformio allows you to build/upload/monitor Arduino programs without using the Arduino IDE (and more). All settings (which target, which libraries, etc) are stored in a platformio.ini file (instead of existing only as selections in the Arduino IDE).

Below is an example platformio configuration for a blue pill with the USB bootloader. Save this to a file named platformio.ini in the directory where the .ino file is, and run it with 'pio run'.

[platformio]
src_dir = .

[env:default]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = dfu

Hardware

Bluepill pinout.png

The hardware I'm using, is the blue pill, I soldered on the headers for easy plugging with dupont-wire.

Flashing the USB bootloader

The USB bootloader makes it easy/fast to upload new software into the board.

You need a USB-serial converter for this.

Wire it up as follows:

  • converter 5V -> board 5V
  • converter GND -> board GND
  • converter RXD -> board A9
  • converter TXD -> board A10

Set the BOOT0 jumper to the "1" position and the BOOT1 jumper to the "0" position, then push the reset button.

For the blue pill the steps to install the bootloader are as follows:

  • cd into the directory Arduino_STM32/tools/linux/stm32flash
  • disable the flash-read protection:
 ./stm32flash /dev/ttyUSB0 -k
  • flash the bootloader:
 ./stm32flash -w ~/code/stm32/STM32duino-bootloader/binaries/generic_boot20_pc13.bin -v -g 0x0 /dev/ttyUSB0
  • return both BOOT jumpers to the "0" position.

Software

To load your application using the Arduino IDE:

  • in the Arduino IDE, under menu Tools / Board, select "Generic STM32F103C Series"
  • in the Arduino IDE, under menu Tools / Upload Method, select "STM32duino bootloader"
  • use the following program to blink the on-board LED:
#define pinLED PC13

void setup() {
  pinMode(pinLED, OUTPUT);
}

void loop() {
  digitalWrite(pinLED, HIGH);
  delay(200);
  digitalWrite(pinLED, LOW);
  delay(100);
}
  • ctrl-U to upload it to the board, the program will start automatically

Future work

Actually build something with an STM32!

Ideas:

  • a LoRaWAN node for The-Things-Network
  • a bat call recorder, this thing is faster and has more memory than the LPC2148 in my previous bat call recorder prototype

Investigate the Blackmagic debugging firmware. This should allow you to debug your applications (e.g. step through code in an IDE such as eclipse). See also: