Skip to content

Problem: No AVR support and path issues on windows #5

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions Modules/AVRObj2Hex.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#=============================================================================
# Copyright 2016 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)


function(avr_obj2hex target)
find_program(AVR_OBJ2HEX
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to name it AVR_OBJCOPY as it's more descriptive.

Copy link
Author

Choose a reason for hiding this comment

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

Hmmm, since there is already a MicrochipBin2Hex.cmake it feels for me more suitable.
On the other hand, since I do not develop our MCU software, but manage the CI and test final hardware, this naming is a little helper, that this function gives the files for program the device ;) I know... weak arguments ^^
OBJCOPY directly fits to the called avr program, so there is a better connection for typical developer...

At the end, I found this cmake file once somewhere, it is from the owner of this Repository, and I think it would be nice, if we can discuss the naming with him (and hopefully also other users)

NAMES ${_CMAKE_TOOLCHAIN_PREFIX}avr-objcopy avr-objcopy
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}
)

if(NOT AVR_OBJ2HEX)
message(SEND_ERROR "No avr-objcopy program was found")
endif()

function(get_target_property_fallback var target)
set(result NOTFOUND)
foreach(property ${ARGN})
get_target_property(result ${target} ${property})
if(result)
break()
endif()
endforeach()
set(${var} ${result} PARENT_SCOPE)
endfunction()

get_target_property_fallback(in_f ${target}
RUNTIME_OUTPUT_NAME
OUTPUT_NAME
NAME
)

get_target_property_fallback(dir ${target}
RUNTIME_OUTPUT_DIRECTORY
BINARY_DIR
)

get_filename_component(out_f ${in_f} NAME_WE)
set(out_f "${out_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.hex")

add_custom_command(
TARGET ${target} POST_BUILD
WORKING_DIRECTORY ${dir}/$<CONFIG>
COMMAND "${AVR_OBJ2HEX}" -O ihex "${in_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.elf" "${out_f}"
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it easier to customize consider adding a variable AVR_OBJCOPY_FLAGS (AVR_OBJ2HEX_FLAGS) and maybe appropriate target property for more complex projects.

Copy link
Author

Choose a reason for hiding this comment

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

Uff, feel free ;) This is behind my knowladge of AVR_OBJCOPY ;)

BYPRODUCTS ${dir}/$<CONFIG>/${out_f}
VERBATIM
)

set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
${dir}/${out_f}
)
endfunction()
6 changes: 5 additions & 1 deletion Modules/Compiler/XC8CC-C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
string(APPEND CMAKE_C_FLAGS_INIT
# build for the configured MCU model
" -mcpu=${MICROCHIP_MCU_MODEL}"
)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_8")
string(APPEND CMAKE_C_FLAGS_INIT
# fail if the requested optimization level is forbidden by the license
" --nofallback"
)
)
endif()

set(CMAKE_C_OUTPUT_EXTENSION ".p1")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
Expand Down
2 changes: 2 additions & 0 deletions Modules/MicrochipBin2Hex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ function(bin2hex target)
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
${dir}/${out_f}
)

install(FILES ${out_f} TYPE BIN)
endfunction()
2 changes: 1 addition & 1 deletion Modules/Platform/MicrochipMCU-C-XC8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT MICROCHIP_XC8_PATH)
endif()

set(CMAKE_FIND_ROOT_PATH "${MICROCHIP_XC8_PATH}")

set(CMAKE_PREFIX_PATH "${MICROCHIP_XC8_PATH}")

if(NOT MICROCHIP_XC8_CLI)
set(MICROCHIP_XC8_CLI "xc8-cc")
Expand Down
2 changes: 1 addition & 1 deletion Modules/Platform/MicrochipMCU-C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# This module is loaded during the search for a C compiler
# to provide the information necessary to find one.

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_8")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_8" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AVR")
include(Platform/MicrochipMCU-C-XC8)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_16")
include(Platform/MicrochipMCU-C-XC16)
Expand Down
1 change: 1 addition & 0 deletions Modules/Platform/MicrochipMCU.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ set(CMAKE_SYSTEM_INCLUDE_PATH /include)
set(CMAKE_SYSTEM_LIBRARY_PATH /lib)
set(CMAKE_SYSTEM_PROGRAM_PATH /bin)

include(AVRObj2Hex)
include(MicrochipBin2Hex)
14 changes: 13 additions & 1 deletion toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ set(MICROCHIP_MCU "${MICROCHIP_MCU}"
CACHE STRING "full model number of the target Microchip MCU"
)


# known 8-bit MCU families
list(APPEND MICROCHIP_FAMILIES_8
PIC12F
PIC16F
PIC18F
ATtiny
ATxmega
Copy link
Contributor

Choose a reason for hiding this comment

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

What about ATmega parts?

Copy link
Author

@argltuc argltuc May 14, 2021

Choose a reason for hiding this comment

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

I do not have any test hardware for ATmega. I can add it, but untested.

)

# known 16-bit MCU families
Expand Down Expand Up @@ -112,6 +113,17 @@ elseif(MICROCHIP_MCU MATCHES "^(dsPIC|PIC)(32M[XZ]|[0-9]+[A-Z])([A-Z0-9]+)$")
"Unsupported MCU family '${MICROCHIP_MCU_FAMILY}'."
)
endif()

elseif(MICROCHIP_MCU MATCHES "^(AT)(tiny|xmega)([a-zA-Z0-9]+)$")
set(MICROCHIP_MCU_FAMILY "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
set(MICROCHIP_MCU_MODEL "${MICROCHIP_MCU}")
if(MICROCHIP_MCU_FAMILY IN_LIST MICROCHIP_FAMILIES_8)
Copy link
Contributor

Choose a reason for hiding this comment

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

Building a test program to check if the compiler actually supports the CPU would make error messages nicer - i.e. a descriptive error during configure instead of during compile (though still descriptive).

Copy link
Author

Choose a reason for hiding this comment

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

This idea sounds good. but as above: feel free :)
I can try to manage a configuration test, but i will need some time for it. I want to use this toolchain for some of our components and I just want to share my adaptions, which I made to fit my purposes, so a configuration test is currently not on my way :)

set(CMAKE_SYSTEM_PROCESSOR "AVR")
else()
message(FATAL_ERROR
"Unsupported MCU family '${MICROCHIP_MCU_FAMILY}'."
)
endif()

else()
message(FATAL_ERROR
Expand Down