Differences between revisions 7 and 8
Revision 7 as of 2018-05-06 06:17:47
Size: 17402
Editor: RudolfReuter
Comment: DFU explanation added
Revision 8 as of 2018-05-06 12:54:21
Size: 17929
Editor: RudolfReuter
Comment: added USB reconnect issue
Deletions are marked like this. Additions are marked like this.
Line 34: Line 34:

/!\ The '''Maple Mini''' board has a hardware and software provision to re-enumerate the '''USB-port''' after flashing an Arduino program to Flash-ROM. Unfortunately it does '''not''' at least under Mac OS. There are two tries to solve that, [[http://www.stm32duino.com/viewtopic.php?f=32&t=1307|Bootloader - a pin for the usb d+ disconnect]] and [[http://www.stm32duino.com/viewtopic.php?t=780|Blue Pill with USB disconnect circuit added]], but for me it is sufficient to re-plug the USB cable after flashing the STM32.
Line 85: Line 87:
 * USB idendity: VID 0x0483 PID 0x3748  * USB identity: VID 0x0483 PID 0x3748
Line 239: Line 241:
 * Compile and upload (programm Flah-ROM)  * Compile and upload (programm Flash-ROM)
Line 347: Line 349:
 * In Aduino menu->Tools setup:  * In Arduino menu->Tools setup:

/!\ 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.):

  • STM32F103C8T6 Small System Board Microcontroller, nick name Blue Pill.

  • STM32F103RCBT6 ARM Cortesx-M3 Leaf Maple Mini Module.

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

  • Benefits:

    • Low cost (usually below 10 EUR)
    • Small size
    • Can be battery powered
    • Software Development under Arduino IDE (Integrated Development Environment) via USB port
  • Drawbacks:

    • Has no EEPROM included, if you are using a LCD it may have a SD-card interface

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.

/!\ The Maple Mini board has a hardware and software provision to re-enumerate the USB-port after flashing an Arduino program to Flash-ROM. Unfortunately it does not at least under Mac OS. There are two tries to solve that, Bootloader - a pin for the usb d+ disconnect and Blue Pill with USB disconnect circuit added, but for me it is sufficient to re-plug the USB cable after flashing the STM32.

/!\ 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.

  • Features
    • Model: STM32F103C8T6
    • Kernel: ARM32 bit Cortex™-M3CPU
    • 8 MHz crystal oscillator
    • 32.768 KHz crystal oscillator
    • Size: 22.9 mm x 53.4 mm
    • 40 pins Dual In Line (DIL), different pin layout to Maple Mini

    • Debug Mode: SWD (Serial Wire Debug), use software openOCD,

    • 4 pin connector for STLink V2 Simulator Programmer Downloader

    • Micro USB connector, for 5V power supply, serial I/O and programming (Arduino IDE)

    • Boot mode jumper (programming / operation)
    • LED green on port PC13

    • No USB disconnect signal

    • Needs Bootloader for Arduino USB port programming, generic_boot20_pc13.bin

    • No separate 3V3 supply for the analog part of the CPU

  • MCU Introduction
    1. Maximum operating frequency 72MHz
    2. Single-cycle multiply and hardware divide
    3. 64k or 128 Flash program memory
    4. 20k bytes SRAM
    5. 2.0-3.6V power supply and I/O pins
    6. Power On Reset (POR / PDR), programmable voltage detector (PVD)
    7. 4-16 MHz crystal oscillator
    8. PLL (Phase Locked Loop) for CPU clock
    9. Sleep, Stop and Standby modes
    10. VBAT power supply for the RTC (Real Time Clock) and backup registers
    11. 37 I/O ports, the I/O ports can be mapped to 16 external interrupts vectors, some are 5V tolerant

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.

  • USB identity: VID 0x0483 PID 0x3748
  • Jumper BOOT0 must be set to 1 for DFU upload mode, see at Links #6

  • with Arduino USB port Upload method: "STM32duino bootloader" jumper BOOT0 must be 0
  • Install utility stlink

# 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.

  • Install Boot Loader with STLink V2 interface:

# 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:

  • Arduino menu->Sketch->include library->administrate library - Install A_STM32_Examples

  • Restart Arduino IDE (V. 1.8.5)
  • Load program Arduino menu->Files->Examples->01.Basics->Blink

  • Replace LED_BUILTIN by PC13

  • In Aduino menu->Tools setup:

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)"
  • Compile and upload (programm Flash-ROM)
  • Replug the Micro USB cable.
  • Check, if the green LED blinks.

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.

attachment:STM32_Maple_Mini_Top_DSC07654.jpg

Leaf Maple Mini

See the documentation at STM32duino.

The Maple Mini is the second of the two original STM32F103 boards made originally 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.

  • Features
    • Model: STM32F103CBT6
    • Kernel: ARM32 bit Cortex™-M3CPU
    • 8 MHz crystal oscillator
    • No 32.768 KHz crystal oscillator

    • Size: 22.9 mm x 53.4 mm
    • 40 pins Dual In Line (DIL), different pin layout to Blue Pill

    • Debug Mode: SWD (Serial Wire Debug), use software openOCD,

    • No 4 pin connector for STLink V2 Simulator Programmer Downloader, connect to DIL pins J2,11 SWDCLK, J2,10 SWDIO

    • Mini USB connector, for 5V power supply, serial I/O and programming (Arduino IDE)

    • No Boot mode jumper (programming / operation), instead Push button on BOOT0

    • LED blue on port PB1

    • No power LED

    • Push (3V3) button on port PB8 and BOOT0, J2 pin 18

    • USB disconnect signal from port PB9

    • Separate 3V3 supply for the analog part of the CPU, AV+ at pin J1,1, AV- ar pin J1,2

      • Unfortunately the clone boards from China does not have the second 3V3 regulator

Access to Maple Mini

The Maple Mini clone should come with a flashed Boot Loader, and should enumerate via USB port.

Unfortunately not. What is next: try with STLink V2 to flash a bootloader. Also not possible.

Next an USB-UART converter on STM32 port RX1 and TX1, see Maple Mini bootloader flashing. Now I got access to the Maple Mini clone, but it did not flash, see:

Got NACK from device on command 0x43  
Can't initiate chip mass erase!
Failed to erase memory

An internet search brought Re: Can't initiate chip erase. You first have to Disable the flash read-protection, then you can flash the STM32. Now the handling in the working sequence with an 3V3 USB-UART converter:

# Connect at Maple Mini port BOOT1 J2,4 to GND
# USB-UART - Maple mini
  RXD  -     RX1 J1, 6
  TXD  -     TX1 J1, 7
  3V3  -     VCC
  GND  -     GND
# Note: RXD, TXD may be swapped, depending on the type of the USB-UART converter

# Bring the STM32 into flash mode (DFU upload mode):
  Press RESET + BOOT0 button -> release RESET -> release BOOT0

# Disable the flash read-protection
$ stm32flash  -k /dev/cu.SLAB_USBtoUART # device name may be different
stm32flash 0.5

Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : 20KiB  (512b reserved by bootloader)
- Flash      : 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Read-UnProtecting flash
Done.

# Flash the Boot Loader, to allow access via USB port
$ stm32flash  -w maple_mini_boot20.bin /dev/cu.SLAB_USBtoUART
stm32flash 0.5
...
Using Parser : Raw BINARY
Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : 20KiB  (512b reserved by bootloader)
- Flash      : 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x0800501c (100.00%) Done.

# remove all connections and plug in a Mini USB cable to the PC
# Check for USB port access
$ ls /dev/cu.u*
/dev/cu.usbmodem143141  # USB enumeration works now, OK

# Now the Arduino IDE access works

Arduino IDE

Install the STM32 addition:

  • Arduino menu->Sketch->include library->administrate library - Install A_STM32_Examples

  • Restart Arduino IDE (V. 1.8.5)
  • Load program Arduino menu->Files->Examples->01.Basics->Blink

  • Replace LED_BUILTIN by PB1

  • In Arduino menu->Tools setup:

Board: "Maple Mini" 
CPU speed (MHz): "72Mhz (Normal)"
Bootloader version: "Bootloader 2.0 (20K RAM, 120k Flash)"
Optimize: "Smallest (default)"
Port: "/dev/cu.usbmodem143141 (Maple Mini)"
  • Compile and upload (programm Flash-ROM)
  • Replug the Mini USB cable (seems to be that the USB disconnect does not work)

  • Check, if the blue LED blinks.

  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

  6. Explanation for the DFU upload mode

{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

STM32F103Board (last edited 2018-05-23 12:53:25 by RudolfReuter)