diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2864d04..196da5a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: preset: description: > CMake preset to build the project, run - `cmake --build --list-presets` to see options + `cmake --list-presets` to see options required: false type: string default: 'nucleo-debug' @@ -20,7 +20,7 @@ on: preset: description: > CMake preset to build the project, run - `cmake --build --list-presets` to see options + `cmake --list-presets` to see options required: false type: string default: 'nucleo-debug' @@ -76,4 +76,4 @@ jobs: path: out/build/latest.elf retention-days: 7 compression-level: 0 - if-no-files-found: error \ No newline at end of file + if-no-files-found: error diff --git a/.github/workflows/compile-checks.yml b/.github/workflows/compile-checks.yml index 9cfea1a7..19c1e5b1 100644 --- a/.github/workflows/compile-checks.yml +++ b/.github/workflows/compile-checks.yml @@ -28,9 +28,12 @@ jobs: - board-debug - board-release - board-relwithdebinfo - - board-debug-eth - - board-release-eth - - board-relwithdebinfo-eth + - board-debug-eth-ksz8041 + - board-debug-eth-lan8700 + - board-release-eth-ksz8041 + - board-release-eth-lan8700 + - board-relwithdebinfo-eth-ksz8041 + - board-relwithdebinfo-eth-lan8700 # - simulator fail-fast: false uses: ./.github/workflows/build.yml diff --git a/.vscode/launch.json b/.vscode/launch.json index dea90b45..2b644dbf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,6 @@ { - "version": "0.2.0", - "configurations": [ + "version": "0.2.0", + "configurations": [ { "name": "Build and Debug STM32H723 (OpenOCD + RTT)", "type": "cortex-debug", @@ -16,7 +16,7 @@ "device": "STM32H723ZGTx", "interface": "swd", "runToEntryPoint": "main", - "svdFile":"./STM32H723.svd", + "svdFile": "./STM32H723.svd", "showDevDebugOutput": "parsed", "postLaunchCommands": [ "monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"", @@ -39,8 +39,7 @@ } ] }, - "preLaunchTask": "CMake: build then pre-flash check" - + "preLaunchTask": "CMake: build" }, { "name": "Debug STM32H723 (OpenOCD + RTT) - No Build", @@ -57,7 +56,7 @@ "device": "STM32H723ZGTx", "interface": "swd", "runToEntryPoint": "main", - "svdFile":"./STM32H723.svd", + "svdFile": "./STM32H723.svd", "showDevDebugOutput": "parsed", "postLaunchCommands": [ "monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"", @@ -80,26 +79,86 @@ } ] }, - "preLaunchTask": "Pre-flash check" + // "preLaunchTask": "Pre-flash check" }, - { - "name": "Debug simulator on Rosetta", - "type": "cppdbg", - "request": "launch", - "program": "out/build/latest.elf", - "miDebuggerServerAddress": "localhost:1234", - "miDebuggerPath": "/usr/bin/gdb", - "MIMode": "gdb", - "setupCommands": [ { - "description": "Set architecture to x86-64", - "text": "set architecture i386:x86-64", - "ignoreFailures": false + "name": "Debug simulator on Rosetta", + "type": "cppdbg", + "request": "launch", + "program": "out/build/latest.elf", + "miDebuggerServerAddress": "localhost:1234", + "miDebuggerPath": "/usr/bin/gdb", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Set architecture to x86-64", + "text": "set architecture i386:x86-64", + "ignoreFailures": false + } + ], + "preLaunchTask": "Start Debug Server for Simulator on emulated arch", + "cwd": "${workspaceFolder}", + "externalConsole": false + }, + { + "type": "cortex-debug", + "request": "launch", + "name": "Build and Debug Project", + "servertype": "stlink", + "cwd": "${workspaceRoot}", + "runToEntryPoint": "main", + "showDevDebugOutput": "raw", + "executable": "out/build/latest.elf", + "device": "STM32H723ZG", + "configFiles": [ + ".vscode/stlink.cfg", + ".vscode/stm32h7x.cfg" + ], + "svdFile": ".vscode/STM32H723.svd", + "swoConfig": { + "enabled": true, + "cpuFrequency": 8000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM", + "port": 0 + } + ] + }, + "preLaunchTask": "CMake: build" + }, + { + "type": "cortex-debug", + "request": "launch", + "name": "Debug Project", + "servertype": "stlink", + "cwd": "${workspaceRoot}", + "runToEntryPoint": "main", + "showDevDebugOutput": "raw", + "executable": "out/build/latest.elf", + "device": "STM32H723ZG", + "configFiles": [ + ".vscode/stlink.cfg", + ".vscode/stm32h7x.cfg" + ], + "svdFile": "./STM32H723.svd", + "swoConfig": { + "enabled": true, + "cpuFrequency": 8000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM", + "port": 0 + } + ] + }, + "stm32cubeprogrammer": "/opt/st/stm32cubeclt_1.16.0/STM32CubeProgrammer/bin" } - ], - "preLaunchTask": "Start Debug Server for Simulator on emulated arch", - "cwd": "${workspaceFolder}", - "externalConsole": false - } - ] -} + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bf4f5d3f..f393b8b6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,22 +8,22 @@ "problemMatcher": [], "isBackground": true }, - { - "label": "Pre-flash check", - "type": "shell", - "command": "${workspaceFolder}/virtual/bin/python", - "windows": { - "command": "${workspaceFolder}/virtual/Scripts/python" - }, - "args": [ - "${workspaceFolder}/tools/preflash_check.py" - ], - "problemMatcher": [], - "presentation": { - "reveal": "always", - "panel": "shared" - } - }, + // { + // "label": "Pre-flash check", + // "type": "shell", + // "command": "${workspaceFolder}/virtual/bin/python", + // "windows": { + // "command": "${workspaceFolder}/virtual/Scripts/python" + // }, + // "args": [ + // "${workspaceFolder}/tools/preflash_check.py" + // ], + // "problemMatcher": [], + // "presentation": { + // "reveal": "always", + // "panel": "shared" + // } + // }, { "label": "CMake: build then pre-flash check", "dependsOn": ["CMake: build", "Pre-flash check"], diff --git a/CMakeLists.txt b/CMakeLists.txt index 354cbc73..ee8dd6df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,44 +5,48 @@ project(template-project LANGUAGES ASM C CXX) set(EXECUTABLE ${PROJECT_NAME}.elf) set(Board "VCU") # User must change the Board name set(STLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/ST-LIB) -set(LD_SCRIPT ${STLIB_DIR}/STM32H723ZGTX_FLASH.ld) +set(LD_SCRIPT ${STLIB_DIR}/STM32H723ZGTX_FLASH.ld) find_package(Python3 COMPONENTS Interpreter REQUIRED) set(GENERATOR_SCRIPT "${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/Generator.py") -add_custom_target(run_generator ALL - COMMAND ${Python3_EXECUTABLE} ${GENERATOR_SCRIPT} ${Board} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -if(CMAKE_HOST_WIN32 ) +if(CMAKE_HOST_WIN32) set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/Scripts/python) else() set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/bin/python) endif() -add_custom_target( - my_custom_target_that_always_runs ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_tmp.h -) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/_tmp.h # fake! ensure we run! - COMMAND ${VENV_PYTHON} ${CMAKE_SOURCE_DIR}/tools/generate_binary_metadata.py -) - option(USE_ETHERNET "Enable ethernet peripheral" OFF) option(TARGET_NUCLEO "Targets the STM32H723 Nucleo development board" OFF) +option(BUILD_EXAMPLES "Build Core/Src/Examples sources" OFF) +option(USE_CCACHE "Use ccache if available" ON) +if(NOT DEFINED ENABLE_LTO) + if(CMAKE_CROSSCOMPILING) + set(ENABLE_LTO OFF) + else() + set(ENABLE_LTO ON) + endif() +endif() +set(ENABLE_LTO "${ENABLE_LTO}" CACHE BOOL "Enable link-time optimization (LTO)") + +if(USE_CCACHE) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) + set(CMAKE_ASM_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) + endif() +endif() -if (PROJECT_IS_TOP_LEVEL AND (NOT CMAKE_CROSSCOMPILING)) +if(PROJECT_IS_TOP_LEVEL AND (NOT CMAKE_CROSSCOMPILING)) include(FetchContent) option(BUILD_GMOCK OFF) option(INSTALL_GTEST OFF) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.15.2 + GIT_TAG v1.15.2 ) FetchContent_MakeAvailable(googletest) add_library(GTest::GTest INTERFACE IMPORTED) @@ -56,115 +60,182 @@ message(STATUS "Template project: TARGET_NUCLEO = ${TARGET_NUCLEO}") add_subdirectory(${STLIB_DIR}) message(STATUS "Using ST-LIB target: ${STLIB_LIBRARY}") -file(GLOB_RECURSE SOURCE_C ${CMAKE_SOURCE_DIR}/Core/*.c) -file(GLOB_RECURSE SOURCE_CPP ${CMAKE_SOURCE_DIR}/Core/*.cpp) -file(GLOB_RECURSE SOURCE_H ${CMAKE_SOURCE_DIR}/Core/*.h) -file(GLOB_RECURSE SOURCE_HPP ${CMAKE_SOURCE_DIR}/Core/*.hpp) - -add_executable(${EXECUTABLE} - ${SOURCE_C} - ${SOURCE_CPP} - ${SOURCE_H} - ${SOURCE_HPP} - - $<$:${STLIB_DIR}/startup_stm32h723zgtx.s> -) - -target_link_libraries(${EXECUTABLE} PRIVATE - ${STLIB_LIBRARY} +file(GLOB_RECURSE GENERATOR_JSONS + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/JSON_ADE/*.json ) -set_target_properties(${EXECUTABLE} PROPERTIES - CXX_STANDARD 23 - CXX_STANDARD_REQUIRED YES - C_STANDARD 17 - C_STANDARD_REQUIRED YES +set(GENERATED_DATA_PACKETS ${CMAKE_SOURCE_DIR}/Core/Inc/Communications/Packets/DataPackets.hpp) +set(GENERATED_ORDER_PACKETS ${CMAKE_SOURCE_DIR}/Core/Inc/Communications/Packets/OrderPackets.hpp) +set(GENERATED_STATE_MACHINE ${CMAKE_SOURCE_DIR}/Core/Inc/state_machine.hpp) +add_custom_command( + OUTPUT + ${GENERATED_DATA_PACKETS} + ${GENERATED_ORDER_PACKETS} + ${GENERATED_STATE_MACHINE} + COMMAND ${VENV_PYTHON} ${GENERATOR_SCRIPT} ${Board} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + DEPENDS + ${GENERATOR_SCRIPT} + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/Packet_generation/Packet_generation.py + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/State_machine_generation/State_machine_generation.py + ${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/State_machine_generation/State_machine_description.py + ${CMAKE_SOURCE_DIR}/state_machine.json + ${GENERATOR_JSONS} + COMMENT "Generating packets and state machine" ) -target_compile_definitions(${EXECUTABLE} PRIVATE - $<$:STLIB_ETH> - $,NUCLEO,BOARD> - $,HSE_VALUE=8000000,HSE_VALUE=25000000> +add_custom_target(run_generator ALL + DEPENDS + ${GENERATED_DATA_PACKETS} + ${GENERATED_ORDER_PACKETS} + ${GENERATED_STATE_MACHINE} ) -target_compile_options(${EXECUTABLE} PRIVATE - $<$:-mcpu=cortex-m7> - $<$:-mfpu=fpv5-d16> - $<$:-mfloat-abi=hard> - $<$:-mthumb> - $<$:-specs=nosys.specs> - -g - -ffunction-sections - -fdata-sections - -fno-exceptions - - -Wno-psabi - - $<$:-w> - - $<$:-Wall> - # $<$:-Wpedantic> - $<$:-Werror> - $<$:-fno-use-cxa-atexit> - $<$:-fno-rtti> +file(GLOB_RECURSE METADATA_SOURCES + ${CMAKE_SOURCE_DIR}/Core/*.c + ${CMAKE_SOURCE_DIR}/Core/*.cpp + ${CMAKE_SOURCE_DIR}/Core/*.h + ${CMAKE_SOURCE_DIR}/Core/*.hpp ) -target_include_directories(${EXECUTABLE} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc -) +set(METADATA_OUTPUT ${CMAKE_SOURCE_DIR}/Core/Src/Runes/generated_metadata.cpp) +set(METADATA_TEMPLATE ${CMAKE_SOURCE_DIR}/tools/binary_metadata_template.cpp) +set(METADATA_SCRIPT ${CMAKE_SOURCE_DIR}/tools/generate_binary_metadata.py) -target_link_options(${EXECUTABLE} PRIVATE - $<$:-T${LD_SCRIPT}> - $<$:-mcpu=cortex-m7> - $<$:-mthumb> - $<$:-mfpu=fpv5-d16> - $<$:-mfloat-abi=hard> - $<$:-specs=nosys.specs> - $<$:-lc> - $<$:-lm> - $<$:-lnosys> - $<$:-Wl,-Map=${PROJECT_NAME}.map,--cref> - $<$:-Wl,--gc-sections> -) +list(REMOVE_ITEM METADATA_SOURCES ${METADATA_OUTPUT}) -add_custom_target(generate_binary_metadata ALL - COMMAND ${VENV_PYTHON} ${CMAKE_SOURCE_DIR}/tools/generate_binary_metadata.py +add_custom_command( + OUTPUT ${METADATA_OUTPUT} + COMMAND ${VENV_PYTHON} ${METADATA_SCRIPT} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + DEPENDS + ${METADATA_SCRIPT} + ${METADATA_TEMPLATE} + ${METADATA_SOURCES} COMMENT "Generating binary metadata" ) -add_dependencies(${EXECUTABLE} generate_binary_metadata) -if (PROJECT_IS_TOP_LEVEL) - execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink - ${CMAKE_BINARY_DIR}/compile_commands.json - ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json - ) -endif() -# Post-build: Copy binary to out/build/latest.elf and create marker for BOARD builds -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - # Create output directory - COMMAND ${CMAKE_COMMAND} -E make_directory - ${CMAKE_SOURCE_DIR}/out/build - # Copy the built binary to out/build/latest.elf - COMMAND ${CMAKE_COMMAND} -E copy - $ - ${CMAKE_SOURCE_DIR}/out/build/latest.elf - COMMENT "Copying ${EXECUTABLE} to out/build/latest.elf" +add_custom_target(generate_binary_metadata + DEPENDS ${METADATA_OUTPUT} ) -# Create or remove marker file for BOARD builds (used by preflash_check.py) -if(NOT TARGET_NUCLEO) - add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/out/build/board_build_marker - COMMENT "Creating BOARD build marker for pre-flash check" +if(CMAKE_CROSSCOMPILING) + file(GLOB_RECURSE SOURCE_C ${CMAKE_SOURCE_DIR}/Core/*.c) + file(GLOB_RECURSE SOURCE_CPP ${CMAKE_SOURCE_DIR}/Core/*.cpp) + file(GLOB_RECURSE SOURCE_H ${CMAKE_SOURCE_DIR}/Core/*.h) + file(GLOB_RECURSE SOURCE_HPP ${CMAKE_SOURCE_DIR}/Core/*.hpp) + + if(NOT BUILD_EXAMPLES) + file(GLOB_RECURSE EXAMPLE_CPP ${CMAKE_SOURCE_DIR}/Core/Src/Examples/*.cpp) + list(REMOVE_ITEM SOURCE_CPP ${EXAMPLE_CPP}) + endif() + + add_executable(${EXECUTABLE} + ${SOURCE_C} + ${SOURCE_CPP} + ${SOURCE_H} + ${SOURCE_HPP} + + $<$:${STLIB_DIR}/startup_stm32h723zgtx.s> ) -else() - add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_SOURCE_DIR}/out/build/board_build_marker - COMMENT "Removing BOARD build marker (NUCLEO build)" + + target_link_libraries(${EXECUTABLE} PRIVATE + ${STLIB_LIBRARY} ) -endif() + set_target_properties(${EXECUTABLE} PROPERTIES + CXX_STANDARD 23 + CXX_STANDARD_REQUIRED YES + C_STANDARD 17 + C_STANDARD_REQUIRED YES + ) + target_compile_definitions(${EXECUTABLE} PRIVATE + $<$:STLIB_ETH> + $,NUCLEO,BOARD> + $,HSE_VALUE=8000000,HSE_VALUE=25000000> + ) + + target_compile_options(${EXECUTABLE} PRIVATE + $<$:-mcpu=cortex-m7> + $<$:-mfpu=fpv5-d16> + $<$:-mfloat-abi=hard> + $<$:-mthumb> + $<$:-specs=nosys.specs> + $<$:-g> + $<$:-g> + -ffunction-sections + -fdata-sections + -fno-exceptions + + -Wno-psabi + + $<$:-w> + + $<$:-Wall> + # $<$:-Wpedantic> + $<$:-Werror> + $<$:-fno-use-cxa-atexit> + $<$:-fno-rtti> + ) + target_include_directories(${EXECUTABLE} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc + ) + + target_link_options(${EXECUTABLE} PRIVATE + $<$:-T${LD_SCRIPT}> + $<$:-mcpu=cortex-m7> + $<$:-mthumb> + $<$:-mfpu=fpv5-d16> + $<$:-mfloat-abi=hard> + $<$:-specs=nosys.specs> + $<$:-lc> + $<$:-lm> + $<$:-lnosys> + $<$:-Wl,-Map=${PROJECT_NAME}.map,--cref> + $<$:-Wl,--gc-sections> + ) + + add_dependencies(${EXECUTABLE} run_generator generate_binary_metadata) + + if(ENABLE_LTO) + set_property(TARGET ${EXECUTABLE} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) + set_property(TARGET ${EXECUTABLE} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON) + endif() + + # Post-build: Copy binary to out/build/latest.elf and create marker for BOARD builds + add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + # Create output directory + COMMAND ${CMAKE_COMMAND} -E make_directory + ${CMAKE_SOURCE_DIR}/out/build + # Copy the built binary to out/build/latest.elf + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/out/build/latest.elf + COMMENT "Copying ${EXECUTABLE} to out/build/latest.elf" + ) + + # Create or remove marker file for BOARD builds (used by preflash_check.py) + if(NOT TARGET_NUCLEO) + add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/out/build/board_build_marker + COMMENT "Creating BOARD build marker for pre-flash check" + ) + else() + add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_SOURCE_DIR}/out/build/board_build_marker + COMMENT "Removing BOARD build marker (NUCLEO build)" + ) + endif() +endif() + +if(PROJECT_IS_TOP_LEVEL) + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json + ) +endif() diff --git a/CMakePresets.json b/CMakePresets.json index 3c341ea8..f59704a4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -123,36 +123,75 @@ } }, { - "name": "board-debug-eth", - "displayName": "Board [DBG] [ETH]", + "name": "board-debug-eth-ksz8041", + "displayName": "Board [DBG] [ETH] [KSZ8041]", "inherits": [ "mcu" ], "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "USE_ETHERNET": "ON" + "USE_ETHERNET": "ON", + "PHY_TYPE": "KSZ8041" } }, { - "name": "board-release-eth", - "displayName": "Board [REL] [ETH]", + "name": "board-debug-eth-lan8700", + "displayName": "Board [DBG] [ETH] [LAN8700]", + "inherits": [ + "mcu" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "USE_ETHERNET": "ON", + "PHY_TYPE": "LAN8700" + } + }, + { + "name": "board-release-eth-ksz8041", + "displayName": "Board [REL] [ETH] [KSZ8041]", "inherits": [ "mcu" ], "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "USE_ETHERNET": "ON" + "USE_ETHERNET": "ON", + "PHY_TYPE": "KSZ8041" + } + }, + { + "name": "board-release-eth-lan8700", + "displayName": "Board [REL] [ETH] [LAN8700]", + "inherits": [ + "mcu" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "USE_ETHERNET": "ON", + "PHY_TYPE": "LAN8700" } }, { - "name": "board-relwithdebinfo-eth", - "displayName": "Board [RWD] [ETH]", + "name": "board-relwithdebinfo-eth-ksz8041", + "displayName": "Board [RWD] [ETH] [KSZ8041]", "inherits": [ "mcu" ], "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "USE_ETHERNET": "ON" + "USE_ETHERNET": "ON", + "PHY_TYPE": "KSZ8041" + } + }, + { + "name": "board-relwithdebinfo-eth-lan8700", + "displayName": "Board [RWD] [ETH] [LAN8700]", + "inherits": [ + "mcu" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "USE_ETHERNET": "ON", + "PHY_TYPE": "LAN8700" } }, { @@ -169,68 +208,67 @@ "buildPresets": [ { "name": "nucleo-debug", - "displayName": "Nucleo [DBG]", "configurePreset": "nucleo-debug" }, { "name": "nucleo-release", - "displayName": "Nucleo [REL]", "configurePreset": "nucleo-release" }, { "name": "nucleo-relwithdebinfo", - "displayName": "Nucleo [RWD]", "configurePreset": "nucleo-relwithdebinfo" }, { "name": "nucleo-debug-eth", - "displayName": "Nucleo [DBG] [ETH]", "configurePreset": "nucleo-debug-eth" }, { "name": "nucleo-release-eth", - "displayName": "Nucleo [REL] [ETH]", "configurePreset": "nucleo-release-eth" }, { "name": "nucleo-relwithdebinfo-eth", - "displayName": "Nucleo [RWD] [ETH]", "configurePreset": "nucleo-relwithdebinfo-eth" }, { "name": "board-debug", - "displayName": "Board [DBG]", "configurePreset": "board-debug" }, { "name": "board-release", - "displayName": "Board [REL]", "configurePreset": "board-release" }, { "name": "board-relwithdebinfo", - "displayName": "Board [RWD]", "configurePreset": "board-relwithdebinfo" }, { - "name": "board-debug-eth", - "displayName": "Board [DBG] [ETH]", - "configurePreset": "board-debug-eth" + "name": "board-debug-eth-ksz8041", + "configurePreset": "board-debug-eth-ksz8041" + }, + { + "name": "board-debug-eth-lan8700", + "configurePreset": "board-debug-eth-lan8700" }, { - "name": "board-release-eth", - "displayName": "Board [REL] [ETH]", - "configurePreset": "board-release-eth" + "name": "board-release-eth-ksz8041", + "configurePreset": "board-release-eth-ksz8041" }, { - "name": "board-relwithdebinfo-eth", - "displayName": "Board [RWD] [ETH]", - "configurePreset": "board-relwithdebinfo-eth" + "name": "board-release-eth-lan8700", + "configurePreset": "board-release-eth-lan8700" + }, + { + "name": "board-relwithdebinfo-eth-ksz8041", + "configurePreset": "board-relwithdebinfo-eth-ksz8041" + }, + { + "name": "board-relwithdebinfo-eth-lan8700", + "configurePreset": "board-relwithdebinfo-eth-lan8700" }, { "name": "simulator", - "displayName": "Simulator", "configurePreset": "simulator" } ] -} \ No newline at end of file +} diff --git a/Core/Src/Runes/Runes.cpp b/Core/Src/Runes/Runes.cpp index 16a735b0..d43f1d8d 100644 --- a/Core/Src/Runes/Runes.cpp +++ b/Core/Src/Runes/Runes.cpp @@ -17,19 +17,19 @@ ADC_HandleTypeDef hadc3; LPTIM_HandleTypeDef hlptim1; LPTIM_HandleTypeDef hlptim2; LPTIM_HandleTypeDef hlptim3; -TIM_HandleTypeDef htim1; -TIM_HandleTypeDef htim2; -TIM_HandleTypeDef htim3; -TIM_HandleTypeDef htim4; -TIM_HandleTypeDef htim5; -TIM_HandleTypeDef htim7; -TIM_HandleTypeDef htim8; -TIM_HandleTypeDef htim12; -TIM_HandleTypeDef htim16; -TIM_HandleTypeDef htim17; -TIM_HandleTypeDef htim15; -TIM_HandleTypeDef htim23; -TIM_HandleTypeDef htim24; +extern TIM_HandleTypeDef htim1; +extern TIM_HandleTypeDef htim2; +extern TIM_HandleTypeDef htim3; +extern TIM_HandleTypeDef htim4; +extern TIM_HandleTypeDef htim5; +extern TIM_HandleTypeDef htim7; +extern TIM_HandleTypeDef htim8; +extern TIM_HandleTypeDef htim12; +extern TIM_HandleTypeDef htim16; +extern TIM_HandleTypeDef htim17; +extern TIM_HandleTypeDef htim15; +extern TIM_HandleTypeDef htim23; +extern TIM_HandleTypeDef htim24; UART_HandleTypeDef huart1; UART_HandleTypeDef huart2; UART_HandleTypeDef huart3; diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index c367556e..a740113f 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -1,23 +1,53 @@ -#include "Examples/ExampleMPU.cpp" -#include "Examples/ExamplesHardFault.cpp" - -#include "main.h" -#include "ST-LIB.hpp" - -int main(void) { - Hard_fault_check(); - STLIB::start(); - - using myBoard = ST_LIB::Board<>; - myBoard::init(); - - while (1) { - STLIB::update(); - } -} -void Error_Handler(void) { - ErrorHandler("HAL error handler triggered"); - while (1) { - } -} - +#include "Examples/ExampleMPU.cpp" +#include "Examples/ExamplesHardFault.cpp" + +#include "ST-LIB.hpp" +#include "main.h" + +using namespace ST_LIB; + +constexpr auto led = ST_LIB::DigitalOutputDomain::DigitalOutput(ST_LIB::PB0); + +#ifdef STLIB_ETH +#if defined(USE_PHY_LAN8742) +constexpr auto eth = + EthernetDomain::Ethernet(EthernetDomain::PINSET_H10, "00:80:e1:00:01:07", + "192.168.1.7", "255.255.0.0"); +#elif defined(USE_PHY_LAN8700) +constexpr auto eth = + EthernetDomain::Ethernet(EthernetDomain::PINSET_H10, "00:80:e1:00:01:07", + "192.168.1.7", "255.255.0.0"); +#elif defined(USE_PHY_KSZ8041) +constexpr auto eth = + EthernetDomain::Ethernet(EthernetDomain::PINSET_H11, "00:80:e1:00:01:07", + "192.168.1.7", "255.255.0.0"); +#else +#error "No PHY selected for Ethernet pinset selection" +#endif + +using myBoard = ST_LIB::Board; +#else +using myBoard = ST_LIB::Board; +#endif + +int main(void) { + Hard_fault_check(); + + myBoard::init(); +#ifdef STLIB_ETH + auto eth_instance = &myBoard::instance_of(); +#endif + auto led_instance = &myBoard::instance_of(); + + led_instance->turn_on(); + while (1) { +#ifdef STLIB_ETH + eth_instance->update(); +#endif + } +} +void Error_Handler(void) { + ErrorHandler("HAL error handler triggered"); + while (1) { + } +} diff --git a/deps/ST-LIB b/deps/ST-LIB index 80d9efef..77224aa7 160000 --- a/deps/ST-LIB +++ b/deps/ST-LIB @@ -1 +1 @@ -Subproject commit 80d9efef0634408b10695db836da861a702bcde2 +Subproject commit 77224aa709b0b77e54f5a2cf2ce55bc6f0deb9af