-
Notifications
You must be signed in to change notification settings - Fork 64
Add support for Microchip XC32 toolchain in the CMSIS toolbox #2310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jkrech
merged 5 commits into
Open-CMSIS-Pack:main
from
MicrochipTech:add_xc_toolchain_in_cmsis_toolbox
Jan 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19288c6
Add support for Microchip XC32 toolchain in the CMSIS toolbox
ashish-mahanth 49a0b58
Update Microchip XC support based on review comments
ashish-mahanth beb46c7
Fix addressing copilot findings
ashish-mahanth 07dcbef
Implementing logic to obtain path to be passed to -mdfp option of the…
ashish-mahanth d26077f
Refine MDFP logic
ashish-mahanth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # 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(MDFP "") | ||
| file(GLOB_RECURSE ALL_DIRS LIST_DIRECTORIES true "${DPACK_DIR}/*") | ||
| foreach(DIR_PATH ${ALL_DIRS}) | ||
| if(IS_DIRECTORY "${DIR_PATH}") | ||
| get_filename_component(CURRENT_DIR_NAME "${DIR_PATH}" NAME) | ||
| if(CURRENT_DIR_NAME STREQUAL DNAME AND EXISTS "${DIR_PATH}/specs-${DNAME}") | ||
| set(MDFP "${DIR_PATH}/../../") | ||
| break() | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
|
|
||
| if(NOT DEFINED MDFP OR MDFP STREQUAL "") | ||
| message(FATAL_ERROR " Error: Could not determine the DFP path for -mdfp option!!") | ||
| endif() | ||
|
|
||
| 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=${MDFP}") | ||
|
|
||
| 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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| # define CODE_REGION rom | ||
| # else | ||
| # define CODE_REGION ram | ||
| # endif | ||
| #endif | ||
| #ifndef DATA_REGION | ||
| # define DATA_REGION ram | ||
| #endif | ||
| #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 ; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.