/!\ Vorläufig / Preliminary, work in progress /!\

STM32F103 Boards

From company STMicroelectronics there is a powerful low cost ARM®-based 32-bit MCU with 64 or 128 KB Flash, USB, CAN, 7 timers, 2 ADCs, 9 com. interfaces, named STM32F103x8 (64 KByte Flash ROM) and STM32F103xB (128 KByte Flash ROM).

It is interesting that some (most?) STM32F103x8 also have a 128 KByte Flash ROM, explained later.

There are 2 popular boards (3 - 5 EUR) on the market (Ebay, banggood.com, etc.):

Unfortunately boards delivered from China have usually very little documentation for the usage.

I like to explain the usage with the Arduino IDE (version 1.8.5). You find a here Links #4 a Arduino for STM32 Forum.

/!\ I am using the software under Mac OS 10.13.4. The usage should be similar to Linux.

/!\ A mouse click on a picture will expand the picture for better viewing.

/!\ A mouse click on a source program will show the listing in a new window with colour coding.

attachment:STM32_BluePill_DSC07650.jpg

Blue Pill

A good description is at Wiki stm32duino Blue Pill.

A German description of the Blue Pill at Links #3.

attachment:STM32_STLinkV2_DSC07653.jpg

Programming the STM32

  1. Programming with the STLink V2 interface, for ordering see at Banggood for the title "3.3V 5V XTW ST-LINK V2 STM8 / STM32 Simulator Programmer" (about 3 EUR). See the picture on the right, with the 4 wire cable to connect the STM32 board.

  2. With the STLink V2 interface you can use the software openOCD (On Chip Debugging) for debugging and programming.

  3. If the Boot Loader generic_boot20_pc13.bin is installed, you can program the STM32 via USB port with the Arduino IDE.

Following the different methods are explained in detail.

The STMLink V2 interface is connected with 4 wires to the STM32 board programming connector. It also supplies the 3V3 voltage.

# Install on Mac OS with Homebrew (version 1.5.0)
$ brew install stlink
# show manual of flash program
$ man st-flash

# Other checks:
$ st-info --probe
Found 1 stlink programmers
 serial: 543f6b06506650511649173f
openocd: "\x54\x3f\x6b\x06\x50\x66\x50\x51\x16\x49\x17\x3f"
  flash: 131072 (pagesize: 1024)
   sram: 20480
 chipid: 0x0410
  descr: F1 Medium-density device

$ st-info --flash
0x20000           # 131072 bytes

Another documentation for Linux at Links #2 from Roger Clark.

Boot Loader

The board is shipped with a Blink programm in the Flash-ROM, but it no Boot Loader programmed, which enumerates the USB port for Arduino programming and Serial I/O.

# Download Boot Loader file to actual directory, see at "Features" for the Link
# Set Jumper BOOT0 to 1
$ st-flash write generic_boot20_pc13.bin 0x8000000
st-flash 1.4.0
2018-05-02T06:33:00 INFO usb.c: -- exit_dfu_mode
2018-05-02T06:33:00 INFO common.c: Loading device parameters....
2018-05-02T06:33:00 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-05-02T06:33:00 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2018-05-02T06:33:00 INFO common.c: Attempting to write 21140 (0x5294) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08005000 erased
2018-05-02T06:33:00 INFO common.c: Finished erasing 21 pages of 1024 (0x400) bytes
2018-05-02T06:33:00 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-05-02T06:33:00 INFO flash_loader.c: Successfully loaded flash loader in sram
 21/21 pages written
2018-05-02T06:33:01 INFO common.c: Starting verification of write complete
2018-05-02T06:33:02 INFO common.c: Flash written and verified! jolly good!

# Remove STLink cable
# Set Jumper BOOT0 to 0

# Connect Micro USB cable to PC
# Check for USB device
$ ls /dev/cu.u*
/dev/cu.usbmodem14321
# Now Arduino IDE programming is possible 

openOCD

The openOCD software must be used with the STLink V2 interface. The first application is the check for 128KB Flash-ROM in the STM32F103x8 (from data sheet just 64 KB).

See at mikrocontroller.net for the details.

Program openOCD opens a Telnet port 4444 for remote controlling. Start with Terminal #1.

# Install openOCD software with Homebrew
$ brew install openOCD
Installing dependencies for open-ocd: libusb-compat, libftdi, hidapi
 /usr/local/Cellar/open-ocd/0.10.0: 632 files, 4.7MB

# Edit /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/target/stm32f1x.cfg
flash bank $_FLASHNAME stm32f1x 0 0x20000 0 0 $_TARGETNAME
adapter_khz 950

# Press Reset on the board

# Start openOCD Telnet server
$ openocd -f /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/target/stm32f1x.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 950 kHz
adapter_nsrst_delay: 100
none separate
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.247246
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
# waiting for connection via telnet
Info : accepting 'telnet' connection on tcp/4444
# reset halt
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1ffff020 msp: 0x200001fc
# flash probe 0
Info : device id = 0x20036410
Info : ignoring flash probed value, using configured bank size
Info : flash size = 128kbytes
flash 'stm32f1x' found at 0x08000000
wrote 120832 bytes from file /Volumes/DAT/Users/rudi/STM32_JPG_121K.bin in 6.591493s (17.902 KiB/s)
dumped 131071 bytes in 2.795402s (45.789 KiB/s)

# to finish Telnet server press key CTRL C

Prepare a JPG picture with a size of about 120KB (< 128 KB), and rename to .bin (e.g. STM32_JPG_121K.bin).

Open Terminal #2 for control.

# type the commands after the ">" prompt.
# See in Terminal #1 for the answers.

$ brew install telnet # only once
$ telnet localhost 4444
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger

> reset halt
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1ffff020 msp: 0x200001fc
> flash probe 0
> flash write_image erase /Volumes/DAT/Users/rudi/STM32_JPG_121K.bin 0x08000000
> dump_image /Volumes/DAT/Users/rudi/STM32_JPG_121K.jpg 0x08000000 0x1ffff
> exit

# check if dumped image is OK, then the Flash-ROM has 128Kb.

# Restore the Boot Loader

Arduino IDE

Install the STM32 addition:

Board: "Generic STM32F103C series" 
Variant: "STM32F103C8 (20k RAM. 64k Flash)"  or 128k
CPU speed (MHz): "72Mhz (Normal)"
Upload method: "STM32duino bootloader"
Optimize: "Smallest (default)"
Port: "/dev/cu.usbmodem14321 (Maple Mini)"

Hardware issue

The USB standard requires a 1.5 kΩ pullup resistor on D+, but this board is known to have a wrong value (R10 = 10K).

If the USB connection works in your case, it might be OK, otherwise change R10 to a SMD 0805 1.5 KOhm resistor.

Leaf Maple Mini

See the documentation at STM32duino.

The Maple Mini is the second of the two original STM32F103 boards made by LeafLabs. It was released in 2011. The original Maple Mini is no longer available, but several companies make clones, which has virtually identical functionality.

  1. Arduino Software IDE download (Integrated Development Environment), actual version 1.8.5.

  2. Programming an STM32F103XXX with a generic "ST Link V2" programmer from Linux

  3. Keine bittere Pille - die Blue Pill mit ARM Cortex M3

  4. Wiki stm32duino Blue Pill documentation

  5. stm32duino Arduino Forum

{i} Go to Top of the page

Contact Email

Please enter your Email address, if you expect an answer.

/!\ The entered Email address will not be published, or given away.

Comment this page
Name:
Comment:
Are you human?

List of pages in this category:

-- RudolfReuter 2018-05-03 18:02:24


Go back to CategoryTechDoc or FrontPage