-
Notifications
You must be signed in to change notification settings - Fork 4
Compilation and Make
- The compiler is the tool that processes your high level code, and converts it into something your can run.
- The output of the compiler is specific to your computer configuration.
- Make uses the
Makefileconfig to compile code.
How compilation works in Linux systems: https://learning.oreilly.com/library/view/how-linux-works/9781098128913/c16.xhtml#h1-500402c16-0002
- Preprocessor
- Substitudes Macros
- Checks for syntax errors
- Compiler High level code -> assembly
- Assembler Assembler -> executables as .o (Object) files
- Linker Joins .o files -> binary
https://youtu.be/2YfM-HxQd_8?si=ryGwmjAWzMQH8CRr

The collecting and combining various pieces of code and data into a single file that can be loaded (copied) into memory and executed. Carnegie Mellon
The linker’s job is to take all the object files that make up a program and put them together. The linker must know exactly what the memory layout of your device is so it can fit the program into memory. It’s also responsible for connecting external symbols in one file with their actual definitions in another. This process is called linking symbols.
A library is a collection of object (.o) files in an archive format.
So basically the linker indicates how the assembly files should be combined to create the final executable.
The linker uses the LinkerScript.ld, where it is specified the system memory. This script contains where the Flash and RAM start, and how long are they.
- The map file tells you where the functions in your code are stored in memory
- The firmware file
startup_stm32fxx.s(an assembly language file) contains the code that defines the ISR and specifications for other memory segments.
| Section name | What is it for |
|---|---|
| text. | Read-only data and code |
| rodata | Read-only data |
| data | Initialized data |
| bss | Data initialized to zero |
| COMMON | Uninitialized data |
| .isr_vector | Interrupt and reset handlers that must go in a specific place |
Refers to how your computer components share and process data.

| CISC | RISC | RISC V |
|---|---|---|
| Complete Instruction Set Computer | Reduced Instruction Set Computer | Open Source |
| Complete set of instructions, can take more than 1 cycle | Single instruction per cycle | Open Source |
| Optimization is based on hardware | Optimization is software based | Open Source |
| Utilizes micro-transactions | Compiler manages the operations | Open Source |
| Variable instruction encoding | Fixed encoding | Open Source |
| Easily manages complex addresses | Needs help when a complex address is asserted | Open Source |
| High throughput | Pipelines instructions | Open Source |
| AMD and Intel? | ARM owned | Open Source |
Used on microprocessors. What your probably using 😀 .
The CPU is made out of ALU, Registes, Control Unit and a memory unit. The CPU communicates with all the components through a single bus, which can cause bandwidth limitations.
Used on microcontrolles/mcus. Like an Arduino.
Has different busses for reading data memory and program memory. Effectively reducing the CPU terminals to access info.

Refers to the number of bits your CPU can process at a time. This directly affects the size of your variables, and how many CPU cycles takes to process them.
Until the recent introduction of ARM CPUs, most computers just had x86 (compatible with x64 and x32 applications). On the other hand, embedded applications have always varied on this characteristic. There exist 8, 16, 32 and 64 bit processors, mainly because of cost and size restrains. However, the trend seems to support the Arm's 32 and 64 bit for the long run.

Cross-compilation: The process of compiling for a different platform that the one that is being built in.
- Build system: Where code is (usually written) and built.
- Host system: Where code is executed.
Remember, we learn to understand the memes

By default, make will build whats specified at first, this is the defacto target.
make
If you wish to compile any other target, then do:
make targetName
The syntax is like:
targetName: dependency1
compiler -flags [args...]
Note: Targets may also be defined as dependencies, thus calling a compilation chain
FYI: Make can also execute bash commands, so that's why you'll sometimes see commands being used in the Makefile.
In fact the syntax, for declaring, using, and even storing variables is the same!

- The GNU Make Book. By John Graham-Cumming.
- Bare Metal C. By Steve Oualline.
- Embedded Systems Object-Oriented Programming in C and C++. By Bohobiom Incorporated Ltd.
- STM32 makefile examples
- Example from workshop
- Create a sub directory with the name you'll identify the program.
- Create a CMakeLists.txt file whiting the sub directory.
- On the document, add the following lines:
-
cmake_minimum_required(VERSION 3.5.1)
-
project(hello)
-
add_executable(hello hello.cpp)
-
set(CMAKE_SYSTEM_NAME Linux)
-
set(CMAKE_SYSTEM_PROCESSOR arm)
-
SET(CMAKE_CXX_FLAGS "--std=c++11")
-
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabi-gcc)
-
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++)
-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
-
- Save
- Run CMake:
- mkdir build && cd build && cmake ..
- Build the application:
- make
Comments: The suggested way to cross compile code is by using toolchains. These pre-define the necessary rules needed for the platform.
With ❤️ from 🇲🇽