In this tutorial I provide a template project based on the Hello world! project with a generic Makefile that is easily-customizable. This reduces the overhead to create the project environment, because you may change, add or remove source files without modifying the Makefile, just like Spock it has one facial expression/one Makefile for many feelings/many projects. 🙂
- Ubuntu 14.04 LTS (x86 architecture).
- STM32F4 Discovery Board (ARM architecture, costs less than 20 EUR).
2. Install Software Dependencies
Use third party GCC suite rather than official, because the latter currently (Aug 2014) lacks C++ library.
cd ~ # Remove the official package sudo apt-get purge binutils-arm-none-eabi \ gcc-arm-none-eabi \ gdb-arm-none-eabi \ libnewlib-arm-none-eabi # Add 3rd party repository sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded sudo apt-get update # Check the GCC package version in the PPA repository sudo apt-cache policy gcc-arm-none-eabi # Install software requirements sudo apt-get install build-essential git openocd \ gcc-arm-none-eabi qemu-system-arm \ symlinks expect # Clone my git repository & init submodules git clone https://github.com/istarc/stm32.git cd ~/stm32 git submodule update --init
3. Build and deploy the template project
The project tree below describes the project structure. It is based on the “Hello World!” project.
cd ~/stm32/examples/Template # tree # . # ├── bin # DON'T TOUCH # ├── inc # DON'T TOUCH # │ ├── CMSIS/Include # │ ├── stm32f4_discovery.h # │ ├── STM32F4xx/Include # │ ├── stm32f4xx_conf.h # │ ├── stm32f4xx_it.h # │ └── STM32F4xx_StdPeriph_Driver/inc # ├── src # DON'T TOUCH # │ ├── main.c # │ ├── misc.c # │ ├── startup_stm32f4xx.s # │ ├── stm32f4_discovery.c # │ ├── stm32f4xx_exti.c # │ ├── stm32f4xx_gpio.c # │ ├── stm32f4xx_it.c # │ ├── stm32f4xx_rcc.c # │ ├── stm32f4xx_syscfg.c # │ └── system_stm32f4xx.c # ├── Makefile # DON'T TOUCH # └── stm32_flash.ld
The template should automatically adjust to your project changes as long you keep the directory structure intact, i.e. bin, inc and src folders.
- You may add or remove header files (*.h) from the inc folder, add subdirectories or even use symbolic links. The Makefile script automagically finds appropriate files. 😉
- You may add or remove C (*.c) or Assembly (*.s) source files from the src folder, add subdirectories or use symbolic links.
- Don’t touch the Makefile unless, unless necessary.
- Build and deploy the project as follows.
make clean && make -j4 # Size optimized build # Other build options # make clean && make -j4 release-memopt # Size opt. build # make clean && make -j4 release # Non-optimized build # make clean && make -j4 debug # Debug build sudo make deploy # Deploy on ST32F4XX target platform
Q: Deployment fails repeatedly due to some OpenOCD issue. 😦 Is there a workaround?
A: Yes, the current official Ubuntu package (Aug 2014) contains a prehistoric OpenOCD version. You should build a newer version from scratch. I provide step-by-step instructions here (2nd section, it takes less than 3 minutes to build it). When you are done, just return here and continue as nothing happened. It will work out of the box. 🙂
This generic template is useful, because it eases project building. However, it leaves you on your own at project setup. It is your responsibility to add source files, appropriate libraries, etc. Because project initialization is time-consuming task as well, I provide a project wizard that accomplishes this for you in no time. 😉