Skip to content

Commit 0fcca05

Browse files
Add support for the TI-CGT-CLANG toolchain
This PR aims to add support for the [TI Clang toolchain](https://www.ti.com/tool/download/ARM-CGT-CLANG) and provide a solution for the issue found [here](Open-CMSIS-Pack/cmsis-toolbox#220). --------- Co-authored-by: Hermann Core <[email protected]> Co-authored-by: Daniel Brondani <[email protected]>
1 parent c3bf42e commit 0fcca05

File tree

3 files changed

+270
-1
lines changed

3 files changed

+270
-1
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# This file maps the CMSIS project options to toolchain settings.
2+
#
3+
# - Applies to toolchain: Texas Instruments CGT Clang (TI-CGT-CLANG) Bare Metal Toolchain for the Arm Architecture 4.0.1 and greater
4+
5+
set(AS "tiarmclang")
6+
set(CC "tiarmclang")
7+
set(CXX "tiarmclang")
8+
set(CPP "tiarmclang")
9+
set(OC "tiarmobjcopy")
10+
11+
set(TOOLCHAIN_ROOT "${REGISTERED_TOOLCHAIN_ROOT}")
12+
set(TOOLCHAIN_VERSION "${REGISTERED_TOOLCHAIN_VERSION}")
13+
14+
if(DEFINED TOOLCHAIN_ROOT)
15+
set(PREFIX)
16+
set(EXT)
17+
18+
set(AS ${TOOLCHAIN_ROOT}/${PREFIX}${AS}${EXT})
19+
set(CC ${TOOLCHAIN_ROOT}/${PREFIX}${CC}${EXT})
20+
set(CXX ${TOOLCHAIN_ROOT}/${PREFIX}${CXX}${EXT})
21+
set(CPP ${TOOLCHAIN_ROOT}/${PREFIX}${CPP}${EXT})
22+
set(OC ${TOOLCHAIN_ROOT}/${PREFIX}${OC}${EXT})
23+
endif()
24+
25+
# Helpers
26+
27+
function(cbuild_set_defines lang defines)
28+
set(TMP_DEFINES)
29+
foreach(DEFINE ${${defines}})
30+
string(REPLACE "\"" "\\\"" ENTRY ${DEFINE})
31+
string(REGEX REPLACE "=.*" "" KEY ${ENTRY})
32+
if (KEY STREQUAL ENTRY)
33+
set(VALUE "1")
34+
else()
35+
string(REGEX REPLACE ".*=" "" VALUE ${ENTRY})
36+
endif()
37+
string(APPEND TMP_DEFINES "-D${ENTRY} ")
38+
endforeach()
39+
set(${defines} ${TMP_DEFINES} PARENT_SCOPE)
40+
endfunction()
41+
42+
set(OPTIMIZE_VALUES "debug" "none" "balanced" "size" "speed")
43+
set(OPTIMIZE_CC_FLAGS "-Og" "-O0" "-O2" "-Os" "-O3")
44+
set(OPTIMIZE_ASM_FLAGS ${OPTIMIZE_CC_FLAGS})
45+
set(OPTIMIZE_CXX_FLAGS ${OPTIMIZE_CC_FLAGS})
46+
set(OPTIMIZE_LD_FLAGS ${OPTIMIZE_CC_FLAGS})
47+
48+
set(DEBUG_VALUES "on" "off")
49+
set(DEBUG_CC_FLAGS "-g3" "-g0")
50+
set(DEBUG_CXX_FLAGS ${DEBUG_CC_FLAGS})
51+
set(DEBUG_LD_FLAGS ${DEBUG_CC_FLAGS})
52+
set(DEBUG_ASM_FLAGS ${DEBUG_CC_FLAGS})
53+
54+
set(WARNINGS_VALUES "on" "off" "all")
55+
set(WARNINGS_CC_FLAGS "" "-w" "-Wall")
56+
set(WARNINGS_ASM_FLAGS "" "-w" "-Wall")
57+
set(WARNINGS_CXX_FLAGS "" "-w" "-Wall")
58+
set(WARNINGS_LD_FLAGS "" "-w" "-Wall")
59+
60+
set(LANGUAGE_VALUES "c90" "gnu90" "c99" "gnu99" "c11" "gnu11" "c17" "gnu17" "" "" "c++98" "gnu++98" "c++03" "gnu++03" "c++11" "gnu++11" "c++14" "gnu++14" "c++17" "gnu++17" "" "" "" "")
61+
set(LANGUAGE_CC_FLAGS "-std=c90" "-std=gnu90" "-std=c99" "-std=gnu99" "-std=c11" "-std=gnu11" "-std=c17" "-std=gnu17" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")
62+
set(LANGUAGE_CXX_FLAGS "" "" "" "" "" "" "" "" "" "" "-std=c++98" "-std=gnu++98" "-std=c++03" "-std=gnu++03" "-std=c++11" "-std=gnu++11" "-std=c++14" "-std=gnu++14" "-std=c++17" "-std=gnu++17" "" "" "" "")
63+
64+
function(cbuild_set_option_flags lang option value flags)
65+
if(NOT DEFINED ${option}_${lang}_FLAGS)
66+
return()
67+
endif()
68+
list(FIND ${option}_VALUES "${value}" _index)
69+
if (${_index} GREATER -1)
70+
list(GET ${option}_${lang}_FLAGS ${_index} flag)
71+
set(${flags} "${flag} ${${flags}}" PARENT_SCOPE)
72+
elseif(NOT value STREQUAL "")
73+
string(TOLOWER "${option}" _option)
74+
message(FATAL_ERROR "unkown '${_option}' value '${value}' !")
75+
endif()
76+
endfunction()
77+
78+
function(cbuild_set_options_flags lang optimize debug warnings language flags)
79+
set(opt_flags)
80+
cbuild_set_option_flags(${lang} OPTIMIZE "${optimize}" opt_flags)
81+
cbuild_set_option_flags(${lang} DEBUG "${debug}" opt_flags)
82+
cbuild_set_option_flags(${lang} WARNINGS "${warnings}" opt_flags)
83+
cbuild_set_option_flags(${lang} LANGUAGE "${language}" opt_flags)
84+
set(${flags} "${opt_flags} ${${flags}}" PARENT_SCOPE)
85+
endfunction()
86+
87+
if(CPU STREQUAL "Cortex-M0")
88+
set(TIARMCLANG_CPU "-mcpu=cortex-m0")
89+
elseif(CPU STREQUAL "Cortex-M0+")
90+
set(TIARMCLANG_CPU "-mcpu=cortex-m0plus")
91+
elseif(CPU STREQUAL "Cortex-M3")
92+
set(TIARMCLANG_CPU "-mcpu=cortex-m3")
93+
elseif(CPU STREQUAL "Cortex-M4")
94+
if(FPU STREQUAL "SP_FPU")
95+
set(TIARMCLANG_CPU "-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard")
96+
else()
97+
set(TIARMCLANG_CPU "-mcpu=cortex-m4 -mfloat-abi=soft")
98+
endif()
99+
elseif(CPU STREQUAL "Cortex-M33")
100+
if(FPU STREQUAL "SP_FPU")
101+
set(TIARMCLANG_CPU "-mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard")
102+
else()
103+
set(TIARMCLANG_CPU "-mcpu=cortex-m33 -mfloat-abi=soft")
104+
endif()
105+
elseif(CPU STREQUAL "Cortex-R4")
106+
if(FPU STREQUAL "DP_FPU")
107+
set(TIARMCLANG_CPU "-mcpu=cortex-r4 -mfpu=vfpv3-d16 -mfloat-abi=hard")
108+
else()
109+
set(TIARMCLANG_CPU "-mcpu=cortex-r4 -mfloat-abi=soft")
110+
endif()
111+
elseif(CPU STREQUAL "Cortex-R5")
112+
if(FPU STREQUAL "DP_FPU")
113+
set(TIARMCLANG_CPU "-mcpu=cortex-r5 -mfpu=vfpv3-d16 -mfloat-abi=hard")
114+
else()
115+
set(TIARMCLANG_CPU "-mcpu=cortex-r5 -mfloat-abi=soft")
116+
endif()
117+
endif()
118+
if(NOT DEFINED TIARMCLANG_CPU)
119+
message(FATAL_ERROR "Error: CPU is not supported!")
120+
endif()
121+
122+
# Assembler
123+
124+
set(ASM_CPU "${TIARMCLANG_CPU}")
125+
set(ASM_DEFINES ${DEFINES})
126+
cbuild_set_defines(ASM ASM_DEFINES)
127+
128+
set(ASM_OPTIONS_FLAGS)
129+
cbuild_set_options_flags(ASM "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "" ASM_OPTIONS_FLAGS)
130+
131+
if(BYTE_ORDER STREQUAL "Little-endian")
132+
set(ASM_BYTE_ORDER "-mlittle-endian")
133+
elseif(BYTE_ORDER STREQUAL "Big-endian")
134+
set(ASM_BYTE_ORDER "-mbig-endian")
135+
endif()
136+
137+
# C Pre-Processor
138+
139+
if(SECURE STREQUAL "Secure" OR SECURE STREQUAL "Secure-only")
140+
set(CC_SECURE "-mcmse")
141+
endif()
142+
143+
set(CPP_FLAGS "-E -P ${TIARMCLANG_CPU} -xc ${CC_SECURE}")
144+
set(CPP_DEFINES ${LD_SCRIPT_PP_DEFINES})
145+
cbuild_set_defines(CC CPP_DEFINES)
146+
if(DEFINED LD_REGIONS AND NOT LD_REGIONS STREQUAL "")
147+
set(CPP_INCLUDES "-include \"${LD_REGIONS}\"")
148+
endif()
149+
set(CPP_ARGS_LD_SCRIPT "${CPP_FLAGS} ${CPP_DEFINES} ${CPP_INCLUDES} \"${LD_SCRIPT}\" -o \"${LD_SCRIPT_PP}\"")
150+
separate_arguments(CPP_ARGS_LD_SCRIPT NATIVE_COMMAND ${CPP_ARGS_LD_SCRIPT})
151+
152+
# C Compiler
153+
154+
set(CC_CPU "${TIARMCLANG_CPU}")
155+
set(CC_DEFINES ${ASM_DEFINES})
156+
set(CC_BYTE_ORDER ${ASM_BYTE_ORDER})
157+
set(CC_FLAGS "")
158+
set(_PI "-include ")
159+
set(_ISYS "-isystem ")
160+
set(CC_OPTIONS_FLAGS)
161+
cbuild_set_options_flags(CC "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "${LANGUAGE_CC}" CC_OPTIONS_FLAGS)
162+
163+
if(BRANCHPROT STREQUAL "NO_BRANCHPROT")
164+
set(CC_BRANCHPROT "-mbranch-protection=none")
165+
elseif(BRANCHPROT STREQUAL "BTI")
166+
set(CC_BRANCHPROT "-mbranch-protection=bti")
167+
elseif(BRANCHPROT STREQUAL "BTI_SIGNRET")
168+
set(CC_BRANCHPROT "-mbranch-protection=bti+pac-ret")
169+
endif()
170+
171+
# C++ Compiler
172+
173+
set(CXX_CPU "${CC_CPU}")
174+
set(CXX_DEFINES "${CC_DEFINES}")
175+
set(CXX_BYTE_ORDER "${CC_BYTE_ORDER}")
176+
set(CXX_SECURE "${CC_SECURE}")
177+
set(CXX_BRANCHPROT "${CC_BRANCHPROT}")
178+
set(CXX_FLAGS "${CC_FLAGS}")
179+
set(CXX_OPTIONS_FLAGS)
180+
cbuild_set_options_flags(CXX "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "${LANGUAGE_CXX}" CXX_OPTIONS_FLAGS)
181+
182+
# Linker
183+
184+
set(LD_CPU ${TIARMCLANG_CPU})
185+
set(_LS)
186+
187+
if(SECURE STREQUAL "Secure")
188+
set(LD_SECURE "-Wl,--import_cmse_lib_out=\"${OUT_DIR}/${CMSE_LIB}\"")
189+
endif()
190+
191+
set(LD_FLAGS)
192+
set(LD_OPTIONS_FLAGS)
193+
cbuild_set_options_flags(LD "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "" LD_OPTIONS_FLAGS)
194+
195+
# Group libraries for rescanning
196+
set(LIB_FILES -Wl,--start-group ${LIB_FILES} -Wl,--end-group)
197+
198+
# ELF to HEX conversion
199+
set (ELF2HEX -O ihex "${OUT_DIR}/$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>$<TARGET_PROPERTY:${TARGET},SUFFIX>" "${OUT_DIR}/${HEX_FILE}")
200+
201+
# ELF to BIN conversion
202+
set (ELF2BIN -O binary "${OUT_DIR}/$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>$<TARGET_PROPERTY:${TARGET},SUFFIX>" "${OUT_DIR}/${BIN_FILE}")
203+
204+
# Linker Map file generation
205+
set (LD_MAP -Wl,--map_file=${OUT_DIR}/${LD_MAP_FILE})
206+
207+
# Set CMake variables for toolchain initialization
208+
set(CMAKE_C_FLAGS_INIT "${CC_CPU}")
209+
set(CMAKE_CXX_FLAGS_INIT "${CXX_CPU}")
210+
set(CMAKE_SYSTEM_NAME Generic)
211+
set(CMAKE_CROSSCOMPILING TRUE)
212+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
213+
set(CMAKE_ASM_COMPILER "${AS}")
214+
set(CMAKE_C_COMPILER "${CC}")
215+
set(CMAKE_CXX_COMPILER "${CXX}")
216+
set(CMAKE_OBJCOPY "${OC}")
217+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeASM")

tools/projmgr/schemas/common.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
},
130130
"CompilerType": {
131131
"type": "string",
132-
"pattern": "^(GCC|CLANG|AC6|IAR)(@(>=)?([0-9]+\\.[0-9]+\\.[0-9]+((\\+|\\-)[a-zA-Z0-9_\\.\\+-]+)?))?$",
132+
"pattern": "^(GCC|CLANG|AC6|IAR|CLANG_TI)(@(>=)?([0-9]+\\.[0-9]+\\.[0-9]+((\\+|\\-)[a-zA-Z0-9_\\.\\+-]+)?))?$",
133133
"description": "Compiler toolchain to be used, optionally with version, for example [email protected]."
134134
},
135135
"ConsumesProvidesType": {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2024 Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* ----------------------------------------------------------------------------
20+
Memory definition
21+
*----------------------------------------------------------------------------*/
22+
MEMORY
23+
{
24+
ROM0 : ORIGIN = __ROM0_BASE, LENGTH = __ROM0_SIZE
25+
#if __ROM1_SIZE > 0
26+
ROM1 : ORIGIN = __ROM1_BASE, LENGTH = __ROM1_SIZE
27+
#endif
28+
#if __ROM2_SIZE > 0
29+
ROM2 : ORIGIN = __ROM2_BASE, LENGTH = __ROM2_SIZE
30+
#endif
31+
#if __ROM3_SIZE > 0
32+
ROM3 : ORIGIN = __ROM3_BASE, LENGTH = __ROM3_SIZE
33+
#endif
34+
35+
RAM0 : ORIGIN = __RAM0_BASE, LENGTH = __RAM0_SIZE
36+
#if __RAM1_SIZE > 0
37+
RAM1 : ORIGIN = __RAM1_BASE, LENGTH = __RAM1_SIZE
38+
#endif
39+
#if __RAM2_SIZE > 0
40+
RAM2 : ORIGIN = __RAM2_BASE, LENGTH = __RAM2_SIZE
41+
#endif
42+
#if __RAM3_SIZE > 0
43+
RAM3 : ORIGIN = __RAM3_BASE, LENGTH = __RAM3_SIZE
44+
#endif
45+
}
46+
47+
SECTIONS
48+
{
49+
.text: > ROM0
50+
.data: > RAM0
51+
.bss: > RAM0
52+
}

0 commit comments

Comments
 (0)