September 17, 2016
The hard facts: STM32F103C8T6 ARM STM32 Minimum System Development Boards
After almost a year away from these little boards, I am back at it again and
working up an "executive course" in using these devices.
-
The first thing to know is that the USB connector is useless for anything other
than powering up the board. You cannot program these via the USB connector.
You can load a USB boot loader into the board later (and apparently many people do)
but it does not ship with one.
Someday of course you could write (or obtain) USB drivers for your application
but that is a bridge I have yet to cross.
-
Some of my devices came to me "write locked" with a blink demo in place.
This was inconvenient to say the least. I do all of my development under linux
and none of the tools I had were capable of resetting the lock. I could be
done with a windows tools and I found some other way to do it as well.
-
You can connect a USB to serial gadget to the PA9 and PA10 pins (this is the first
serial port) and use this to program the device. The chip has serial boot code
inside to support this when you get those boot jumpers set right.
I am pretty sure this is what those poor people who use the arduino GUI do.
You need a special program to talk the protocol (see my Github stuff).
-
By far the best way to program these is to get an ST-Link adapter and use the
SWD port (sort of a poor man's JTAG). Along with burning code into flash,
you can do all kind of debugging using remote Gdb and it is quite slick.
-
Even though these devices are sold as having 64K of flash, they actually have
twice that (128K). You should probably be cautious about using the second half
as it may not be fully reliable, but I have had no problems.
How to burn code with openOCD
So, suppose you go to my github repository and download one of the examples.
You type "make" (after going through whatever you need to do to get a compiler
and toolchain setup) and you will get something like "blink.bin" that you want
to flash into a unit. Here is how you do it.
- Grab an STM32F103 board.
- Grab a ST-Link V2 unit and connect it to the four SWD pins on the STM board.
- Connect a USB cable to the ST-Link unit
- Type "make flash"
So, the STM unit is powered from the ST-Link device, which seems just fine.
It doesn't seem to matter where the jumpers are on the STM unit when you do this,
but you will need to put them both to zero to run the code.
This is a much simpler process than I used to use, thanks to the openocd "program"
facility (that is a built in script to do just what I want). I used to have to
open two terminal windows, run openocd in one and a telnet window in the other and
remember commands. The stuff in the Makefile that does this is:
OCDCFG = -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
flash:
openocd $(OCDCFG) -c "program blink.bin verify reset exit 0x08000000"
These paths are correct on my Fedora system.
Note that it not only verifies the code, but also resets the board to run the new code.
Feedback? Questions?
Drop me a line!
Tom's Computer Info / [email protected]