Skip to content

Commit

Permalink
Add VSCode and CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jan 7, 2022
1 parent 634409e commit e6bd9bf
Show file tree
Hide file tree
Showing 31 changed files with 1,871 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 4,
"configurations": [
{
"name": "STM32",
"includePath": [],
"defines": [],
"compilerPath": "",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "${default}",

/* Use this and all the include paths will come from CMake configuration instead */
"configurationProvider": "ms-vscode.cmake-tools"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "GCC arm-none-eabi - custom toolchain setup",
"compilers": {
"C": "arm-none-eabi-gcc",
"CXX": "arm-none-eabi-g++"
},
"toolchainFile": "gcc-arm-none-eabi.cmake"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Microcontroller - STLink-V3",
"cwd": "${workspaceFolder}",
"type": "cortex-debug",
"executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf
"request": "launch", //Use "attach" to connect to target w/o elf download
"servertype": "stlink",
"device": "STM32H735IG", //MCU used
"interface": "swd",
"serialNumber": "", //Set ST-Link ID if you use multiple at the same time
"runToMain": true,
"svdFile": "STM32H73x.svd", //SVD file to see reisters
"v1": false,
"showDevDebugOutput": true,

/* Will get automatically detected if STM32CubeIDE is installed to default directory
or it can be manually provided if necessary.. */
//"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe",
//"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin",
//"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin",

/* If you use external loader, add additional arguments */
//"serverArgs": ["--extload", "path/to/ext/loader.stldr"],
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build project",
"command": "cmake",
"args": ["--build", "\"build\""],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Re-build project",
"command": "cmake",
"args": ["--build", "\"build\"", "--clean-first", "-v"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
},
{
"type": "shell",
"label": "Clean project",
"command": "cmake",
"args": ["--build", "\"build\"", "--target", "clean"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Run CMake configuration",
"command": "cmake",
"args": [
"--no-warn-unused-cli",
"-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE",
"-DCMAKE_BUILD_TYPE:STRING=Debug",
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=gcc-arm-none-eabi.cmake",
"-Bbuild",
"-G", "Ninja"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
}
]
}
246 changes: 246 additions & 0 deletions examples/stm32/ow_ds18b20_multi_rtos_stm32f429zi_nucleo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
cmake_minimum_required(VERSION 3.22)

message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")

#
# Core project settings
#
set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR})
project(lwow_stm32f429zi_nucleo_ds18b20_multi_rtos)
enable_language(C CXX ASM)
message("Build type: " ${CMAKE_BUILD_TYPE})

# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

#
# Core MCU flags, CPU, instruction set and FPU setup
#
set(CPU_PARAMETERS
-mthumb
-mcpu=cortex-m4
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
)

# Set linker script
set(linker_script_SRC ${PROJ_PATH}/STM32F429ZITX_FLASH.ld)
set(EXECUTABLE ${CMAKE_PROJECT_NAME})

#
# Source files
#
set(linked_SRCS
${PROJ_PATH}/../../../lwow/src/lwow/lwow.c
${PROJ_PATH}/../../../lwow/src/devices/lwow_device_ds18x20.c
${PROJ_PATH}/../../../lwow/src/system/lwow_ll_stm32_hal.c
${PROJ_PATH}/../../../lwow/src/system/lwow_sys_cmsis_os.c
${PROJ_PATH}/../../../snippets/scan_devices.c
)
set(source_folder_Core_SRCS
${PROJ_PATH}/Core/Src/freertos.c
${PROJ_PATH}/Core/Src/main.c
${PROJ_PATH}/Core/Src/stm32f4xx_hal_msp.c
${PROJ_PATH}/Core/Src/stm32f4xx_hal_timebase_tim.c
${PROJ_PATH}/Core/Src/stm32f4xx_it.c
${PROJ_PATH}/Core/Src/syscalls.c
${PROJ_PATH}/Core/Src/sysmem.c
${PROJ_PATH}/Core/Src/system_stm32f4xx.c
${PROJ_PATH}/Core/Startup/startup_stm32f429zitx.s)

set(source_folder_Drivers_SRCS
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c)

set(source_folder_Middlewares_SRCS
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/croutine.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/list.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/queue.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/tasks.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/timers.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c)

set(source_folder_lwow_SRCS
)

# Source files in the same path as ".cproject/.project" but nowhere included in file descriptions
set(all_project_dir_SRCS

)

#
# Include directories
#
set(include_c_DIRS
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/include
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
${PROJ_PATH}/Drivers/CMSIS/Include
${PROJ_PATH}/../../../lwow/src/include
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Inc
${PROJ_PATH}/Core/Inc
${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32F4xx/Include
${PROJ_PATH}/../../../snippets/include
${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
${PROJ_PATH}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
)
set(include_cxx_DIRS

)
set(include_asm_DIRS

)

#
# Symbols definition
#
set(symbols_c_SYMB
"USE_HAL_DRIVER"
"DEBUG"
"STM32F429xx"
)
set(symbols_cxx_SYMB

)
set(symbols_asm_SYMB

)

#
# Link directories setup
# Must be before executable is added
#
set(link_DIRS

)
link_directories(${EXECUTABLE} ${link_DIRS})

#
# Executable files
#
add_executable(${EXECUTABLE}
${linked_SRCS}
${all_project_dir_SRCS}
${source_folder_Core_SRCS}
${source_folder_Drivers_SRCS}
${source_folder_Middlewares_SRCS}
${source_folder_lwow_SRCS})

#
# Add linked libraries for linker
#
set(link_LIBS

)
target_link_libraries(${EXECUTABLE} ${link_LIBS})

#
# Project symbols
#
target_compile_definitions(${EXECUTABLE} PRIVATE
# Language specific only
$<$<COMPILE_LANGUAGE:C>: ${symbols_c_SYMB}>
$<$<COMPILE_LANGUAGE:CXX>: ${symbols_cxx_SYMB}>
$<$<COMPILE_LANGUAGE:ASM>: ${symbols_asm_SYMB}>

# Configuration specific
$<$<CONFIG:Debug>:
DEBUG
>
$<$<CONFIG:Release>: >
)

#
# Add include paths for each of the compiler
#
target_include_directories(${EXECUTABLE} PRIVATE
# Language specific only
$<$<COMPILE_LANGUAGE:C>: ${include_c_DIRS}>
$<$<COMPILE_LANGUAGE:CXX>: ${include_cxx_DIRS}>
$<$<COMPILE_LANGUAGE:ASM>: ${include_asm_DIRS}>

# Configuration specific
$<$<CONFIG:Debug>: >
$<$<CONFIG:Release>: >
)

# Compiler and linker options
target_compile_options(${EXECUTABLE} PRIVATE
${CPU_PARAMETERS}
-Wall
-Wextra
-Wpedantic
-Wno-unused-parameter
$<$<COMPILE_LANGUAGE:C>:

>
$<$<COMPILE_LANGUAGE:CXX>:
#-Wno-volatile
#-Wold-style-cast
#-Wuseless-cast
#-Wsuggest-override
>
$<$<COMPILE_LANGUAGE:ASM>:

>
$<$<CONFIG:Debug>:
-Og -g3 -ggdb
>
$<$<CONFIG:Release>:
-Og -g0
>
)

# Setup linker parameters
target_link_options(${EXECUTABLE} PRIVATE
-T${MCU_LINKER_SCRIPT}${linker_script_SRC}
${CPU_PARAMETERS}
-Wl,-Map=${CMAKE_PROJECT_NAME}.map
--specs=nosys.specs
-Wl,--start-group
-lc
-lm
-lstdc++
-lsupc++
-Wl,--end-group
-Wl,--print-memory-usage
)

# Execute post-build to print size
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${EXECUTABLE}>
)

# Convert output to hex and binary
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${EXECUTABLE}> ${EXECUTABLE}.hex
)

# Conver to bin file -> add conditional check?
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${EXECUTABLE}> ${EXECUTABLE}.bin
)

message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

# Some default GCC settings
# arm-none-eabi- must be part of path environment
set(TOOLCHAIN_PREFIX arm-none-eabi-)
set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections")
set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics")

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS})
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS})
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)

set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

0 comments on commit e6bd9bf

Please sign in to comment.