From d03ecc26978fe1c5073fce698c00cc653b794edb Mon Sep 17 00:00:00 2001
From: Erik Strand <erik.strand@cba.mit.edu>
Date: Sat, 8 Feb 2020 20:04:48 -0500
Subject: [PATCH] Build with cmake!

The key is to use an object library instead of a static library. The
linker was throwing out the startup code because it's never called.
---
 blink-cmake/CMakeLists.txt | 20 +++++++++++++++-----
 blink-cmake/openocd.cfg    |  7 +++++++
 2 files changed, 22 insertions(+), 5 deletions(-)
 create mode 100644 blink-cmake/openocd.cfg

diff --git a/blink-cmake/CMakeLists.txt b/blink-cmake/CMakeLists.txt
index de8c9d0..2c219dd 100644
--- a/blink-cmake/CMakeLists.txt
+++ b/blink-cmake/CMakeLists.txt
@@ -5,17 +5,27 @@ set(CMAKE_SYSTEM_NAME Generic)
 set(CMAKE_SYSTEM_PROCESSOR arm)
 set(CMAKE_CROSSCOMPILING 1)
 set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
-#set(CMAKE_C_LINKER "arm-none-eabi-gcc")
+set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
+set(CMAKE_AR "arm-none-eabi-ar")
+set(CMAKE_RANLIB "arm-none-eabi-ranlib")
+set(CMAKE_C_FLAGS "")
 set(CMAKE_C_LINK_FLAGS "")
 
+# search for programs in the build host directories
+SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+# for libraries and headers in the target directories
+SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
 set(MCU_DEFINE "__SAMD51J19A__")
 
 if(NOT CMAKE_BUILD_TYPE)
-    set(CMAKE_BUILD_TYPE "Debug")
+    set(CMAKE_BUILD_TYPE "Release")
 endif()
 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
 
-add_library(asf
+add_library(asf OBJECT
     samd51/startup/startup_samd51.c
     samd51/startup/system_samd51.c
 )
@@ -29,7 +39,7 @@ target_link_libraries(asf m)
 target_link_options(asf PUBLIC
     -mthumb
     -mabi=aapcs-linux
-    #-mlong-calls
+    -mlong-calls
     -mcpu=cortex-m4
     -mfpu=fpv4-sp-d16
     -mfloat-abi=softfp
@@ -53,7 +63,7 @@ target_compile_options(asf PUBLIC
     -std=gnu99
     -mthumb # use T32 instruction set instead of A32 (don't know if this matters)
     -mabi=aapcs-linux
-    #-mlong-calls # changes how functions are called
+    -mlong-calls # changes how functions are called
     -mcpu=cortex-m4
     -mfpu=fpv4-sp-d16
     -mfloat-abi=softfp # this flag specifies whether to use software or hardware float operations
diff --git a/blink-cmake/openocd.cfg b/blink-cmake/openocd.cfg
new file mode 100644
index 0000000..8760b7d
--- /dev/null
+++ b/blink-cmake/openocd.cfg
@@ -0,0 +1,7 @@
+# Atmel-ICE JTAG/SWD in-circuit debugger.
+interface cmsis-dap
+transport select swd
+
+# Chip info
+set CHIPNAME at91samd51j18
+source [find target/atsame5x.cfg]   
-- 
GitLab