how to use arm-none-eabi-gcc compile STM32 program

3.4k views Asked by At

I have used arm-none-eabi-gcc(from launchpad) with Eclipse as my STM32 development tool for about several months(on ubuntu). It's a great IDE better than keil MDK I think. But now I wanna cast off the comfortable IDE and learn how the program is compiled. I want to know how the program is compiled in command line step by step. But it's not an easy way. I think that generating object file is almost the same to the normal program. The difficulty may be link. I have little knowledge about link and linker script. How to place interrupt vector into correct memory address. What are the necessary files in ARM CMSIS. What about newlib? Must I use it. What is "-spaecs" command line option. Too many questions for me. Do you have any information or reference about this. Thanks in advance.

By the way, it's strange that I run

make all

get

../system/src/newlib/_cxx.cpp:13:19: fatal error: cstdlib: No such file or directory

but there is no error when it is built in Eclipse

1

There are 1 answers

0
Richard at ImageCraft On

First, -specs=XYZ.specs asks the linker to look at the file XYZ.specs for additional linker library info. For example, here are some of the lines in the nano.specs file

%rename link nano_link %rename link_gcc_c_sequence nano_link_gcc_c_sequence ... *cpp_unique_options: -isystem =/include/newlib-nano %(nano_cpp_unique_options)

*nano_libc: -lc_nano ...

Basically an internal language to describe actions and what files to include. The content of the specs file would depend on a number of factors including compiler, MCU, etc.

For nano.specs, the main takeaway is that it includes the nanolib.

Moving on to nanolib vs. newlib. The short of it is that newlib is the libc implementation for embedded systems (vs. "regular" glibc for big machines like Linux), and nanolib is a further optimized library for embedded system based on microcontrollers. Nanolib even comes with "small" printf by default to further reduce the output program size. For a bit more background, I have written a blog post here. https://imagecraft.com/blog/2019/04/embedded-gcc-libraries-newlib-vs-nanolib/

To fully answer all your questions (CMSIS, how does GCC compile and link...), it would require a lot more than a simple answer that can fit in here. I would recommend looking up "GNU Embedded ARM" toolchain, and start with its documentation. The basic operations are simple: the compiler compile your files into object files (.o) and the linker combines them with libc into a working program. The major difficulty in building programs for an ARM MCU is which vendor libraries to use to access the peripherals. CMSIS is a way to solve the "generic" ARM MCU requirements, but most programs require much more than that.

STM32 is particular good that ST provides many libraries and even a GUI tool (CubeMX), but is also exceptionally bad that there are no less than 3 major versions (Standard Peripheral Library or SPL, HAL, and Low Level LL) of the libraries, and according to some people, are all broken in many ways.