1

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

6
  • github.com/dwelch67/stm32_samples Commented Jun 15, 2015 at 17:29
  • the IDE and other parts of that purpose built environment provide libraries of all kinds, and know how/where to link them. If you want to continue to have all of those libraries or ones like them then you need to either use the same tools as command line without the ide itself but figure out where all the parts are (simple/silly trick backup and replace the gcc and ld and such programs with one that prints out or logs the command like to truly figure out how the ide is calling the tools and where all the libraries are, then research what you find). Commented Jun 15, 2015 at 17:32
  • my examples are the other extreme, minimal to no libraries, just a compiler assembler and minimal linker. Commented Jun 15, 2015 at 17:32
  • newlib is/was a lightweight replacement for the c library targeted at embedded environments, rather than trying to carry around a full sized glibc for example. easy to port the backend on it to your operating system or bare metal, etc. do you need it lands in the same question, do you want/need a lot of C library functions or can you live without or live with a few that you implement in your own library (written from scratch or borrowed from other open source libraries but without the operating system hooks)? Commented Jun 15, 2015 at 17:35
  • Does it mean if I don't use standard library, I might not use newlib. Commented Jun 16, 2015 at 4:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.