STM32 dev
Description
Notes on STM32 microcontrollers and on how to get them working in DIY projects.
/// this is a work in progress draft ///
Software Tools
All about software tools for STM32 dev. Development environments, compilers, debuggers, IDEs etc.
STM32CubeMX on Linux
STM32CubeMX is a code generator for STM32 micros that can come in handy when you start a new project. It generates all the necessary init and HAL code, library and custom pin mux code etc for that specific MCU.
Unfortunately, it comes as a Windows EXE and ST doesn't mention that it is a Java application. Luckily it can be installed on Linux by hand (thanks to Joe's great note there):
- Download STM32CubeMX.
- Install the application (tested in January 2016):
$ unzip SetupSTM32CubeMX-4.12.0.exe -d stm32cube $ cd stm32cube $ java -cp . com.izforge.izpack.installer.bootstrap.Installer
- Run:
$ cd <install_dir> $ java -cp . java -cp . com.st.microxplorer.maingui.STM32CubeMX
Convert STM32CubeMX generated project to GCC/Makefile
For whatever reason, STM32CubeMX does not export plain GCC/Makefiles along with the initialization code. Instead, it supports an unpopular IDE called SW4STM32, which is based on free GNU tools. So after installin STM32CubeMX, these are the steps to get the GCC/Makefile project running:
- Install arm-gnu-none-eabi- toolchain for your OS. On Arch Linux:
$ sudo pacman -S arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-binutils arm-none-eabi-newlib
- Get this nice Python script to generate the Makefile for an exported SW4STM32 project.
$ git clone https://github.com/baoshi/CubeMX2Makefile $ cd CubeMX2Makefile $ python2 CubeMX2Makefile.py <your_sw4stm32_prject_dir> $ cd <your_sw4stm32_prject_dir>
- Modify the Makefile (tested in January 2016). Look for __weak and remove the backslashes (needed, at least in Bash). More can be read here.
$ grep __weak Makefile C_DEFS = -D__weak="__attribute__\(\(weak\)\)" -D__packed="__attribute__\(\(__packed__\)\)" -DUSE_HAL_DRIVER -DSTM32F072xB $ sed -i 's/\\(\\(weak\\)\\)/((weak))/g' Makefile $ sed -i 's/\\(\\(packed\\)\\)/((packed))/g' Makefile $ grep __weak Makefile C_DEFS = -D__weak="__attribute__((weak))" -D__packed="__attribute__\(\(__packed__\)\)" -DUSE_HAL_DRIVER -DSTM32F072xB
- Then make the binary:
$ make (...) arm-none-eabi-size build/STM32F072RBT6.elf text data bss dec hex filename 4568 12 1572 6152 1808 build/STM32F072RBT6.elf arm-none-eabi-objcopy -O ihex build/STM32F072RBT6.elf build/STM32F072RBT6.hex arm-none-eabi-objcopy -O binary -S build/STM32F072RBT6.elf build/STM32F072RBT6.bin
Flash
Install OpenOCD and STLINK. On Arch Linux.
sudo pacman -S stlink openocd
Now openocd and (arm-none-eabi-)gdb can be used to program and debug the MCU!
Debugging
/todo
The power of raw (arm-none-eabi-)gdb -tui DDD IDE?
Hardware
/todo
Minimal STM32 JTAG Serial .....
Projects
/todo
bare metal hello blink I2C peripherals I2S peripherals SPI peripherals touch usb .....