STM32 VLDISCOVERY
Using STM32 VLDISCOVERY with GNU/Linux tools
In this tutorial I will try to explain basic steps you have to do to successfully program STM32 microprocessor using GNU/Linux tools.
What is STM32 VLDISCOVERY
STM32 VLDISCOVERY is low-cost STM32F100 (ARM Cortex-M3) development board. There is ST-link programmer on the board, which is not supported under Linux.
How to write source code
Download example project
You can write your source code in whatever text editor you like. Life will be much easier when you use:
- STM32 hardware specific header file (stm32f10x.h in example project)
- C Startup code (included in example project)
How to compile your program
You will need to have GCC ARM cross compiler and tools installed on your computer (Cross_compilers)
Use Makefile (and stm32.ld) from example project. To compile run:
make
How to flash it
There are many possible ways how to flash STM32 microprocessor embedded on STM32 VLDISCOVERY board.
- Using ST-Link (
Windows only), UPDATE: There is a project on GITHub called texane/stlink which supports STLink interface to program from Linux. How deal with doggy usb-storage class look-like of STLink is described in the Readme file. - Using bootloader
- Using JTAG
- (Using SWD?)
Flashing using bootloader
Nice tutorial how to use bootloader.
To use bootloader, you have to:
- Change logic value of BOOT0 pin
- Have USB<->USART convertor (with TTL logic levels) or ...
- (Have USB<->RS232 convertor + MAX232 logic level convertor)
- Use Stm32flash
Flashing using ST-Link
- download and build tool from: https://github.com/texane/stlink
Flashing using JTAG
U will need JTAG debugger/programmer. This tutorial is for FTDI2232_JTAG debugger only.
For flashing microprocessor
- Install openocd on your computer (compiling newest version preferred)
- Copy openocd.cfg from example project into your working directory
- Connect JTAG programmer to your computer (without connecting it to microprocessor)
- Run
make openocd
- If the output is like
... make: *** [openocd] Error 1
Try to reconnect JTAG programmer and rerun the command mentioned above.
- If it writes something like
... Polling target failed, GDB will be halted. Polling again in 1500ms
Hit Ctrl+C and connect JTAG to microprocessor, then rerun the command. The output should be like
... Info : clock speed 1000 kHz Info : JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3) Info : JTAG tap: stm32.bs tap/device found: 0x06420041 (mfg: 0x020, part: 0x6420, ver: 0x0) ...
- Open another console. Copy stm32-prog.script into your working directory. Run
telnet localhost 4444
Inside telnet run
script stm32-prog.script
The output should be something like
> script stm32-prog.script JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3) JTAG tap: stm32.bs tap/device found: 0x06420041 (mfg: 0x020, part: 0x6420, ver: 0x0) target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc device id = 0x10016420 flash size = 128kbytes stm32x mass erase complete wrote 400 bytes from file main.elf in 0.165895s (2.355 KiB/s) JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3) JTAG tap: stm32.bs tap/device found: 0x06420041 (mfg: 0x020, part: 0x6420, ver: 0x0)
And your application is running on the microprocessor
How to debug
It should be possible to use GDB (run "make gdb" in example project directory), but I had some problems (with breakpoints etc.).
I used mostly USART and LEDs for debugging.
Tips & Tricks
Be aware of pins PC13, 14, 15 -- they are not regular IO pins (for more information see chapter "4.1.2 Battery backup domain" in STM32 VLDISCOVERY manual).
Pins PA13, PA14, PA15, PB3 and PB4 are used for JTAG and SWD, so they can't be (easy) used as GPIO.