STM32 – minimal libraries project

Hey! So you most likely here because you would like to challenge yourself and try to program 32bit microcontrollers using minimal amount of libraries ( HAL/CMSIS ). On the internet you will find multiple discussions which approach to use – I will not be touching that – I guess everyone has his own way 😉

We will starting by shortly discussing environment used and then we will move on to configuring our project. I will be using for this STM324F407 discovery board – but with the right changes you will be able to adjust it to your own needs.

I will cover in this post:

  • Creating new project in Eclipse
  • Setting all libraries
  • Setting project & compilator settings

Before you start you should have


This project will use several files i.e. startup file / linker script and several header files.


Setting up project

Go ahead and create new ARM project. Here we will not be using any ‘Hello world’ or prepared examples – we start blank!



Here just go through the wizard and finish. When done we will move on getting extra files we need for our project.


Create folders inside the project folder so the structure will look as follow


Download firmware using STM32Cube

Now we need to start our STM32Cube to get all files we will need to move on with our project. Go to help -> install new libraries and then select the firmware for your cortex. For me it will be for STM32F4



Get following files into the project directories:

├── cmsis
│   ├── include
│   │   ├── cmsis_gcc.h
│   │   ├── core_cm0plus.h
│   │   ├── core_cm4.h ** THIS IS BASED ON YOUR CORTEX!! If you have different take different lib file !! **
│   │   ├── core_cmFunc.h
│   │   ├── core_cmInstr.h
│   │   └── core_cmSimd.h
│   └── src
├── include
├── src
│   └── main.c ( this is file created by you )
└── system
    ├── include
    │   ├── stm32f407xx.h
    │   ├── stm32f4xx.h
    │   └── system_stm32f4xx.h
    └── src
        ├── startup_stm32f407xx.s
        └── system_stm32f4xx.c


Modify project settings

Now since we have all the files we need your project should look similar to the following



We will now go and modify several project settings. Open project preferences and make required modifications

  • Change extension used by assembler source file to be *.s ( it’s project specific setting )stm32_minimallibs_06
  • Change to appropriate cortex family modelstm32_minimallibs_07
  • Modify preprocessor definitions to match your processor ( this settings in image below are for STM32F407VGx )stm32_minimallibs_08
  • Modify includes in Assembler and Compiler so it contains “${ProjDirPath}/cmsis/include” and “${ProjDirPath}/system/include
  • Under Linker -> General have the following ${ProjDirPath}/STM32F407VGTx_FLASH.ld ( if you are using different MCU then you will need to change this )
  • Modify paths which include source codestm32_minimallibs_09


Blink the diode

So now you are in position to just blink the diode using the following code in main.c

 * main.c
 *  Created on: 12 Nov 2016
 *      Author: rafpe
#include "stm32f4xx.h"
#include "stm32f407xx.h"

int main(void)
	volatile uint32_t delay;

	RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD


	GPIOD->MODER = (1 << 26); // set pin 13 to be general purpose output

	while (1)
		for (delay = 1000000; delay; delay--)
			GPIOD->ODR ^= (1 << 13);


Compile and you are ready to flash your device.




Given all setup here we are HSI is used as system clock source. We will definitely come back to this as we will need more than i.e. 16 Mhz! Happy coding!






Using STM32CubeMX on MacOS

When it comes to using multiple tools to program/develop it can be sometimes challenging to have them running in single OS. Might be that you would end up having virtual machine running some of your tools – which of course – does not make it easier at all!

One of tools that I really have need of using ( when it comes to development of 32bit microcontrollers ) is STM32CubeMX. If you have not clue what that tool does – in short – it is GUI which allows for quick configuration of microcontroller and its peripheral. It is nice at the end to generate you the code in selected IDE project format ( we will come back to alternate use of this in one of next posts )

Download the software

We will start off with downloading the software. Go STM32CubeMx download page  and scroll down to the bottom. You will find the download option for the software there



Page requires you to create account – but that is part which I leave completely up to you 😉


Install software

Once downloaded on our Mac it would be great to just go ahead and install. If you open folder you will see the following files.



For obvious reasons you will start the ‘application’ file which in return will open the installer



The installation is like ‘camera’ – just next => next=> done! The only thing you need to do now is to open it and use it features!


Use the app



I hope this will get you and your toolkit on the right track! Enjoy coding!





Setup for AVR development on MacOS


So today we look into something which I really was looking for recently. In nutshell it is setup of required components which are necessary to program AVRs on our MacOS.

Here I assume you for sure already have HomeBrew installed as it will be our main point of software installation.


Add new tap

brew tap osx-cross/avr

Install avr-gcc

brew install avr-libc

This one will install avr-binutils and avr-gcc. The avr-gcc installation takes time as it is compiling … so make ur self your favourite drink here 😉


Install avrdude

brew install avrdude --with-usb


Avrdude error when loading MCU in Eclipse

If you have error when using Eclipse and avrdude it seems that the AVR plugin has not been updated for a while. Although this does not affect programming can be easily solved. My friend sanderv32 has created a really nice AVRdude wrapper which solves this problem once and for all!

You can find his repo here => https://github.com/sanderv32/avrdude-av


Happy coding!