Squashed 'third_party/pico-sdk/' content from commit 2062372d2
Change-Id: Ic20f199d3ed0ea8d3a6a1bbf513f875ec7500cc6
git-subtree-dir: third_party/pico-sdk
git-subtree-split: 2062372d203b372849d573f252cf7c6dc2800c0a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/cmake/Platform/PICO.cmake b/cmake/Platform/PICO.cmake
new file mode 100644
index 0000000..06388b5
--- /dev/null
+++ b/cmake/Platform/PICO.cmake
@@ -0,0 +1,4 @@
+# this is included because toolchain file sets SYSTEM_NAME=PICO
+
+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+set(CMAKE_EXECUTABLE_SUFFIX .elf)
\ No newline at end of file
diff --git a/cmake/pico_pre_load_platform.cmake b/cmake/pico_pre_load_platform.cmake
new file mode 100644
index 0000000..51ee39a
--- /dev/null
+++ b/cmake/pico_pre_load_platform.cmake
@@ -0,0 +1,29 @@
+# PICO_CMAKE_CONFIG: PICO_PLATFORM, platform to build for e.g. rp2040/host, default=rp2040 or environment value, group=build
+if (DEFINED ENV{PICO_PLATFORM} AND (NOT PICO_PLATFORM))
+ set(PICO_PLATFORM $ENV{PICO_PLATFORM})
+ message("Using PICO_PLATFORM from environment ('${PICO_PLATFORM}')")
+else()
+ if (NOT PICO_PLATFORM)
+ set(PICO_PLATFORM "rp2040")
+ pico_message("Defaulting PICO_PLATFORM to ${PICO_PLATFORM} since not specified.")
+ else()
+ message("PICO platform is ${PICO_PLATFORM}.")
+ endif()
+endif ()
+
+set(PICO_PLATFORM ${PICO_PLATFORM} CACHE STRING "PICO Build platform (e.g. rp2040, host)")
+
+# PICO_CMAKE_CONFIG: PICO_CMAKE_RELOAD_PLATFORM_FILE, custom CMake file to use to set up the platform environment, default=none, group=build
+set(PICO_CMAKE_PRELOAD_PLATFORM_FILE "" CACHE INTERNAL "")
+set(PICO_CMAKE_PRELOAD_PLATFORM_DIR "${CMAKE_CURRENT_LIST_DIR}/preload/platforms" CACHE INTERNAL "")
+
+if (NOT PICO_CMAKE_PRELOAD_PLATFORM_FILE)
+ set(PICO_CMAKE_PRELOAD_PLATFORM_FILE ${PICO_CMAKE_PRELOAD_PLATFORM_DIR}/${PICO_PLATFORM}.cmake CACHE INTERNAL "")
+endif ()
+
+if (NOT EXISTS "${PICO_CMAKE_PRELOAD_PLATFORM_FILE}")
+ message(FATAL_ERROR "${PICO_CMAKE_PRELOAD_PLATFORM_FILE} does not exist. \
+ Either specify a valid PICO_PLATFORM (or PICO_CMAKE_PRELOAD_PLATFORM_FILE).")
+endif ()
+
+include(${PICO_CMAKE_PRELOAD_PLATFORM_FILE})
diff --git a/cmake/pico_pre_load_toolchain.cmake b/cmake/pico_pre_load_toolchain.cmake
new file mode 100644
index 0000000..b77f421
--- /dev/null
+++ b/cmake/pico_pre_load_toolchain.cmake
@@ -0,0 +1,43 @@
+# PICO_CMAKE_CONFIG: PICO_TOOLCHAIN_PATH, Path to search for compiler, default=none (i.e. search system paths), group=build
+set(PICO_TOOLCHAIN_PATH "${PICO_TOOLCHAIN_PATH}" CACHE INTERNAL "")
+
+# Set a default build type if none was specified
+set(default_build_type "Release")
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ message(STATUS "Defaulting build type to '${default_build_type}' since not specified.")
+ set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build, options are: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'." FORCE)
+ # Set the possible values of build type for cmake-gui
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
+ "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
+endif()
+
+if (CMAKE_BUILD_TYPE STREQUAL "Default")
+ error("Default build type is NOT supported")
+endif()
+
+# PICO_CMAKE_CONFIG: PICO_COMPILER, Optionally specifies a different compiler (other than pico_arm_gcc.cmake) - this is not yet fully supported, default=none, group=build
+# If PICO_COMPILER is specified, set toolchain file to ${PICO_COMPILER}.cmake.
+if (DEFINED PICO_COMPILER)
+ if (DEFINED CMAKE_TOOLCHAIN_FILE)
+ get_filename_component(toolchain "${CMAKE_TOOLCHAIN_FILE}" NAME_WE)
+ if (NOT "${PICO_COMPILER}" STREQUAL "${toolchain}")
+ message(WARNING "CMAKE_TOOLCHAIN_FILE is already defined to ${toolchain}.cmake, you\
+ need to delete cache and reconfigure if you want to switch compiler.")
+ endif ()
+ else ()
+ set(toolchain_dir "${CMAKE_CURRENT_LIST_DIR}/preload/toolchains")
+ set(toolchain_file "${toolchain_dir}/${PICO_COMPILER}.cmake")
+ if (EXISTS "${toolchain_file}")
+ set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE INTERNAL "")
+ else ()
+ # todo improve message
+ message(FATAL_ERROR "Toolchain file \"${PICO_COMPILER}.cmake\" does not exist, please\
+ select one from \"cmake/toolchains\" folder.")
+ endif ()
+ endif ()
+ message("PICO compiler is ${PICO_COMPILER}")
+endif ()
+
+unset(PICO_COMPILER CACHE)
+
diff --git a/cmake/pico_utils.cmake b/cmake/pico_utils.cmake
new file mode 100644
index 0000000..3bce54b
--- /dev/null
+++ b/cmake/pico_utils.cmake
@@ -0,0 +1,28 @@
+function(pico_message param)
+ if (${ARGC} EQUAL 1)
+ message("${param}")
+ return()
+ endif ()
+
+ if (NOT ${ARGC} EQUAL 2)
+ message(FATAL_ERROR "Expect at most 2 arguments")
+ endif ()
+ message("${param}" "${ARGV1}")
+endfunction()
+
+macro(assert VAR MSG)
+ if (NOT ${VAR})
+ message(FATAL_ERROR "${MSG}")
+ endif ()
+endmacro()
+
+function(pico_find_in_paths OUT PATHS NAME)
+ foreach(PATH IN LISTS ${PATHS})
+ if (EXISTS ${PATH}/${NAME})
+ get_filename_component(FULLNAME ${PATH}/${NAME} ABSOLUTE)
+ set(${OUT} ${FULLNAME} PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ set(${OUT} "" PARENT_SCOPE)
+endfunction()
\ No newline at end of file
diff --git a/cmake/preload/platforms/host.cmake b/cmake/preload/platforms/host.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cmake/preload/platforms/host.cmake
diff --git a/cmake/preload/platforms/pico/pico.cmake b/cmake/preload/platforms/pico/pico.cmake
new file mode 100644
index 0000000..6e49411
--- /dev/null
+++ b/cmake/preload/platforms/pico/pico.cmake
@@ -0,0 +1,7 @@
+if (NOT (DEFINED PICO_COMPILER OR DEFINED CMAKE_TOOLCHAIN_FILE))
+ pico_message("Defaulting PICO platform compiler to pico_arm_gcc since not specified.")
+ set(PICO_COMPILER "pico_arm_gcc")
+endif ()
+
+
+
diff --git a/cmake/preload/platforms/rp2040.cmake b/cmake/preload/platforms/rp2040.cmake
new file mode 100644
index 0000000..3406bfc
--- /dev/null
+++ b/cmake/preload/platforms/rp2040.cmake
@@ -0,0 +1 @@
+include(${CMAKE_CURRENT_LIST_DIR}/pico/pico.cmake)
\ No newline at end of file
diff --git a/cmake/preload/toolchains/find_compiler.cmake b/cmake/preload/toolchains/find_compiler.cmake
new file mode 100644
index 0000000..6052369
--- /dev/null
+++ b/cmake/preload/toolchains/find_compiler.cmake
@@ -0,0 +1,31 @@
+# Toolchain file is processed multiple times, however, it cannot access CMake cache on some runs.
+# We store the search path in an environment variable so that we can always access it.
+if (NOT "${PICO_TOOLCHAIN_PATH}" STREQUAL "")
+ set(ENV{PICO_TOOLCHAIN_PATH} "${PICO_TOOLCHAIN_PATH}")
+endif ()
+
+# Find the compiler executable and store its path in a cache entry ${compiler_path}.
+# If not found, issue a fatal message and stop processing. PICO_TOOLCHAIN_PATH can be provided from
+# commandline as additional search path.
+function(pico_find_compiler compiler_path compiler_exe)
+ # Search user provided path first.
+ find_program(
+ ${compiler_path} ${compiler_exe}
+ PATHS ENV PICO_TOOLCHAIN_PATH
+ PATH_SUFFIXES bin
+ NO_DEFAULT_PATH
+ )
+
+ # If not then search system paths.
+ if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
+ if (DEFINED ENV{PICO_TOOLCHAIN_PATH})
+ message(WARNING "PICO_TOOLCHAIN_PATH specified ($ENV{PICO_TOOLCHAIN_PATH}), but ${compiler_exe} not found there")
+ endif()
+ find_program(${compiler_path} ${compiler_exe})
+ endif ()
+ if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
+ set(PICO_TOOLCHAIN_PATH "" CACHE PATH "Path to search for compiler.")
+ message(FATAL_ERROR "Compiler '${compiler_exe}' not found, you can specify search path with\
+ \"PICO_TOOLCHAIN_PATH\".")
+ endif ()
+endfunction()
diff --git a/cmake/preload/toolchains/pico_arm_clang.cmake b/cmake/preload/toolchains/pico_arm_clang.cmake
new file mode 100644
index 0000000..1d2c4eb
--- /dev/null
+++ b/cmake/preload/toolchains/pico_arm_clang.cmake
@@ -0,0 +1,53 @@
+# NOTE: THIS IS A WIP ONLY PICO_ARM_GCC IS CURRENTLY SUPPORTED
+# todo there is probably a more "cmake" way of doing this going thru the standard path with our "PICO" platform
+# i.e. CMake<Lang>Information and whatnot
+include(${CMAKE_CURRENT_LIST_DIR}/find_compiler.cmake)
+
+# include our Platform/pico.cmake
+set(CMAKE_SYSTEM_NAME PICO)
+set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
+
+# Find CLANG
+pico_find_compiler(PICO_COMPILER_CC clang)
+pico_find_compiler(PICO_COMPILER_CXX clang)
+#pico_find_compiler(PICO_COMPILER_ASM armasm)
+set(PICO_COMPILER_ASM "${PICO_COMPILER_CC}" CACHE INTERNAL "")
+pico_find_compiler(PICO_OBJCOPY llvm-objcopy)
+pico_find_compiler(PICO_OBJDUMP llvm-objdump)
+
+# Specify the cross compiler.
+set(CMAKE_C_COMPILER ${PICO_COMPILER_CC} CACHE FILEPATH "C compiler")
+set(CMAKE_CXX_COMPILER ${PICO_COMPILER_CXX} CACHE FILEPATH "C++ compiler")
+set(CMAKE_C_OUTPUT_EXTENSION .o)
+
+# todo should we be including CMakeASMInformation anyway - i guess that is host side
+set(CMAKE_ASM_COMPILER ${PICO_COMPILER_ASM} CACHE FILEPATH "ASM compiler")
+set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+set(CMAKE_INCLUDE_FLAG_ASM "-I")
+set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
+set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
+
+# Disable compiler checks.
+set(CMAKE_C_COMPILER_FORCED TRUE)
+set(CMAKE_CXX_COMPILER_FORCED TRUE)
+
+# Add target system root to cmake find path.
+get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
+get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
+
+# Look for includes and libraries only in the target system prefix.
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+include_directories(/usr/include/newlib)
+
+# todo move to platform/Generix-xxx
+set(ARM_CLANG_COMMON_FLAGS " --target=arm-none-eabi -mcpu=cortex-m0plus -mthumb")
+set(CMAKE_C_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+set(CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+set(CMAKE_ASM_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+set(CMAKE_C_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+
diff --git a/cmake/preload/toolchains/pico_arm_clang_arm.cmake b/cmake/preload/toolchains/pico_arm_clang_arm.cmake
new file mode 100644
index 0000000..50fabbc
--- /dev/null
+++ b/cmake/preload/toolchains/pico_arm_clang_arm.cmake
@@ -0,0 +1,52 @@
+# NOTE: THIS IS A WIP ONLY PICO_ARM_GCC IS CURRENTLY SUPPORTED
+# todo there is probably a more "cmake" way of doing this going thru the standard path with our "PICO" platform
+# i.e. CMake<Lang>Information and whatnot
+include(${CMAKE_CURRENT_LIST_DIR}/find_compiler.cmake)
+
+# include our Platform/PICO.cmake
+set(CMAKE_SYSTEM_NAME PICO)
+set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
+
+# Find ARMClang.
+pico_find_compiler(PICO_COMPILER_CC armclang)
+pico_find_compiler(PICO_COMPILER_CXX armclang)
+pico_find_compiler(PICO_COMPILER_ASM armasm)
+set(PICO_COMPILER_ASM "${PICO_COMPILER_ASM}" CACHE INTERNAL "")
+pico_find_compiler(PICO_OBJCOPY llvm-objcopy)
+pico_find_compiler(PICO_OBJDUMP llvm-objdump)
+
+# Specify the cross compiler.
+set(CMAKE_C_COMPILER ${PICO_COMPILER_CC} CACHE FILEPATH "C compiler")
+set(CMAKE_CXX_COMPILER ${PICO_COMPILER_CXX} CACHE FILEPATH "C++ compiler")
+set(CMAKE_C_OUTPUT_EXTENSION .o)
+
+# todo should we be including CMakeASMInformation anyway - i guess that is host side
+set(CMAKE_ASM_COMPILER ${PICO_COMPILER_ASM} CACHE FILEPATH "ASM compiler")
+set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+set(CMAKE_INCLUDE_FLAG_ASM "-I")
+set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
+set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
+
+# Disable compiler checks.
+set(CMAKE_C_COMPILER_FORCED TRUE)
+set(CMAKE_CXX_COMPILER_FORCED TRUE)
+
+# Add target system root to cmake find path.
+get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
+get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
+
+# Look for includes and libraries only in the target system prefix.
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# todo move to platform/Generix-xxx
+set(ARM_CLANG_COMMON_FLAGS " --cpu=Cortex-M0plus")
+string(APPEND CMAKE_C_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+string(APPEND CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+string(APPEND CMAKE_ASM_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+string(APPEND CMAKE_C_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+
+
diff --git a/cmake/preload/toolchains/pico_arm_gcc.cmake b/cmake/preload/toolchains/pico_arm_gcc.cmake
new file mode 100644
index 0000000..d8c56fc
--- /dev/null
+++ b/cmake/preload/toolchains/pico_arm_gcc.cmake
@@ -0,0 +1,67 @@
+# todo there is probably a more "cmake" way of doing this going thru the standard path with our "PICO" platform
+# i.e. CMake<Lang>Information and whatnot
+include(${CMAKE_CURRENT_LIST_DIR}/find_compiler.cmake)
+
+# include our Platform/PICO.cmake
+set(CMAKE_SYSTEM_NAME PICO)
+set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
+
+if (NOT PICO_GCC_TRIPLE)
+ if (DEFINED ENV{PICO_GCC_TRIPLE})
+ set(PICO_GCC_TRIPLE $ENV{PICO_GCC_TRIPLE})
+ message("PICO_GCC_TRIPLE set from environment: $ENV{PICO_GCC_TRIPLE}")
+ else()
+ set(PICO_GCC_TRIPLE arm-none-eabi)
+ #pico_message_debug("PICO_GCC_TRIPLE defaulted to arm-none-eabi")
+ endif()
+endif()
+
+# Find GCC for ARM.
+pico_find_compiler(PICO_COMPILER_CC ${PICO_GCC_TRIPLE}-gcc)
+pico_find_compiler(PICO_COMPILER_CXX ${PICO_GCC_TRIPLE}-g++)
+set(PICO_COMPILER_ASM "${PICO_COMPILER_CC}" CACHE INTERNAL "")
+pico_find_compiler(PICO_OBJCOPY ${PICO_GCC_TRIPLE}-objcopy)
+pico_find_compiler(PICO_OBJDUMP ${PICO_GCC_TRIPLE}-objdump)
+
+# Specify the cross compiler.
+set(CMAKE_C_COMPILER ${PICO_COMPILER_CC} CACHE FILEPATH "C compiler")
+set(CMAKE_CXX_COMPILER ${PICO_COMPILER_CXX} CACHE FILEPATH "C++ compiler")
+set(CMAKE_C_OUTPUT_EXTENSION .o)
+
+# todo should we be including CMakeASMInformation anyway - i guess that is host side
+set(CMAKE_ASM_COMPILER ${PICO_COMPILER_ASM} CACHE FILEPATH "ASM compiler")
+set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+set(CMAKE_INCLUDE_FLAG_ASM "-I")
+set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
+set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
+
+# Disable compiler checks.
+set(CMAKE_C_COMPILER_FORCED TRUE)
+set(CMAKE_CXX_COMPILER_FORCED TRUE)
+
+# Add target system root to cmake find path.
+get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
+get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
+
+# Look for includes and libraries only in the target system prefix.
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
+
+# todo move to platform/Generix-xxx
+
+# on ARM -mcpu should not be mixed with -march
+set(ARM_GCC_COMMON_FLAGS " -mcpu=cortex-m0plus -mthumb")
+foreach(LANG IN ITEMS C CXX ASM)
+ set(CMAKE_${LANG}_FLAGS_INIT "${ARM_GCC_COMMON_FLAGS}")
+ if (PICO_DEOPTIMIZED_DEBUG)
+ set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-O0")
+ else()
+ set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
+ endif()
+ set(CMAKE_${LANG}_LINK_FLAGS "-Wl,--build-id=none")
+endforeach()
+