Actions

EmSys

Difference between revisions of "Using Visual Studio Code for ARM Development – Build Tasks"

From EdWiki

m (CMake Config Output)
m (Using Visual Studio Code for ARM Development – Build Tasks)
Line 1: Line 1:
 +
__NOTOC__
 
__NOTOC__
 
__NOTOC__
 
== Using Visual Studio Code for ARM Development – Build Tasks ==
 
== Using Visual Studio Code for ARM Development – Build Tasks ==
Line 141: Line 142:
 
This completes setting up the configuration for the build.
 
This completes setting up the configuration for the build.
  
[variant] Loaded new set of variants
+
=== CMkae Config Output ===
[kit] Successfully loaded 3 kits from /home/jshankar/.local/share/CMakeTools/cmake-tools-kits.json
+
[variant] Loaded new set of variants<br />
[proc] Executing command: /opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -v
+
[kit] Successfully loaded 3 kits from /home/jshankar/.local/share/CMakeTools/cmake-tools-kits.json<br />
[cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt.
+
[proc] Executing command: /opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -v<br />
[main] Configuring folder: blinky  
+
[cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt.<br />
[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"
+
[main] Configuring folder: blinky <br />
[cmake] Not searching for unused variables given on the command line.
+
[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"<br />
[cmake] -- CMAKE_TOOLCHAIN_FILE is: /home/jshankar/codeprojects/tm4c123gxl/blinky/arm-toolchain.cmake
+
[cmake] Not searching for unused variables given on the command line.<br />
[cmake] -- Configuring done
+
[cmake] -- CMAKE_TOOLCHAIN_FILE is: /home/jshankar/codeprojects/tm4c123gxl/blinky/arm-toolchain.cmake<br />
[cmake] -- Generating done
+
[cmake] -- Configuring done<br />
 +
[cmake] -- Generating done<br />
 
[cmake] -- Build files have been written to: /home/jshankar/codeprojects/tm4c123gxl/blinky/build
 
[cmake] -- Build files have been written to: /home/jshankar/codeprojects/tm4c123gxl/blinky/build
  

Revision as of 01:40, 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

  1. # Toolchain file for arm-none-eabi-gcc
  2. #
  3. set(CMAKE_SYSTEM_NAME Generic)
  4. set(CMAKE_SYSTEM_PROCESSOR ARM)
  5. set(CMAKE_CROSSCOMPILING "TRUE")
  6.  
  7. set(ARM_TOOLCHAIN_DIR "C:/ProgramData/chocolatey/bin")
  8. set(BINUTILS_PATH ${ARM_TOOLCHAIN_DIR}) 
  9.  
  10. set(TOOLCHAIN_PREFIX ${ARM_TOOLCHAIN_DIR}/arm-none-eabi-)
  11.  
  12. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  13.  
  14. set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc.exe")
  15. set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
  16. set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++.exe")
  17.  
  18. set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
  19. set(CMAKE_SIZE_UTIL ${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool")
  20.  
  21. set(CMAKE_FIND_ROOT_PATH ${BINUTILS_PATH})
  22. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  23. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  24. 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.

  1. # CMake file for tm4c123gxl
  2. #
  3. cmake_minimum_required(VERSION 3.15.3)
  4.  
  5. # Optional: print out extra messages to see what is going on. Comment it to have less verbose messages
  6. set(CMAKE_VERBOSE_MAKEFILE ON)
  7.  
  8. # Path to toolchain file. This one has to be before 'project()' below
  9. set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/arm-toolchain.cmake)
  10.  
  11. # Setup project, output and linker file
  12. project(blinky VERSION 0.1)
  13. set(EXECUTABLE ${PROJECT_NAME}.elf)
  14. set(LINKER_FILE ${CMAKE_SOURCE_DIR}/ld/tm4c123gh6pm.ld)
  15.  
  16. enable_language(C ASM)
  17. set(CMAKE_C_STANDARD 99)
  18. set(CMAKE_C_STANDARD_REQUIRED ON)
  19. set(CMAKE_C_EXTENSIONS OFF)
  20.  
  21. # Optional: issue a message to be sure it uses the correct toolchain file.
  22. message(STATUS "CMAKE_TOOLCHAIN_FILE is: ${CMAKE_TOOLCHAIN_FILE}")
  23.  
  24. # List of source files
  25. set(SRC_FILES
  26.         src/main.c
  27.         src/tm4c_startup.c
  28.         inc/tm4c_startup.h
  29.         )
  30.  
  31. # Build the executable based on the source files
  32. add_executable(${EXECUTABLE} ${SRC_FILES})
  33.  
  34. # List of compiler defines, prefix with -D compiler option
  35. target_compile_definitions(${EXECUTABLE} PRIVATE
  36.         -DPART_TM4C123GH6PM
  37.         )
  38.  
  39. # List of include directories
  40. target_include_directories(${EXECUTABLE} PRIVATE
  41.         src 
  42.         inc
  43.         "E:/ti/TivaWare_C_Series-2.2.0.295"
  44.         )
  45.  
  46. # Compiler options
  47. target_compile_options(${EXECUTABLE} PRIVATE
  48.         -mcpu=cortex-m4
  49.         -mthumb
  50.         -mfpu=fpv4-sp-d16
  51.         -mfloat-abi=hard
  52.  
  53.         -fdata-sections
  54.         -ffunction-sections
  55.  
  56.         -Wall
  57.         -O0
  58.         -g3
  59.         )
  60.  
  61. # Linker options
  62. target_link_options(${EXECUTABLE} PRIVATE
  63.         -T${LINKER_FILE}
  64.         -mcpu=cortex-m4
  65.         -mthumb
  66.         -mfpu=fpv4-sp-d16
  67.         -mfloat-abi=hard
  68.         -specs=nano.specs
  69.         -specs=nosys.specs
  70.         -lc
  71.         -lm
  72.         -Wl,-Map=${PROJECT_NAME}.map,--cref
  73.         -Wl,--gc-sections
  74.         -Xlinker -print-memory-usage -Xlinker
  75.         )
  76.  
  77. # Optional: Print executable size as part of the post build process
  78. add_custom_command(TARGET ${EXECUTABLE}
  79.         POST_BUILD
  80.         COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE})
  81.  
  82. # Optional: Create hex, bin and S-Record files after the build
  83. add_custom_command(TARGET ${EXECUTABLE}
  84.         POST_BUILD
  85.         COMMAND ${CMAKE_OBJCOPY} -O srec --srec-len=64 ${EXECUTABLE} ${PROJECT_NAME}.s19
  86.         COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
  87.         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.

CMkae Config Output

[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>