Difference between revisions of "Using Visual Studio Code for ARM Development – Build Tasks"
From EdWiki
m (→CMake Build Output) |
m (→CMake Config Output) |
||
Line 141: | Line 141: | ||
This completes setting up the configuration for the build. | This completes setting up the configuration for the build. | ||
− | |||
− | |||
[variant] Loaded new set of variants | [variant] Loaded new set of variants | ||
− | [kit] Successfully loaded | + | [kit] Successfully loaded 3 kits from /home/jshankar/.local/share/CMakeTools/cmake-tools-kits.json |
− | [proc] Executing command: | + | [proc] Executing command: /opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -v |
+ | [cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt. | ||
[main] Configuring folder: blinky | [main] Configuring folder: blinky | ||
− | [proc] Executing command: | + | [proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++ -S/home/jshankar/codeprojects/tm4c123gxl/blinky -B/home/jshankar/codeprojects/tm4c123gxl/blinky/build -G "Unix Makefiles" |
[cmake] Not searching for unused variables given on the command line. | [cmake] Not searching for unused variables given on the command line. | ||
− | [cmake] -- CMAKE_TOOLCHAIN_FILE is: | + | [cmake] -- CMAKE_TOOLCHAIN_FILE is: /home/jshankar/codeprojects/tm4c123gxl/blinky/arm-toolchain.cmake |
[cmake] -- Configuring done | [cmake] -- Configuring done | ||
[cmake] -- Generating done | [cmake] -- Generating done | ||
− | [cmake] -- Build files have been written to | + | [cmake] -- Build files have been written to: /home/jshankar/codeprojects/tm4c123gxl/blinky/build |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
=== Build === | === Build === |
Revision as of 01:30, 23 March 2022
Using Visual Studio Code for ARM Development – Build Tasks
We are going to use CMake with Make to build the project. CMake needs some information where to find the tools. A simple and easy way is to to add a the following file to the project. I have named it arm-toolchain.cmake and placed it in the project root folder.
Toolchain CMake File
# Toolchain file for arm-none-eabi-gcc
#
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(CMAKE_CROSSCOMPILING "TRUE")
set(ARM_TOOLCHAIN_DIR "C:/ProgramData/chocolatey/bin")
set(BINUTILS_PATH ${ARM_TOOLCHAIN_DIR})
set(TOOLCHAIN_PREFIX ${ARM_TOOLCHAIN_DIR}/arm-none-eabi-)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc.exe")
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++.exe")
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
set(CMAKE_SIZE_UTIL ${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool")
set(CMAKE_FIND_ROOT_PATH ${BINUTILS_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
ARM_TOOLCHAIN_DIR specifies the compiler to be used. Additionally it defines extra tools as size and objcopy.
CMake CMakeLists.txt
To tell CMake what to do, create a file name CMakeList.txt in the project root.
# CMake file for tm4c123gxl
#
cmake_minimum_required(VERSION 3.15.3)
# Optional: print out extra messages to see what is going on. Comment it to have less verbose messages
set(CMAKE_VERBOSE_MAKEFILE ON)
# Path to toolchain file. This one has to be before 'project()' below
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/arm-toolchain.cmake)
# Setup project, output and linker file
project(blinky VERSION 0.1)
set(EXECUTABLE ${PROJECT_NAME}.elf)
set(LINKER_FILE ${CMAKE_SOURCE_DIR}/ld/tm4c123gh6pm.ld)
enable_language(C ASM)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Optional: issue a message to be sure it uses the correct toolchain file.
message(STATUS "CMAKE_TOOLCHAIN_FILE is: ${CMAKE_TOOLCHAIN_FILE}")
# List of source files
set(SRC_FILES
src/main.c
src/tm4c_startup.c
inc/tm4c_startup.h
)
# Build the executable based on the source files
add_executable(${EXECUTABLE} ${SRC_FILES})
# List of compiler defines, prefix with -D compiler option
target_compile_definitions(${EXECUTABLE} PRIVATE
-DPART_TM4C123GH6PM
)
# List of include directories
target_include_directories(${EXECUTABLE} PRIVATE
src
inc
"E:/ti/TivaWare_C_Series-2.2.0.295"
)
# Compiler options
target_compile_options(${EXECUTABLE} PRIVATE
-mcpu=cortex-m4
-mthumb
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-fdata-sections
-ffunction-sections
-Wall
-O0
-g3
)
# Linker options
target_link_options(${EXECUTABLE} PRIVATE
-T${LINKER_FILE}
-mcpu=cortex-m4
-mthumb
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-specs=nano.specs
-specs=nosys.specs
-lc
-lm
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
-Xlinker -print-memory-usage -Xlinker
)
# Optional: Print executable size as part of the post build process
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE})
# Optional: Create hex, bin and S-Record files after the build
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O srec --srec-len=64 ${EXECUTABLE} ${PROJECT_NAME}.s19
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin)
The most important sections/entries are:
- project(<your project name here>): Give your project a name
- set(LINKER_FILE <your linker file here>): specify the linker file name
- set(SRC_FILES <your source files here>): list of source files to compile
- target_compile_definitions(${EXECUTABLE} PRIVATE <compiler defines here>): list of compiler #defines
- target_include_directories(${EXECUTABLE} PRIVATE <list of include dir>): list of include directories
- target_compile_options(${EXECUTABLE} PRIVATE <compiler options>): list of compiler options
- target_link_options(${EXECUTABLE} PRIVATE <linker options>): list of linker options
This completes setting up the configuration for the build.
[variant] Loaded new set of variants [kit] Successfully loaded 3 kits from /home/jshankar/.local/share/CMakeTools/cmake-tools-kits.json [proc] Executing command: /opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -v [cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt. [main] Configuring folder: blinky [proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++ -S/home/jshankar/codeprojects/tm4c123gxl/blinky -B/home/jshankar/codeprojects/tm4c123gxl/blinky/build -G "Unix Makefiles" [cmake] Not searching for unused variables given on the command line. [cmake] -- CMAKE_TOOLCHAIN_FILE is: /home/jshankar/codeprojects/tm4c123gxl/blinky/arm-toolchain.cmake [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: /home/jshankar/codeprojects/tm4c123gxl/blinky/build
Build
View-->Terminal
cd build make
Make Build Output
PS E:\tm4c123gxl\blinky> cd .\build\ PS E:\tm4c123gxl\blinky\build> make E:/msys64/mingw64/bin/cmake.exe -SE:/tm4c123gxl/blinky -BE:/tm4c123gxl/blinky/build --check-build-system CMakeFiles/Makefile.cmake 0 E:/msys64/mingw64/bin/cmake.exe -E cmake_progress_start E:/tm4c123gxl/blinky/build/CMakeFiles E:/tm4c123gxl/blinky/build//CMakeFiles/progress.marks C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles/Makefile2 all make[1]: Entering directory 'E:/tm4c123gxl/blinky/build' C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles/blinky.elf.dir/build.make CMakeFiles/blinky.elf.dir/depend make[2]: Entering directory 'E:/tm4c123gxl/blinky/build' E:/msys64/mingw64/bin/cmake.exe -E cmake_depends "Unix Makefiles" E:/tm4c123gxl/blinky E:/tm4c123gxl/blinky E:/tm4c123gxl/blinky/build E:/tm4c123gxl/blinky/build E:/tm4c123gxl/blinky/build/CMakeFiles/blinky.elf.dir/DependInfo.cmake --color= make[2]: Leaving directory 'E:/tm4c123gxl/blinky/build' C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles/blinky.elf.dir/build.make CMakeFiles/blinky.elf.dir/build make[2]: Entering directory 'E:/tm4c123gxl/blinky/build' [ 33%] Building C object CMakeFiles/blinky.elf.dir/src/main.c.obj C:/ProgramData/chocolatey/bin/arm-none-eabi-gcc.exe -DPART_TM4C123GH6PM -IE:/tm4c123gxl/blinky/src -IE:/tm4c123gxl/blinky/inc -IE:/ti/TivaWare_C_Series-2.2.0.295 -g -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fdata-sections -ffunction-sections -Wall -O0 -g3 -std=c99 -MD -MT CMakeFiles/blinky.elf.dir/src/main.c.obj -MF CMakeFiles/blinky.elf.dir/src/main.c.obj.d -o CMakeFiles/blinky.elf.dir/src/main.c.obj -c E:/tm4c123gxl/blinky/src/main.c [ 66%] Building C object CMakeFiles/blinky.elf.dir/src/tm4c_startup.c.obj C:/ProgramData/chocolatey/bin/arm-none-eabi-gcc.exe -DPART_TM4C123GH6PM -IE:/tm4c123gxl/blinky/src -IE:/tm4c123gxl/blinky/inc -IE:/ti/TivaWare_C_Series-2.2.0.295 -g -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fdata-sections -ffunction-sections -Wall -O0 -g3 -std=c99 -MD -MT CMakeFiles/blinky.elf.dir/src/tm4c_startup.c.obj -MF CMakeFiles/blinky.elf.dir/src/tm4c_startup.c.obj.d -o CMakeFiles/blinky.elf.dir/src/tm4c_startup.c.obj -c E:/tm4c123gxl/blinky/src/tm4c_startup.c [100%] Linking C executable blinky.elf C:/ProgramData/chocolatey/bin/arm-none-eabi-gcc.exe -g -TE:/tm4c123gxl/blinky/ld/tm4c123gh6pm.ld -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nano.specs -specs=nosys.specs -lc -lm -Wl,-Map=blinky.map,--cref -Wl,--gc-sections -Xlinker -print-memory-usage "CMakeFiles/blinky.elf.dir/src/main.c.obj" "CMakeFiles/blinky.elf.dir/src/tm4c_startup.c.obj" -o blinky.elf Memory region Used Size Region Size %age Used FLASH: 980 B 256 KB 0.37% SRAM: 540 B 32 KB 1.65% C:/ProgramData/chocolatey/bin/arm-none-eabi-size blinky.elf text data bss dec hex filename 980 0 540 1520 5f0 blinky.elf C:/ProgramData/chocolatey/bin/arm-none-eabi-objcopy -O srec --srec-len=64 blinky.elf blinky.s19 C:/ProgramData/chocolatey/bin/arm-none-eabi-objcopy -O ihex blinky.elf blinky.hex C:/ProgramData/chocolatey/bin/arm-none-eabi-objcopy -O binary blinky.elf blinky.bin make[2]: Leaving directory 'E:/tm4c123gxl/blinky/build' [100%] Built target blinky.elf make[1]: Leaving directory 'E:/tm4c123gxl/blinky/build' E:/msys64/mingw64/bin/cmake.exe -E cmake_progress_start E:/tm4c123gxl/blinky/build/CMakeFiles 0 PS E:\tm4c123gxl\blinky\build>