Skip to content

Commit 8e24e3c

Browse files
Start on adding Arduino Giga support
1 parent 182829f commit 8e24e3c

35 files changed

+220351
-300
lines changed

.github/workflows/build-cores.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- ARDUINO_NANO33BLE
1414
- RASPBERRY_PI_PICO
1515
- ARDUINO_NICLA_SENSE_ME
16+
- ARDUINO_GIGA_CM7
1617
cmake_build_type:
1718
- Debug
1819
- Release

.github/workflows/publish-release-artifacts.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
permissions:
77
contents: write
88

9+
10+
# This workflow run fires whenever a tag is created, and downloads all compiled cores and publishes them
11+
# as part of the release.
12+
# It does have one limitation: you have to manually ensure this workflow gets run after all the build-core
13+
# workflow runs are completed. I couldn't find a way to make it wait automatically.
14+
915
jobs:
1016
release:
1117
name: Create Release with Artifacts

CMakeLists.txt

Lines changed: 19 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ elseif("RASPBERRY_PI_PICO" IN_LIST MBED_TARGET_LABELS)
2020
set(ARDUINO_VARIANT_NAME "RASPBERRY_PI_PICO")
2121
elseif("ARDUINO_NICLA_SENSE_ME" IN_LIST MBED_TARGET_LABELS)
2222
set(ARDUINO_VARIANT_NAME "ARDUINO_NICLA_SENSE_ME")
23+
elseif("ARDUINO_GIGA" IN_LIST MBED_TARGET_LABELS)
24+
set(ARDUINO_VARIANT_NAME "ARDUINO_GIGA")
2325
else()
2426
message(FATAL_ERROR "This MBED_TARGET is currently not supported by the arduino core!")
2527
endif()
@@ -80,8 +82,8 @@ endif()
8082

8183
if("FEATURE_BLE=1" IN_LIST MBED_TARGET_DEFINITIONS)
8284

83-
# Note: There are circular dependencies between the BLE libraries, so we have to list some of them twice.
84-
list(APPEND MBED_LIBS_TO_INSTALL
85+
# Note: There are circular dependencies between the BLE libraries, so we have to list some of them multiple times.
86+
set(BLE_LIBRARIES
8587
mbed-ble
8688
mbed-ble-cordio_ll
8789
mbed-ble-cordio
@@ -91,6 +93,20 @@ if("FEATURE_BLE=1" IN_LIST MBED_TARGET_DEFINITIONS)
9193
mbed-ble
9294
mbed-ble-cordio_ll
9395
mbed-ble-cordio)
96+
97+
# filter out any Cordio libraries that don't exist for the current target
98+
foreach(LIBRARY ${BLE_LIBRARIES})
99+
if(NOT TARGET ${LIBRARY})
100+
list(REMOVE_ITEM BLE_LIBRARIES ${LIBRARY})
101+
endif()
102+
endforeach()
103+
104+
list(APPEND MBED_LIBS_TO_INSTALL ${BLE_LIBRARIES})
105+
endif()
106+
107+
if("COMPONENT_QSPIF=1" IN_LIST MBED_TARGET_DEFINITIONS)
108+
list(APPEND MBED_LIBS_TO_INSTALL
109+
mbed-storage-qspif)
94110
endif()
95111

96112
# We also need to know about any precompiled .a files
@@ -115,122 +131,7 @@ install(TARGETS ${MBED_UNIQUE_LIBS_TO_INSTALL} DESTINATION "variants/${ARDUINO_V
115131

116132
# Generate compile option files for Arduino IDE
117133
# ---------------------------------------------------------
118-
119-
# Iterate though the Mbed main build target and the optional targets and collect include dirs / defines / etc.
120-
set(TARGETS_TO_SCAN mbed-os ${MBED_UNIQUE_LIBS_TO_INSTALL})
121-
set(SCANNED_INCLUDE_DIRS "")
122-
set(SCANNED_DEFINES "")
123-
foreach(TARGET ${TARGETS_TO_SCAN})
124-
get_property(TARGET_INCLUDE_DIRS TARGET ${TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
125-
get_property(TARGET_COMPILE_DEFINITIONS TARGET ${TARGET} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
126-
127-
# For include dirs, if the include dir points to generated-headers, that's in the bin dir so we will handle it separately.
128-
foreach(INCLUDE_DIR ${TARGET_INCLUDE_DIRS})
129-
if(NOT "${INCLUDE_DIR}" MATCHES "generated-headers")
130-
list(APPEND SCANNED_INCLUDE_DIRS ${INCLUDE_DIR})
131-
endif()
132-
endforeach()
133-
134-
# Defines can just be passed through
135-
list(APPEND SCANNED_DEFINES ${TARGET_COMPILE_DEFINITIONS})
136-
endforeach()
137-
138-
# Generate defines file.
139-
# TODO do we need to escape defines with spaces?
140-
set(DEFINES_TXT_CONTENTS "")
141-
foreach(DEFINE ${SCANNED_DEFINES})
142-
string(APPEND DEFINES_TXT_CONTENTS "-D${DEFINE}\n")
143-
endforeach()
144-
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/defines.txt CONTENT ${DEFINES_TXT_CONTENTS})
145-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/defines.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")
146-
147-
# Generate includes file.
148-
set(INCLUDES_TXT_CONTENTS "")
149-
foreach(INCLUDE_DIR ${SCANNED_INCLUDE_DIRS})
150-
151-
# Make each include path relative to the current source dir
152-
# (so it starts with the first path component after mbed-os/)
153-
cmake_path(RELATIVE_PATH INCLUDE_DIR BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os OUTPUT_VARIABLE REL_INCLUDE_DIR)
154-
155-
string(APPEND INCLUDES_TXT_CONTENTS "-iwithprefixbefore/mbed/${REL_INCLUDE_DIR}\n")
156-
endforeach()
157-
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/includes.txt CONTENT ${INCLUDES_TXT_CONTENTS})
158-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/includes.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")
159-
160-
# Generate compile options files.
161-
foreach(LANG C CXX)
162-
163-
# The profile-specific compile options are set as a property on the mbed-core-flags
164-
# target so they get applied everywhere.
165-
# (see e.g. profiles/develop.cmake)
166-
get_property(MBED_${LANG}_PROFILE_COMPILE_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_COMPILE_OPTIONS)
167-
168-
# Slightly janky, but we need to simulate expanding the generator expressions in this property.
169-
# Use a regex to replace the generator expressions for the language we want, and then
170-
# use another regex to get rid of the genexes for the other languages.
171-
string(REGEX REPLACE
172-
"\\$<\\$<COMPILE_LANGUAGE:${LANG}>:([^>]+)>" "\\1"
173-
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
174-
string(GENEX_STRIP "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}" MBED_${LANG}_PROFILE_COMPILE_FLAGS)
175-
176-
# For the profile flags, we want to strip out the "-include;xxx/mbed-target-config.h" flag
177-
# as it contains a path specific to the build machine and isn't needed by Arduino anyway.
178-
# So, remove "-include" and the option after it.
179-
string(REGEX REPLACE
180-
"-include;[^;]+" ""
181-
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
182-
183-
# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
184-
# by the app.cmake toolchain file.
185-
separate_arguments(CMAKE_${LANG}_FLAGS_LIST NATIVE_COMMAND ${CMAKE_${LANG}_FLAGS})
186-
187-
# Annoyingly, the "--std" argument won't be in these lists because it's added by CMake.
188-
# We'll have to do that ourselves.
189-
if(${LANG} STREQUAL "C")
190-
set(C_STD_ARGUMENT --std=gnu${CMAKE_C_STANDARD})
191-
else() # CXX
192-
set(CXX_STD_ARGUMENT --std=gnu++${CMAKE_CXX_STANDARD})
193-
endif()
194-
195-
set(MBED_${LANG}_COMPILE_FLAGS
196-
${MBED_${LANG}_PROFILE_COMPILE_FLAGS}
197-
${CMAKE_${LANG}_FLAGS_LIST}
198-
${${LANG}_STD_ARGUMENT})
199-
200-
# Write list to a file, with one element on each line
201-
list(JOIN MBED_${LANG}_COMPILE_FLAGS "\n" ${LANG}_FLAG_FILE_CONTENTS)
202-
string(TOLOWER "${LANG}flags.txt" ${LANG}_FLAG_FILE_NAME)
203-
file(GENERATE
204-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
205-
CONTENT "${${LANG}_FLAG_FILE_CONTENTS}")
206-
install(FILES
207-
${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
208-
DESTINATION variants/${ARDUINO_VARIANT_NAME})
209-
endforeach()
210-
211-
# Generate linker options file
212-
213-
# The profile-specific linker options are set as a property on the mbed-core-flags
214-
# target so they get applied everywhere.
215-
# (see e.g. profiles/develop.cmake)
216-
get_property(MBED_PROFILE_LINKER_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_LINK_OPTIONS)
217-
218-
# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
219-
# by the app.cmake toolchain file.
220-
separate_arguments(CMAKE_EXE_LINKER_FLAGS_LIST NATIVE_COMMAND ${CMAKE_EXE_LINKER_FLAGS})
221-
222-
set(MBED_LINKER_FLAGS
223-
${MBED_PROFILE_LINKER_FLAGS}
224-
${CMAKE_EXE_LINKER_FLAGS_LIST})
225-
226-
# Write list to a file, with one element on each line
227-
list(JOIN MBED_LINKER_FLAGS "\n" LD_FLAG_FILE_CONTENTS)
228-
file(GENERATE
229-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
230-
CONTENT "${LD_FLAG_FILE_CONTENTS}")
231-
install(FILES
232-
${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
233-
DESTINATION variants/${ARDUINO_VARIANT_NAME})
134+
include(GenerateArduinoIDEFlagTxtFiles.cmake)
234135

235136
# Copy sources and headers into the install dir as needed
236137
# ---------------------------------------------------------

GenerateArduinoIDEFlagTxtFiles.cmake

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
##
2+
## This script scans the Mbed CMake targets and collects lists of compiler options.
3+
## It then writes those lists out to text files for the Arduino IDE ot use
4+
##
5+
6+
# Iterate though the Mbed main build target and the optional targets and collect include dirs / defines / etc.
7+
set(TARGETS_TO_SCAN mbed-os ${MBED_UNIQUE_LIBS_TO_INSTALL})
8+
set(SCANNED_INCLUDE_DIRS "")
9+
set(SCANNED_DEFINES "")
10+
foreach(TARGET ${TARGETS_TO_SCAN})
11+
get_property(TARGET_INCLUDE_DIRS TARGET ${TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
12+
get_property(TARGET_COMPILE_DEFINITIONS TARGET ${TARGET} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
13+
14+
# For include dirs, if the include dir points to generated-headers, that's in the bin dir so we will handle it separately.
15+
foreach(INCLUDE_DIR ${TARGET_INCLUDE_DIRS})
16+
if(NOT "${INCLUDE_DIR}" MATCHES "generated-headers")
17+
list(APPEND SCANNED_INCLUDE_DIRS ${INCLUDE_DIR})
18+
endif()
19+
endforeach()
20+
21+
# Defines can just be passed through
22+
list(APPEND SCANNED_DEFINES ${TARGET_COMPILE_DEFINITIONS})
23+
endforeach()
24+
25+
# Generate defines file (defines.txt)
26+
# TODO do we need to escape defines with spaces?
27+
set(DEFINES_TXT_CONTENTS "")
28+
foreach(DEFINE ${SCANNED_DEFINES})
29+
string(APPEND DEFINES_TXT_CONTENTS "-D${DEFINE}\n")
30+
endforeach()
31+
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/defines.txt CONTENT ${DEFINES_TXT_CONTENTS})
32+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/defines.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")
33+
34+
# Generate includes file (includes.txt)
35+
set(INCLUDES_TXT_CONTENTS "")
36+
foreach(INCLUDE_DIR ${SCANNED_INCLUDE_DIRS})
37+
38+
# Make each include path relative to the current source dir
39+
# (so it starts with the first path component after mbed-os/)
40+
cmake_path(RELATIVE_PATH INCLUDE_DIR BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os OUTPUT_VARIABLE REL_INCLUDE_DIR)
41+
42+
string(APPEND INCLUDES_TXT_CONTENTS "-iwithprefixbefore/mbed/${REL_INCLUDE_DIR}\n")
43+
endforeach()
44+
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/includes.txt CONTENT ${INCLUDES_TXT_CONTENTS})
45+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/includes.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")
46+
47+
# Generate compile options files (cflags.txt and cxxflags.txt)
48+
foreach(LANG C CXX)
49+
50+
# The profile-specific compile options are set as a property on the mbed-core-flags
51+
# target so they get applied everywhere.
52+
# (see e.g. profiles/develop.cmake)
53+
get_property(MBED_${LANG}_PROFILE_COMPILE_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_COMPILE_OPTIONS)
54+
55+
# Slightly janky, but we need to simulate expanding the generator expressions in this property.
56+
# Use a regex to replace the generator expressions for the language we want, and then
57+
# use another regex to get rid of the genexes for the other languages.
58+
string(REGEX REPLACE
59+
"\\$<\\$<COMPILE_LANGUAGE:${LANG}>:([^>]+)>" "\\1"
60+
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
61+
string(GENEX_STRIP "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}" MBED_${LANG}_PROFILE_COMPILE_FLAGS)
62+
63+
# For the profile flags, we want to strip out the "-include;xxx/mbed-target-config.h" flag
64+
# as it contains a path specific to the build machine and isn't needed by Arduino anyway.
65+
# So, remove "-include" and the option after it.
66+
string(REGEX REPLACE
67+
"-include;[^;]+" ""
68+
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
69+
70+
# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
71+
# by the app.cmake toolchain file.
72+
separate_arguments(CMAKE_${LANG}_FLAGS_LIST NATIVE_COMMAND ${CMAKE_${LANG}_FLAGS})
73+
74+
# Annoyingly, the "--std" argument won't be in these lists because it's added by CMake.
75+
# We'll have to do that ourselves.
76+
if(${LANG} STREQUAL "C")
77+
set(C_STD_ARGUMENT --std=gnu${CMAKE_C_STANDARD})
78+
else() # CXX
79+
set(CXX_STD_ARGUMENT --std=gnu++${CMAKE_CXX_STANDARD})
80+
endif()
81+
82+
set(MBED_${LANG}_COMPILE_FLAGS
83+
${MBED_${LANG}_PROFILE_COMPILE_FLAGS}
84+
${CMAKE_${LANG}_FLAGS_LIST}
85+
${${LANG}_STD_ARGUMENT})
86+
87+
# Write list to a file, with one element on each line
88+
list(JOIN MBED_${LANG}_COMPILE_FLAGS "\n" ${LANG}_FLAG_FILE_CONTENTS)
89+
string(TOLOWER "${LANG}flags.txt" ${LANG}_FLAG_FILE_NAME)
90+
file(GENERATE
91+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
92+
CONTENT "${${LANG}_FLAG_FILE_CONTENTS}")
93+
install(FILES
94+
${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
95+
DESTINATION variants/${ARDUINO_VARIANT_NAME})
96+
endforeach()
97+
98+
# Generate linker options file (ldflags.txt)
99+
100+
# The profile-specific linker options are set as a property on the mbed-core-flags
101+
# target so they get applied everywhere.
102+
# (see e.g. profiles/develop.cmake)
103+
get_property(MBED_PROFILE_LINKER_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_LINK_OPTIONS)
104+
105+
# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
106+
# by the app.cmake toolchain file.
107+
separate_arguments(CMAKE_EXE_LINKER_FLAGS_LIST NATIVE_COMMAND ${CMAKE_EXE_LINKER_FLAGS})
108+
109+
set(MBED_LINKER_FLAGS
110+
${MBED_PROFILE_LINKER_FLAGS}
111+
${CMAKE_EXE_LINKER_FLAGS_LIST})
112+
113+
# Write list to a file, with one element on each line
114+
list(JOIN MBED_LINKER_FLAGS "\n" LD_FLAG_FILE_CONTENTS)
115+
file(GENERATE
116+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
117+
CONTENT "${LD_FLAG_FILE_CONTENTS}")
118+
install(FILES
119+
${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
120+
DESTINATION variants/${ARDUINO_VARIANT_NAME})

cores/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ if("RASPBERRY_PI_PICO" IN_LIST MBED_TARGET_LABELS)
3737
target_compile_definitions(arduino-core PUBLIC ARDUINO_ARCH_RP2040)
3838
elseif("ARDUINO_NANO33BLE" IN_LIST MBED_TARGET_LABELS)
3939
target_compile_definitions(arduino-core PUBLIC ARDUINO_ARCH_NRF52840)
40+
elseif("ARDUINO_GIGA" IN_LIST MBED_TARGET_LABELS)
41+
target_compile_definitions(arduino-core PUBLIC ARDUINO_GIGA ARDUINO_ARCH_GIGA GIGA_PINS)
4042
endif()

0 commit comments

Comments
 (0)