Table of Contents
ARM STM32 processors programming
The best working environment for ARM processors is the Linux OS. That is why the following manual describes the installation process and how to handle the tools for work with ARM in this particular system. Linux installation manual.
All the software that is mentioned in this guide can be obtained for free.
Introduction for beginners
A required HW includes:
- ARM processor of your choice with necessary peripherals (STM32F10xRxT)
- Program loading
- Through a serial link (USBRS23201B)
- J-TAG (JTAGFT2232V02A)
A required SW includes:
- SW for writing the code
- Compiler
- Loading of the compiled program
Compiler
You can use a freely available GNU C compiler, obtainable from git repository gcc-arm-embedded.
To help you with the Ubuntu installation it is possible to used a ready-made deb packages. A PPA repository currently works only for Ubuntu version 12.04.
Quick installation using a software repository
sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded sudo apt-get update sudo apt-get install gcc-arm-none-eabi
Compilation procedure
Open a terminal and change the directory to the one containing the compilation files. Start the compilation process using the MAKE command.
GUI
Sublime text
Code::Blocks
sudo apt-get install codeblocks
Libraries
STM32F10X standard peripheral library
The complete proprietary library from STMicroelectronics, suffering form an uncomfortable programming interface and occupying a lot of space in the final program.
It is available for download at STMicroelectronics web site.
libopencm3
A new open-source library with better interface and smaller size, that in unfortunately yet incomplete (though under an ongoing development).
Loading
Bootloader
The use of bootloader is useful in cases when we do not intend to use any additional programming HW and we do not need advanced developmental functions like debugger.
STM32F10xRxT01A module
To activate the bootloader, hold the BOOT key, then press the RESET key and immediately release the BOOT key. It is possible to communicate with the bootloader through USB or UART (using e.g. stm32flash program). For loading the firmware through USB you can use dfu-util, that works for Linux, Mac OS and Windows as well.
Connecting the module
In order to be able to use the bootloader, it in necessary to connect it to the serial link. In the case of using USB232R01B module, it is sufficient to have only RXD and TXD connected in a following way:
USB232R01B | STM32F10xRxT01A |
---|---|
TXD | PA10 |
RXD | PA9 |
Professionals can connect other DTR and RTS signals as well, to get rid of an annoying pressing of the keys during every upload :) (This function requires a modified stm32flash).
stm32flash compilation
svn checkout http://stm32flash.googlecode.com/svn/trunk/ stm32flash-read-only cd stm32flash-read-only make sudo make install
An example of use:
sudo stm32flash /dev/ttyUSB0 stm32flash - http://stm32flash.googlecode.com/ Serial Config: 57600 8E1 Version : 0x20 Option 1 : 0x00 Option 2 : 0x00 Device ID : 0x0418 (Connectivity line) RAM : 64KiB (4096b reserved by bootloader) Flash : 256KiB (sector size: 2x2048) Option RAM : 15b System RAM : 18KiB Resetting device... done.
An example of program loading:
$ ./stm32flash -w ./bin/LED_Blink.hex -v -g 0x0 /dev/ttyUSB0 stm32flash - http://stm32flash.googlecode.com/ Using Parser : Intel HEX Serial Config: 57600 8E1 Version : 0x22 Option 1 : 0x00 Option 2 : 0x00 Device ID : 0x0414 (High-density) RAM : 64KiB (512b reserved by bootloader) Flash : 512KiB (sector size: 2x2048) Option RAM : 15b System RAM : 2KiB Wrote and verified address 0x08000c48 (100.00%) Done. Starting execution at address 0x08000000... done.
dfu-util
The binaries for this utility can be found here: dfu-util
To activate the bootloader through USB, you have to connect + 3,3 V to the PA9 pin. In order to run the bootloader follow the sequence: press RESET, press BOOT, release RESET, release BOOT.
A batch to call the dfu-util on Windows platform and the compiled version of dfu-until without the need to download other libraries can be found here: dfu-util-static. Furthermore, to run the program on Windows, it is necessary to install some version of uslib. The easiest way to do it is to use zadig. In the course of installation, the processor must be in DFU mode (see the key sequence mentioned above).
You can test the firmware loading, using this sample binary, that creates the USB HID mouse out of the STM32F107 processor. STM32F107_mouse.bin
J-TAG
An external programmer is required to program through JTAG. In the case of STM32F10xRxT01A module, the JTAG wires have a special pin-out (J51). The JTAGFT2232V02A module can be used as an external programmer.
For programing is suitable eg. OpenOCD, an open programm that supports the majority of JTAG programmers and is able to create the back-end for GDB, thus supporting the debugging as well.
Ubuntu
Though there already exist natively supported packages for OpenOCD in Ubuntu, their versions are usually quite old compared to the latest development. It is therefore recommended to compile the current version…
sudo apt-get install libtool git gcc automake libftdi-dev texinfo git clone git://git.code.sf.net/p/openocd/code openocd-code cd openocd-code/ ./bootstrap ./configure --enable-maintainer-mode --disable-werror --enable-ft2232_libftdi make sudo make install
To uninstal the OpenOCD, use the following command
sudo make uninstall
If you have a JTAGFT2232V02A module with uploaded FPGA scheme connected to you computer, you can connect to ARM
sudo openocd -f "interface/busblaster.cfg" -f "target/stm32f1x.cfg" Open On-Chip Debugger 0.7.0-rc1-dev-00011-gd9ba56c (2013-04-28-11:46) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Info : only one transport option; autoselect 'jtag' adapter speed: 1000 kHz adapter_nsrst_delay: 100 jtag_ntrst_delay: 100 cortex_m3 reset_config sysresetreq Info : max TCK change to: 30000 kHz Info : clock speed 1000 kHz Info : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3) Info : JTAG tap: stm32f1x.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1) Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Tho OpenOCD has created a server, that you can connect with through telnet
telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger >
Mac OS X
./configure --enable-ft2232_ftd2xx openocd -f busblaster.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg\\
busblaster.cfg:
interface ft2232 ft2232_device_desc "Dual RS232-HS" ft2232_layout jtagkey ft2232_vid_pid 0x0403 0x6010
basic info: http://pramode.net/fosstronics/stm32-circle.txt
RTOS
Chibios
Chibios is a basic realtime OS with HAL component that simplifies the work with a microprocessor. To facilitate the work, a Chibios configuration directly for module with ARM has been created, and it is available at github.
In order to obtain more documentation use ChibiOS/RT site.
LED blink demo
#include <ch.h> #include <hal.h> int main(void) { halInit(); chSysInit(); while (TRUE) { palTogglePad(GPIOB, GPIOB_LED1); chThdSleepMilliseconds(250); } }