Skip to content
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

Minimal tools for C #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
137 changes: 137 additions & 0 deletions Template/Minimal_Tools/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...

18 changes: 18 additions & 0 deletions Template/Minimal_Tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Exclude these files from root level .gitignore
build

# Files
!stm32l4discovery.cfg

# Remove everything
.vscode/*.DB*
.vscode/*.json

# Keep these for reference
!.vscode/launch.json
!.vscode/c_cpp_properties.json
!.vscode/tasks.json

# Python
__pycache__
*.pyc
22 changes: 22 additions & 0 deletions Template/Minimal_Tools/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"configurationProvider": "ms-vscode.cmake-tools",
"intelliSenseMode": "gcc-arm",
"browse": {
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
},
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
33 changes: 33 additions & 0 deletions Template/Minimal_Tools/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"configurations": [
{
"cwd": "${workspaceFolder}",
"executable": "build/Minimal_Interfaces.elf",
"configFiles": [
"stm32l4discovery.cfg"
],
"postLaunchCommands": [
"monitor arm semihosting enable",
],
"name": "Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
},
{
"cwd": "${workspaceFolder}",
"executable": "build/Minimal_Interfaces.elf",
"configFiles": [
"stm32l4discovery.cfg"
],
"preLaunchTask": "task_build_and_flash",
"postLaunchCommands": [
"monitor arm semihosting enable",
],
"name": "Flash and Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
}
]
}
12 changes: 12 additions & 0 deletions Template/Minimal_Tools/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "task_build_and_flash",
"type": "shell",
"command": "cmake --build build --target flash"
}
]
}
109 changes: 109 additions & 0 deletions Template/Minimal_Tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
cmake_minimum_required(VERSION 3.16)

# Set your constants inside this file
include(options.cmake)

if (NOT TESTING)
set(CMAKE_TOOLCHAIN_FILE "cmake/toolchain.cmake")
endif()

project(${PROJECT_NAME})

# CMake Settings
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CMake functions
include(cmake/function.cmake)
include(cmake/test/target.cmake)

# Cross Compilation Flags
include(cmake/compile_flags.cmake)

# TODO, Add more subdirectory includes here
ess_include(l0_lowlevel)
ess_include_script(l1_third_party/FreeRTOS/FreeRTOS.cmake)
ess_include(l2_driver)
ess_include(l2_peripheral)
ess_include(l5_application)

set(USER_INCLUDE_DIRS
${l0_lowlevel_dirs}
${FreeRTOS_dirs}
${l2_driver_dirs}
${l2_peripheral_dirs}
${l5_application_dirs}
)

set(USER_SOURCES
${l0_lowlevel_sources}
${FreeRTOS_sources}
${l2_driver_sources}
${l2_peripheral_sources}
${l5_application_sources}
)

set(USER_CLANG_SOURCES
${l2_driver_sources}
${l2_peripheral_sources}
${l5_application_sources}
)

set(USER_CLANG_INC_DIRS
${l2_driver_dirs}
${l2_peripheral_dirs}
${l5_application_dirs}
)

# Set Global requirements for both unit-tests and arm targets
add_compile_definitions(${CONTROLLER_NAME})

if (TESTING)

message("Configuring Testing")

include(CTest)
enable_testing()

# Unit Testing libraries
include(cmake/testing.cmake)

# TODO, Add more mocks here

# TODO, Update this w.r.t the mocks above
set(USER_TEST_DIRS
${USER_INCLUDE_DIRS}
${rcc_mock_include_dirs}
${gpio_mock_include_dirs}
)

# TODO, Add more tests here

# NOTE, Append to USER_CLANG_SOURCES and USER_CLANG_INC_DIRS
# to add unit-tests to clang format

# TODO, Add code coverage tool

else()

message("Configuring ARM Project")

# Tools to add before target is defined
## Static analysis tool
include(cmake/tool/cppcheck.cmake)

# Cross Compiled project
include(cmake/project/project_release.cmake)
# TODO, Add more projects here

# Features
include(cmake/cross/semihosting.cmake)

# Tools
include(cmake/compile.cmake)
include(cmake/flash.cmake)
# TODO, Add documentation generator tool

endif()

# TODO, Add Clang format tool
include(cmake/tool/clangformat.cmake)
31 changes: 31 additions & 0 deletions Template/Minimal_Tools/cmake/compile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set(TOOLS_ARM_EABI_NONE_SIZE "arm-none-eabi-size")
add_custom_command(
TARGET ${USER_PROJECT_TARGET}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -O ihex ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex
COMMAND
${CMAKE_OBJDUMP} --source --all-headers --demangle --line-numbers --wide
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf >
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.lst
VERBATIM USES_TERMINAL)

add_custom_target(size ALL
DEPENDS ${USER_PROJECT_TARGET}
COMMAND ${TOOLS_ARM_EABI_NONE_SIZE} --format=berkeley ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf
VERBATIM USES_TERMINAL)

# TODO, Shift these to its own file
add_custom_target(
openocd_start_server
DEPENDS ${USER_PROJECT_TARGET}
COMMAND openocd.exe -f ${PROJECT_SOURCE_DIR}/stm32l4discovery.cfg
VERBATIM USES_TERMINAL)

add_custom_target(
openocd_connect_client
DEPENDS ${USER_PROJECT_TARGET}
COMMAND arm-none-eabi-gdb.exe ${PROJECT_BINARY_DIR}/${USER_PROJECT_TARGET}
VERBATIM USES_TERMINAL)
Loading