Build setup
Buid using Makefile
Open your project folder. It is better to use
VSCODE
.Open
terminal
from your project folder.Build project using
make
command.It is very easy this time to build the project using Makefile. You just need to use the
make
command and nothig.make -j
-j
is for doing all jobs code at once. It speeds up build time using parallel processing. If you want to don
jobs at once, use-jn
. For example, executing8
tasks at once:make -j8
Tip
Add -Wl,--print-memory-usage
to LDFLAGS
in Makefile to print memory usage.
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
LDFLAGS += -Wl,--print-memory-usage
If you want to clean the project, use
make clean
.
Build using CMake
Open your project folder. It is better to use
VSCODE
.Open
terminal
from your project folder.Build project using
cmake
command.mkdir build cd build cmake .. make -j
But this does not generate
.bin
file which is needed for flashing the microcontroller. To generate, you need to usearm-none-eabi-objcopy
.arm-none-eabi-objcopy -O binary <your_project_name.elf> <your_project_name.bin>We always do this job. So, it is better to generate binary file using CMake.
Add these lines at the bottom of CMakeLists.txt.
# Generate binary add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin COMMAND arm-none-eabi-objcopy -O binary ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.elf ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin DEPENDS ${CMAKE_PROJECT_NAME} COMMENT "Converting ELF to binary" ) # Binary target add_custom_target(bin ALL DEPENDS ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin COMMENT "Generating binary file" )
To build using only one line of command, a script file is needed.
Create a
build.sh
file at your project folder for compiling and generating binary file.flash.sh#!/bin/bash set +e if [[ "$1" == "clean" ]]; then rm -rf build fi if [ ! -d "build" ]; then mkdir build fi cd build cmake .. make -j cd ..
Make
build.sh
executable.chmod +x build.sh
Compile using one line of command.
./build.sh
To clean first then build, run:
./build.sh clean