Skip to content
Merged
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
123 changes: 81 additions & 42 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,87 @@
{
"version": "0.2.0",
"configurations": [
{
"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"
},
{
"name": "Build and Debug STM32H723 (OpenOCD + RTT)",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/out/build/latest.elf",
"servertype": "openocd",
"configFiles": [
"interface/stlink.cfg",
"target/stm32h7x.cfg"
],
"serverpath": "openocd",
"device": "STM32H723ZGTx",
"interface": "swd",
"runToEntryPoint": "main",
"svdFile":"./STM32H723.svd",
"showDevDebugOutput": "parsed",
"postLaunchCommands": [
"monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"",
"monitor rtt start",
"monitor rtt server start 9090 0"
],
"postRestartCommands": [
"monitor halt",
"monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"",
"monitor rtt start",
"monitor rtt server start 9090 0"
],
"rttConfig": {
"enabled": true,
"address": "auto",
"decoders": [
{
"port": 0,
"type": "console"
}
]
},
"preLaunchTask": "CMake: build then pre-flash check"

},
{
"name": "Debug STM32H723 (OpenOCD + RTT) - No Build",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/out/build/latest.elf",
"servertype": "openocd",
"configFiles": [
"interface/stlink.cfg",
"target/stm32h7x.cfg"
],
"serverpath": "openocd",
"device": "STM32H723ZGTx",
"interface": "swd",
"runToEntryPoint": "main",
"svdFile":"./STM32H723.svd",
"showDevDebugOutput": "parsed",
"postLaunchCommands": [
"monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"",
"monitor rtt start",
"monitor rtt server start 9090 0"
],
"postRestartCommands": [
"monitor halt",
"monitor rtt setup 0x24000000 0x24080000 \"SEGGER RTT\"",
"monitor rtt start",
"monitor rtt server start 9090 0"
],
"rttConfig": {
"enabled": true,
"address": "auto",
"decoders": [
{
"port": 0,
"type": "console"
}
]
},
"preLaunchTask": "Pre-flash check"
},
{
"name": "Debug simulator on Rosetta",
"type": "cppdbg",
Expand Down
21 changes: 20 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
"command": "ROSETTA_DEBUGSERVER_PORT=1234 ./out/build/latest.elf",
"problemMatcher": [],
"isBackground": true
},
{
"label": "Pre-flash check",
"type": "shell",
"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"],
"dependsOrder": "sequence",
"problemMatcher": []
}
]
}
}
41 changes: 29 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ project(template-project LANGUAGES ASM C CXX)
set(EXECUTABLE ${PROJECT_NAME}.elf)
set(STLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/ST-LIB)
set(LD_SCRIPT ${CMAKE_SOURCE_DIR}/STM32H723ZGTX_FLASH.ld)
set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/bin/python)

if(CMAKE_HOST_WIN32 )
set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/Scripts/python)
else()
set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/bin/python)
endif()
option(USE_ETHERNET "Enable ethernet peripheral" OFF)
option(TARGET_NUCLEO "Targets the STM32H723 Nucleo dev board" OFF)

Expand Down Expand Up @@ -93,22 +96,36 @@ add_custom_target(generate_binary_metadata ALL
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating binary metadata"
)
add_dependencies(${EXECUTABLE} generate_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
$<TARGET_FILE:${EXECUTABLE}>
${CMAKE_SOURCE_DIR}/out/build/latest.elf
COMMENT "Copying ${EXECUTABLE} to out/build/latest.elf"
)

add_custom_command(
TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_CURRENT_SOURCE_DIR}/out/build
COMMAND ${CMAKE_COMMAND} -E create_symlink
$<TARGET_FILE:${EXECUTABLE}>
${CMAKE_CURRENT_SOURCE_DIR}/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()
27 changes: 27 additions & 0 deletions tools/init.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo off
setlocal enabledelayedexpansion
# This script is supposed to be under ${REPO_PATH}/tools/init.bat

REM Get the script directory and repo directory
set "SCRIPT_DIR=%~dp0"
set "REPO_DIR=%SCRIPT_DIR%.."

echo Script directory: %SCRIPT_DIR%
echo Repository directory: %REPO_DIR%

REM Change to repo directory
cd /d "%REPO_DIR%"

REM Create virtual environment
python -m venv virtual

REM Activate virtual environment
call virtual\Scripts\activate.bat

REM Install requirements
pip install -r requirements.txt

REM Update git submodules
git submodule update --init

echo Setup complete!
17 changes: 17 additions & 0 deletions tools/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

# This script is supposed to be under ${REPO_PATH}/tools/init.sh

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd -- "${SCRIPT_DIR}/.." && pwd)"

echo "Script directory: $SCRIPT_DIR"
echo "Repository directory: $REPO_DIR"

cd "$REPO_DIR"
python3 -m venv virtual
source ./virtual/bin/activate
pip install -r requirements.txt

git submodule update --init
62 changes: 62 additions & 0 deletions tools/preflash_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""
Pre-flash check script.
Checks for uncommitted changes and commits them if the binary was compiled with BOARD symbol.
"""

import subprocess
import sys
import os
from pathlib import Path

def get_script_dir() -> Path:
return Path(__file__).parent.resolve()

def get_workspace_dir() -> Path:
return get_script_dir().parent

def check_board_symbol(build_dir: Path) -> bool:
"""Check if the binary was compiled with BOARD symbol."""
marker_file = build_dir / "board_build_marker"
return marker_file.exists()

def has_uncommitted_changes(workspace_dir: Path) -> bool:
"""Check if there are uncommitted changes in the repository."""
result = subprocess.run(
["git", "status", "--porcelain"],
cwd=workspace_dir,
capture_output=True,
text=True
)
return bool(result.stdout.strip())

def main():
workspace_dir = get_workspace_dir()

# Default build directory - can be overridden by command line argument
if len(sys.argv) > 1:
build_dir = Path(sys.argv[1])
else:
build_dir = workspace_dir / "out" / "build"

print(f"Workspace directory: {workspace_dir}")
print(f"Build directory: {build_dir}")

# Check if this is a BOARD build
if not check_board_symbol(build_dir):
print("Binary was not compiled with BOARD symbol (or marker not found). Skipping pre-flash check.")
sys.exit(0)

print("Binary was compiled with BOARD symbol. Checking for uncommitted changes...")

if has_uncommitted_changes(workspace_dir):
print("Uncommitted changes detected. Aborting Flash...")
print("Please before flashing a board make sure all changes are commited");
sys.exit(1)
else:
print("No uncommitted changes. Proceeding with flash.")

sys.exit(0)

if __name__ == "__main__":
main()