-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move to CMake on Demo/CAN/Send project * Bringup Receive * BasicIO to new format, except SIL * Blink to new structure * RTOS to cmake * Make link private * CAN Projects * Mapper build sys * AnalogPWM to cmake * CANError build sys + formatting * Front Controller * LVController to cmake system and remove unused OS * TMS to build system * Separate toolchain script to avoid Makefile bug * Fix first sed command * BSD Compatible? * Simplify command since this form is BSD compatible
- Loading branch information
1 parent
4d66457
commit 8ebc274
Showing
98 changed files
with
215 additions
and
582 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,120 +1,21 @@ | ||
# Blake Freer | ||
# April 13, 2023 | ||
# This file is included in the cubemx/CMakeLists.txt file of all projects' | ||
# November 2024 | ||
|
||
# Generate code from CubeMX. The Makefile modifies the toolchain to fit our | ||
# system. | ||
# This file is included in the mcal_conf.cmake file of all projects' | ||
# platforms that use the stm32f767 mcal | ||
|
||
message(STATUS "Generating from CubeMX and adding custom targets.") | ||
execute_process( | ||
# Calls generate_cubemx.mk in the context of this file, which is adjacent to | ||
# the board_config.ioc file. | ||
COMMAND ${CMAKE_MAKE_PROGRAM} "--file=${CMAKE_SOURCE_DIR}/cmake/generate_cubemx.mk" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMAND make "--file=${CMAKE_SOURCE_DIR}/cmake/generate_cubemx.mk" | ||
WORKING_DIRECTORY ${DIR_PLATFORM}/cubemx | ||
RESULT_VARIABLE status | ||
) | ||
|
||
if(status AND NOT status EQUAL 0) | ||
message(FATAL_ERROR | ||
"Failed to generate from CubeMX. You should manually 'Generate Code' \ | ||
before building." | ||
"${out} Failed to generate from CubeMX. You should manually 'Generate Code' before building." | ||
) | ||
endif() | ||
|
||
set(CUSTOM_MAKEFILE "${CMAKE_CURRENT_SOURCE_DIR}/CustomMakefile.mk") | ||
|
||
message(STATUS "Building CubeMX objects with the auto-generated Makefile") | ||
execute_process( | ||
# Build all cubemx sources to their objects. This target is added to the | ||
# cubemx Makefile by generate_cubemx.mk. | ||
COMMAND ${CMAKE_MAKE_PROGRAM} "objects" "--file=${CUSTOM_MAKEFILE}" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
function(extract_make_variable output makefile var_name) | ||
# Get a variable from a Makefile | ||
# This requires the Makefile to have the following target & recipe | ||
# | ||
# %.value: | ||
# @echo $($*) | ||
# | ||
# generate_cubemx.mk appends this target to the cubemx Makefile | ||
# See custom_cubemx_targets.mk | ||
execute_process( | ||
COMMAND ${CMAKE_MAKE_PROGRAM} "--file=${makefile}" "${var_name}.value" "--no-print-directory" | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE value | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
message(VERBOSE "The make variable ${var_name} has the value \"${value}\"") | ||
set(${output} ${value} PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Get C_INCLUDES, split string to a list, and remove the -I prefix | ||
extract_make_variable(include_str "${CUSTOM_MAKEFILE}" "C_INCLUDES") | ||
separate_arguments(C_INCLUDES NATIVE_COMMAND ${include_str}) | ||
list(TRANSFORM C_INCLUDES REPLACE "^-I" "") | ||
|
||
# Get Global #defines | ||
extract_make_variable(c_def_str "${CUSTOM_MAKEFILE}" "C_DEFS") | ||
separate_arguments(C_DEFS NATIVE_COMMAND ${c_def_str}) | ||
list(TRANSFORM C_DEFS REPLACE "^-D" "") | ||
|
||
# Get MCU which includes the CPU name (cortex-m7), floating point unit, etc | ||
extract_make_variable(MCU "${CUSTOM_MAKEFILE}" "MCU") | ||
separate_arguments(MCU NATIVE_COMMAND ${MCU}) | ||
|
||
# Get the linker flags. These are needed since we manually link the objects | ||
# instead of using the cubemx Makefile. | ||
extract_make_variable(ldflags_str "${CUSTOM_MAKEFILE}" "LDFLAGS") | ||
separate_arguments(LDFLAGS NATIVE_COMMAND ${ldflags_str}) | ||
# Need to fully specify the link script path | ||
list(TRANSFORM LDFLAGS REPLACE "^-T" "-T${CMAKE_CURRENT_SOURCE_DIR}/") | ||
# Cannot have "build/" in front of the map output. | ||
list(TRANSFORM LDFLAGS REPLACE "Map=.*\\.map" "Map=${CMAKE_PROJECT_NAME}.map") | ||
|
||
# Prepare the driver target | ||
add_library(driver) | ||
set_target_properties(driver PROPERTIES LINKER_LANGUAGE C) # required since the source files are object files | ||
|
||
# The sources are all the object files compiled with the CubeMX Makefile | ||
FILE(GLOB OBJ_DRIVER CONFIGURE_DEPENDS "build/*.o") | ||
target_sources(driver PUBLIC ${OBJ_DRIVER}) | ||
|
||
# Apply the Makefile settings to the targets | ||
target_include_directories(driver PUBLIC ${C_INCLUDES}) | ||
target_compile_definitions(driver PUBLIC ${C_DEFS}) | ||
|
||
target_compile_options(driver | ||
PUBLIC | ||
${MCU} | ||
-fdata-sections | ||
-ffunction-sections | ||
-Wall | ||
-Wextra | ||
-Wpedantic | ||
-Wshadow | ||
-Wdouble-promotion | ||
-Wformat=2 -Wformat-truncation | ||
-Wundef | ||
-fno-common | ||
-Wno-unused-parameter | ||
-Wno-missing-field-initializers | ||
$<$<COMPILE_LANGUAGE:CXX>: | ||
-Wno-old-style-cast | ||
-Wno-useless-cast | ||
-Wconversion | ||
-Wno-volatile | ||
-Wsuggest-override> | ||
$<$<CONFIG:Debug>:-Og -g3 -ggdb> | ||
$<$<CONFIG:Release>:-Og -g0> | ||
) | ||
|
||
# Notice that the linker settings are set for the "main" target. | ||
target_link_options(main | ||
PRIVATE | ||
${LDFLAGS} | ||
$<$<VERSION_GREATER:$<C_COMPILER_VERSION>,10.3.1>:-Wl,--no-warn-rwx-segments> | ||
-Wl,--start-group | ||
-Wl,--end-group | ||
-Wl,--print-memory-usage | ||
) | ||
set(CMAKE_TOOLCHAIN_FILE "${DIR_PLATFORM}/cubemx/cmake/racecar-toolchain.cmake") |
This file was deleted.
Oops, something went wrong.
This file contains 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,14 @@ | ||
# Modify the CubeMX-generated toolchain file to work with out build system. | ||
# These commands are not in the Makefile since Make messes with the ${} characters | ||
# in the `sed` replacement string. | ||
|
||
# CubeMX forces CMake to skip its automatic compiler detection, which messes | ||
# with our clangd setup. Comment out the lines that do this. | ||
sed -E '/set\(CMAKE.*COMPILER_FORCED.*$/s/^/# /g' $1 > tmp.txt | ||
mv tmp.txt $1 | ||
|
||
# CubeMX incorrectly assumes that our top-level CMakeLists.txt is in the same | ||
# directory as the .ioc file. This means that the linker script directory is wrong. | ||
# Find the "-T ** .ld" line and replace the CMAKE variable with the current directory. | ||
sed -E "/-T.*\.ld/s|\\\$\{CMAKE_SOURCE_DIR\}|${PWD}|g" $1 > tmp.txt | ||
mv tmp.txt $1 |
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
target_sources(main PUBLIC main.cc) | ||
target_sources(main PRIVATE main.cc) |
5 changes: 2 additions & 3 deletions
5
firmware/projects/Demo/AnalogPWM/platforms/cli/CMakeLists.txt
This file contains 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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
target_sources(bindings PRIVATE bindings.cc) | ||
|
||
target_link_libraries(bindings PUBLIC mcal-cli) | ||
target_sources(main PRIVATE bindings.cc) | ||
target_link_libraries(main PRIVATE mcal-cli) |
This file contains 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 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,12 @@ | ||
#pragma once | ||
|
||
#include "shared/periph/gpio.h" | ||
|
||
namespace bindings { | ||
|
||
extern shared::periph::DigitalInput& button_di; | ||
extern shared::periph::DigitalOutput& indicator_do; | ||
|
||
extern void Initialize(); | ||
|
||
} // namespace bindings |
Oops, something went wrong.