Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions tools/buildmgr/cbuildgen/config/XC.5.0.0.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# This file maps the CMSIS project options to toolchain settings.
#
# - Applies to toolchain: Microchip XC32 Compiler version 5.0.0 and greater

set(AS "xc32-gcc")
set(CC "xc32-gcc")
set(CPP "xc32-gcc")
set(CXX "xc32-g++")
set(OC "xc32-objcopy")

set(TOOLCHAIN_ROOT "${REGISTERED_TOOLCHAIN_ROOT}")
set(TOOLCHAIN_VERSION "${REGISTERED_TOOLCHAIN_VERSION}")

if(DEFINED TOOLCHAIN_ROOT)
set(PREFIX)
set(EXT)

set(AS ${TOOLCHAIN_ROOT}/${PREFIX}${AS}${EXT})
set(CC ${TOOLCHAIN_ROOT}/${PREFIX}${CC}${EXT})
set(CPP ${TOOLCHAIN_ROOT}/${PREFIX}${CPP}${EXT})
set(CXX ${TOOLCHAIN_ROOT}/${PREFIX}${CXX}${EXT})
set(OC ${TOOLCHAIN_ROOT}/${PREFIX}${OC}${EXT})
endif()

# Helpers

function(cbuild_set_option_flags lang option value flags)
if(NOT DEFINED ${option}_${lang}_FLAGS)
return()
endif()
list(FIND ${option}_VALUES "${value}" _index)
if (${_index} GREATER -1)
list(GET ${option}_${lang}_FLAGS ${_index} flag)
if(NOT flag STREQUAL "")
string(STRIP "${flag} ${${flags}}" ${flags})
set(${flags} "${${flags}}" PARENT_SCOPE)
endif()
elseif(NOT value STREQUAL "")
string(TOLOWER "${option}" _option)
message(FATAL_ERROR "unknown '${_option}' value '${value}' !")
endif()
endfunction()

function(cbuild_set_options_flags lang optimize debug warnings language flags)
set(tmp "")
cbuild_set_option_flags(${lang} OPTIMIZE "${optimize}" tmp)
cbuild_set_option_flags(${lang} DEBUG "${debug}" tmp)
cbuild_set_option_flags(${lang} WARNINGS "${warnings}" tmp)
if(lang STREQUAL "CC" OR lang STREQUAL "CXX")
cbuild_set_option_flags(${lang} LANGUAGE "${language}" tmp)
endif()
set(${flags} "${tmp}" PARENT_SCOPE)
endfunction()


set(OPTIMIZE_VALUES "debug" "none" "balanced" "size" "speed")
set(OPTIMIZE_CC_FLAGS "-Og" "-O0" "-O2" "-Os" "-O1")
set(OPTIMIZE_CXX_FLAGS ${OPTIMIZE_CC_FLAGS})
set(OPTIMIZE_LD_FLAGS ${OPTIMIZE_CC_FLAGS})
set(OPTIMIZE_ASM_FLAGS ${OPTIMIZE_CC_FLAGS})

set(DEBUG_VALUES "on" "off")
set(DEBUG_CC_FLAGS "-g" "")
set(DEBUG_CXX_FLAGS       "-g"    "")
set(DEBUG_LD_FLAGS        "-g"    "")
set(DEBUG_ASM_FLAGS       "-g"    "")

set(WARNINGS_VALUES "on" "off" "all")
set(WARNINGS_CC_FLAGS "-Wall" "-w" "-Wall -Wextra")
set(WARNINGS_CXX_FLAGS "-Wall" "-w" "-Wall -Wextra")
set(WARNINGS_ASM_FLAGS "-Wall" "-w" "-Wall -Wextra")
set(WARNINGS_LD_FLAGS "" "" "")

set(LANGUAGE_VALUES "c90" "gnu90" "c99" "gnu99" "c11" "gnu11" "" "" "c++98" "gnu++98" "c++03" "gnu++03" "c++11" "gnu++11" "c++14" "gnu++14" "c++17" "gnu++17" "" "" "" "" )
set(LANGUAGE_CC_FLAGS "-std=c90" "-std=gnu90" "-std=c99" "-std=gnu99" "-std=c11" "-std=gnu11" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" )
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" "" "" "" "" )

# XC32 Processor/DFP flags
set(XC32_COMMON_FLAGS "-mprocessor=${DNAME} -mdfp=${DPACK_DIR}")

set(CPP_FLAGS "-E -P ${XC32_COMMON_FLAGS} -xc")
set(CPP_DEFINES ${LD_SCRIPT_PP_DEFINES})
if(DEFINED LD_REGIONS AND NOT LD_REGIONS STREQUAL "")
set(CPP_INCLUDES "-include \"${LD_REGIONS}\"")
endif()
set(CPP_ARGS_LD_SCRIPT "${CPP_FLAGS} ${CPP_DEFINES} ${CPP_INCLUDES} \"${LD_SCRIPT}\" -o \"${LD_SCRIPT_PP}\"")
separate_arguments(CPP_ARGS_LD_SCRIPT NATIVE_COMMAND ${CPP_ARGS_LD_SCRIPT})

# C Compiler

set(CC_OPTIONS_FLAGS "")
cbuild_set_options_flags(CC "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "${LANGUAGE_CC}" CC_OPTIONS_FLAGS)
set(CMAKE_C_FLAGS "${XC32_COMMON_FLAGS} ${CC_OPTIONS_FLAGS}")


# C++ Compiler

set(CXX_OPTIONS_FLAGS "")
cbuild_set_options_flags(CXX "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "${LANGUAGE_CXX}" CXX_OPTIONS_FLAGS)
set(CMAKE_CXX_FLAGS "${XC32_COMMON_FLAGS} ${CXX_OPTIONS_FLAGS}")

# Assembler

set(ASM_OPTIONS_FLAGS "")
cbuild_set_options_flags(ASM "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "" ASM_OPTIONS_FLAGS)
set(CMAKE_ASM_FLAGS "${XC32_COMMON_FLAGS} ${ASM_OPTIONS_FLAGS}")

# Linker

set(LD_OPTIONS_FLAGS "")
cbuild_set_options_flags(LD "${OPTIMIZE}" "${DEBUG}" "${WARNINGS}" "" LD_OPTIONS_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${XC32_COMMON_FLAGS} ${LD_OPTIONS_FLAGS} -T")

# ELF to HEX conversion
set(ELF2HEX -O ihex "${OUT_DIR}/$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>.elf" "${OUT_DIR}/${HEX_FILE}")

# ELF to BIN conversion
set(ELF2BIN -O binary "${OUT_DIR}/$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>.elf" "${OUT_DIR}/${BIN_FILE}")

# Set CMake variables for toolchain initialization
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_ASM_COMPILER "${AS}")
set(CMAKE_C_COMPILER "${CC}")
set(CMAKE_CXX_COMPILER "${CXX}")
set(CMAKE_OBJCOPY "${OC}")
2 changes: 1 addition & 1 deletion tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"CompilerType": {
"title":"compiler:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#compiler",
"type": "string",
"pattern": "^(GCC|CLANG|AC6|IAR|CLANG_TI)(@(>=)?([0-9]+\\.[0-9]+\\.[0-9]+((\\+|\\-)[a-zA-Z0-9_\\.\\+-]+)?))?$",
"pattern": "^(GCC|CLANG|AC6|IAR|CLANG_TI|XC)(@(>=)?([0-9]+\\.[0-9]+\\.[0-9]+((\\+|\\-)[a-zA-Z0-9_\\.\\+-]+)?))?$",
"description": "Compiler toolchain to be used, optionally with version, for example AC6@6.23.0."
},
"ConsumesProvidesType": {
Expand Down
140 changes: 140 additions & 0 deletions tools/projmgr/templates/xc_linker_script.ld.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2026 Microchip Technology Inc. and its subsidiaries.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)

/*
* Define the __XC32_RESET_HANDLER_NAME macro on the command line when you
* want to use a different name for the Reset Handler function.
*/
#ifndef __XC32_RESET_HANDLER_NAME
#define __XC32_RESET_HANDLER_NAME Reset_Handler
#endif /* __XC32_RESET_HANDLER_NAME */

ENTRY(__XC32_RESET_HANDLER_NAME)

/* ----------------------------------------------------------------------------
Memory definition
*----------------------------------------------------------------------------*/
MEMORY
{
rom (rx) : ORIGIN = __ROM0_BASE, LENGTH = __ROM0_SIZE
ram (rwx) : ORIGIN = __RAM0_BASE, LENGTH = __RAM0_SIZE
}

#ifndef CODE_REGION
# if ROM0_SIZE > 0
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor conditional references ROM0_SIZE, but the memory definition uses __ROM0_SIZE (with double underscores). This inconsistency will cause the condition to fail. Update to use __ROM0_SIZE to match the MEMORY section definition.

Suggested change
# if ROM0_SIZE > 0
# if __ROM0_SIZE > 0

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the copilot findings, in particular this one concerning the memory definition name conventions: it should match the define from the regions header file otherwise the linker script preprocessing won't find it.

# define CODE_REGION rom
# else
# define CODE_REGION ram
# endif
#endif
#ifndef DATA_REGION
# define DATA_REGION ram
#endif
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has trailing whitespace. Remove the trailing space for consistency with coding standards.

Suggested change
#endif
#endif

Copilot uses AI. Check for mistakes.
#ifndef VECTOR_REGION
# define VECTOR_REGION CODE_REGION
#endif

SECTIONS
{
.vectors :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.* .vectors_default .vectors_default.*))
KEEP(*(.isr_vector))
KEEP(*(.reset*))
KEEP(*(.after_vectors))
} > VECTOR_REGION

.text :
{
. = ALIGN(4);
*(.glue_7t) *(.glue_7)
*(.gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)

/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;

. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;

. = ALIGN(0x4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))

. = ALIGN(4);
KEEP(*(.fini))

. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;

KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))

. = ALIGN(4);
_efixed = .; /* End of text section */
} > CODE_REGION

PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > CODE_REGION
PROVIDE_HIDDEN (__exidx_end = .);

. = ALIGN(4);
_etext = .;

.bss (NOLOAD) :
{
. = ALIGN(4);
__bss_start__ = .;
_sbss = . ;
_szero = .;
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
_ebss = . ;
_ezero = .;
} > DATA_REGION

. = ALIGN(4);
_end = . ;
_ram_end_ = ORIGIN(ram) + LENGTH(ram) -1 ;
}
Loading