Automation Ninja's Dojo

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!

stm32_minimallibs_01

 

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

stm32_minimallibs_02

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

stm32_minimallibs_04

 

Get following files into the project directories:

 

Modify project settings

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

stm32_minimallibs_05

 

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

 

Compile and you are ready to flash your device.

 

 

Caveouts

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!

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: