Tag Archives: MikroC Pro for ARM

Porting ST Standard Peripheral Library (SPL) with MikroC PRO for ARM

What is this Standard Peripheral Library (SPL)?

It’s just a collection of hardware libraries that provide an easy approach to any STM32 ARM programmer. It has support for every peripheral a STM32 micro has like CAN, USB, ADC, Timers, etc. In short it’s a hardware abstraction layer fully covering the STM32.

Why use the ST SPL?

  1. Reduce coding time by spending less time figuring out 32 bit register values and going through a near thousand page reference manual.
  2. Take the advantages of the built-in code library of MikroC which other compilers don’t offer.
  3. SPL is used by most STM32 ARM programmers and so it is a widely used tool with a large community.
  4. Most books and documents on STM32 ARMs are based on SPL.
  5. A compiler like MikroC doesn’t give full focus towards STM32. It has other ARM concerns like TI’s TIVA, NXP, etc and so MikroC’s built-in libraries are not 100% compatible with all ST hardware.
  6. Following the previous point MikroC (at least at the time of writing this article) doesn’t give library support for hardware like the DMA and so there’s incompleteness to some extent. It is also worth noting that depending on MikroC’s library also has the disadvantage of code size and efficiency. It is in general true for every compiler. However MikroC’s IDE is cool enough to do things with ease and that’s why I like it. Unless you are a Maple or Arduino fanboy, you’ll get my point.

Software Needed

  1. Modified ST Standard Peripheral Library (SPL) as supplied here: STM32 Standard Peripheral Library for MikroC. It works for STM32F10x micros only.
  2. MikroC PRO for ARM compiler.
  3. Flash Loader Demo or ST-Link Programmer Software.

Hardware Needed

  1. A STM32F10x Development Board.
  2. A USB-Serial Converter or ST-Link Programmer.
  3. Some basic components like a mini bread board, connecting wires/jumpers, a LED, a 220Ω 0.25W resistor and a push button.
  4. Optional debugger hardware.


How to use the Standard Peripheral Library?

First we need to prepare our MikroC PRO for ARM compiler for linking with SPL. I’m assuming that the compiler is preinstalled. First go to the compiler’s installation folder and look for the include folder. In my case, it is:
C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for ARM\Include.

In this folder there’s a file named stdint.h. It’s basically a definition of variable types and other related stuffs. Rename it to stdint (backup).h and copy the new stdint.h file from the supplied folder to this location. We are done here.

stdint modification

Read more

Recent Entries »