I want to write code in just a text editor (not an IDE) and then build it with a simple Makefile.

I've got:

I tried googling for such Makefiles, but most of them are written for older versions of CMSIS (for example, STM32Cube lacks stm32f10x.h and stm32f10x_conf.h which most build systems rely on).

Please, tell which compile commands should I use to compile code for STM32F103 and where to define the frequency, memory density other chip specific constants.

I would also be grateful if you share example of Makefile that uses texane's stlink utility to detect density and ram/rom size.

  • 1
    \$\begingroup\$ As frequency is application stuff it belongs in the source where the CPU is initialized. Memory layout is a concern for the linker, so that stuff belongs in the linker control file. Chip specific constants are usually defined right before including the generic MCU headers. \$\endgroup\$
    – Arsenal
    Oct 4, 2015 at 8:54
  • \$\begingroup\$ Take a look at this CubeMX2Makefile \$\endgroup\$
    – valeros
    Oct 4, 2015 at 9:22

2 Answers 2


A makefile is actually a script for the 'make' utility and is not specific to any processor (GNU make atleast), neither has it got anything to do with CMSIS. You can, in fact, build nothing and simply create a folder using 'make' and 'recipies' written in the makefile. This is the user manual for GNU make for some background.

For the compiler commands again, you'll have to endure the GCC manual. It mentions the options that you need to enter for specifying the processor, optimization etc. For example, in the makefile recipe below:

build/%.o: source/%.c | build
    @echo " *** Building $@"
    arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -fsigned-char -ffreestanding -nostartfiles -Og -g3 -fno-move-loop-invariants -fdata-sections -ffunction-sections -I"include" -std=gnu11 -c -o $@ $^
    @echo " *** $@ built."
    @echo ""

it tells the 'make' utility that for making a file build\%.o, you'll need a file named source\%.c and the 'recipe' or method to do so is to run the arm-none-eabi-gcc compiler with the options specified in that line. The meaning of each compiler option is mentioned in the GCC manual. For example, -mcpu=cortex-m4 specifies the ARM cortex m4 processor. The stm32f103 would perhaps need -mcpu=cortex-m1.

As Arsenal said, a makefile cannot be used to specify frequency, memory size etc. While the frequency is configured in the application code, the memory size etc. would appear in the linker script used by the GNU linker 'ld'. Here is a reference to the linker manual. In fact, one of the options for the GNU compiler is -T"linker.ld" which specifies the linker file to be used. I found this blog post useful when I was trying to do something similar.


while it's not exactly what you're asking for, I'm using platformio for this purpose. I've only started a couple of days ago, but it seems to work pretty well. It has predefined compilation profiles for a variety of boards (yours seems to be included), and you can define custom ones quite easily. No IDE, I do all my editing in vim :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.