diff --git a/.gitignore b/.gitignore index 2cd0460..76f7503 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ [Bb]uild/ [Dd]atasheets/ [Hh]ardware/ -.vscode/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..83926a9 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,42 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/avr-gcc", + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "-mmcu=atmega168a", + "-DF_CPU=1000000UL", + "-Os" + ] + }, + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.22000.0", + "compilerPath": "C:/avr8-gnu-toolchain/bin/avr-gcc", + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "-mmcu=atmega168a", + "-DF_CPU=1000000UL", + "-Os" + ] + } + ], + "version": 4 +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0fd541a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,33 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "Configure Project", + "command": "cmake", + "args": [ + "-B", "${workspaceFolder}/Build" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, + { + "type": "shell", + "label": "Build Project", + "dependsOn": "Configure Project", + "command": "cmake --build .", + "options": { + "cwd": "${workspaceFolder}/Build" + }, + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": { + "base": "$gcc", + "fileLocation": ["relative", ""] + } + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e00af5..82b6ec5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,11 @@ cmake_minimum_required(VERSION 3.20) -set(CMAKE_TOOLCHAIN_FILE toolchain.cmake) +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/toolchain.cmake) +message(STATUS "CMAKE_TOOLCHAIN_FILE is: ${CMAKE_TOOLCHAIN_FILE}") -# export compile commands to use for clang-tidy +# export compile commands for clang-tidy set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_VERBOSE_MAKEFILE ON) project(AtmegaTddExample VERSION 0.1.0 DESCRIPTION "ATmega TDD Example" LANGUAGES C) @@ -11,4 +13,10 @@ set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use") set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) +message(STATUS "CMAKE_C_COMPILER is: ${CMAKE_C_COMPILER}") + +# set serial port, works under Windows only +set(PORT_NUMBER COM6) +message(STATUS "Serial port set to: ${PORT_NUMBER}") + add_subdirectory(Src Bin) diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt index 79ac121..d627c80 100644 --- a/Src/CMakeLists.txt +++ b/Src/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(${EXECUTABLE} led.c low_power.c main.c superloop.c timer.c) -target_include_directories(${EXECUTABLE} PUBLIC ${PROJECT_SOURCE_DIR}/Inc) +target_include_directories(${EXECUTABLE} PRIVATE ${PROJECT_SOURCE_DIR}/Inc) set_target_properties(${EXECUTABLE} PROPERTIES OUTPUT_NAME ${EXECUTABLE}.elf) @@ -8,4 +8,4 @@ add_custom_target(size ALL ${AVR_SIZE} --format=avr --mcu=${AVR_MCU} ${EXECUTABL add_custom_target(hex ALL ${AVR_OBJCOPY} -j .text -j .data -O ihex ${EXECUTABLE}.elf ${EXECUTABLE}.hex) add_custom_target(erase COMMAND ${AVR_DUDE} -p ${AVR_PARTNO} -P ${PORT_NUMBER} -c ${AVR_PROGRAMMER} -e) -add_custom_target(upload COMMAND ${AVR_DUDE} -p ${AVR_PARTNO} -P ${PORT_NUMBER} -c ${AVR_PROGRAMMER} -U flash:w:${EXECUTABLE}.hex) \ No newline at end of file +add_custom_target(upload COMMAND ${AVR_DUDE} -p ${AVR_PARTNO} -P ${PORT_NUMBER} -c ${AVR_PROGRAMMER} -U flash:w:${EXECUTABLE}.hex) diff --git a/atmega-tdd-example.code-workspace b/atmega-tdd-example.code-workspace index c8fdb74..86ce597 100644 --- a/atmega-tdd-example.code-workspace +++ b/atmega-tdd-example.code-workspace @@ -6,26 +6,8 @@ ], "settings": { "files.associations": { - "delay.h": "c", - "stdint.h": "c", - "io.h": "c", - "iom168a.h": "c", - "iom168.h": "c", - "main.h": "c", - "led.h": "c", - "utils.h": "c", - "bit_manipulation.h": "c", - "runner.h": "c", - "executor.h": "c", - "stdbool.h": "c", - "superloop.h": "c", - "timer.h": "c", - "interrupt.h": "c", - "sleep.h": "c", - "low_power.h": "c", - "testable_mcu_registers.h": "c", - "fff.h": "c", - "commandlinetestrunner.h": "c" + "*.c": "c", + "*.h": "c" }, "cSpell.words": [ "Atmel", diff --git a/toolchain.cmake b/toolchain.cmake index 7823a06..c36f187 100644 --- a/toolchain.cmake +++ b/toolchain.cmake @@ -22,16 +22,23 @@ set(AVR_PARTNO m168) set(AVR_PROGRAMMER avrispv2) set(F_CPU "1000000UL") -# set serial port, works under Windows only -set(PORT_NUMBER COM6) - -# set linker flags -set(CMAKE_EXE_LINKER_FLAGS -mmcu=${AVR_MCU}) - # set compile options add_compile_options( -Wall -g -Os -mmcu=${AVR_MCU} - -DF_CPU=${F_CPU}) + -DF_CPU=${F_CPU} + ) + +# set linker options +add_link_options( + -mmcu=${AVR_MCU} + ) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)