This commit is contained in:
thomas committed 2026-10-18 23:39:44 +02:00
1 parent 2b9e574ba9
commit b119a6abd7
583 files changed
+224175 -218466

No files matched your search

Executable
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Flash / probe helper for the STM32H7S78-DK dual-boot project (macOS/Linux).
#
# Usage: gcc/flash.sh <boot|appli|all|probe|reset|verify>
#
# boot Flash Boot (internal flash 0x08000000)
# appli Flash Appli (external OSPI flash 0x70000000, needs the external loader)
# all Flash Boot then Appli (required order)
# probe Connect to the board and print device info (no write)
# reset Hardware reset of the board
# verify Dump 4 KB of internal and external flash to /tmp for inspection
#
# The STM32H7RS core sits behind access port 1 and the running firmware can
# prevent a hot-plug connection, so every command uses "ap=1 mode=UR".
#
# STM32_Programmer_CLI is looked up in: $STM32_PROGRAMMER_CLI, $PATH,
# the standalone STM32CubeProgrammer app, then the STM32CubeIDE plugin.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BOOT_HEX="$ROOT/Boot/TouchGFX/build/bin/target.hex"
APPLI_HEX="$ROOT/Appli/TouchGFX/build/bin/target.hex"
LOADER="$ROOT/gcc/MX66UW1G45G_STM32H7S78-DK.stldr"
find_cli() {
if [[ -n "${STM32_PROGRAMMER_CLI:-}" && -x "$STM32_PROGRAMMER_CLI" ]]; then
echo "$STM32_PROGRAMMER_CLI"; return
fi
if command -v STM32_Programmer_CLI >/dev/null 2>&1; then
command -v STM32_Programmer_CLI; return
fi
local candidates=(
"/Applications/STMicroelectronics/programmer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI"
"/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI"
"/opt/st/stm32cubeclt/STM32CubeProgrammer/bin/STM32_Programmer_CLI"
)
# STM32CubeIDE bundles its own copy; the plugin folder name changes with each update
local ide
for ide in /Applications/STMicroelectronics/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.*/tools/bin/STM32_Programmer_CLI; do
candidates+=("$ide")
done
local c
for c in "${candidates[@]}"; do
[[ -x "$c" ]] && { echo "$c"; return; }
done
echo "error: STM32_Programmer_CLI not found (set STM32_PROGRAMMER_CLI)" >&2
exit 1
}
require() {
[[ -f "$1" ]] || { echo "error: $1 not found - build first (make -C gcc)" >&2; exit 1; }
}
CLI="$(find_cli)"
CONNECT=(-c port=SWD ap=1 mode=UR)
flash_boot() {
require "$BOOT_HEX"
echo ">>> Flashing Boot: $BOOT_HEX"
"$CLI" "${CONNECT[@]}" -d "$BOOT_HEX" -v -hardRst
}
flash_appli() {
require "$APPLI_HEX"
require "$LOADER"
echo ">>> Flashing Appli: $APPLI_HEX (external loader)"
"$CLI" "${CONNECT[@]}" -el "$LOADER" -d "$APPLI_HEX" -hardRst
}
case "${1:-}" in
boot) flash_boot ;;
appli) flash_appli ;;
all) flash_boot; flash_appli ;;
probe) "$CLI" -l st; "$CLI" "${CONNECT[@]}" ;;
reset) "$CLI" "${CONNECT[@]}" -hardRst ;;
verify)
"$CLI" "${CONNECT[@]}" -u 0x08000000 0x1000 /tmp/read_int.bin
"$CLI" "${CONNECT[@]}" -el "$LOADER" -u 0x70000000 0x1000 /tmp/read_ext.bin
;;
*)
sed -n '4,12p' "$0" | sed 's/^# \{0,1\}//'
exit 1
;;
esac
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Generate compile_commands.json (repo root) from a dry run of the makefiles.
Used by VS Code IntelliSense (C/C++ extension) and clangd.
Usage: python3 gcc/gen_compile_commands.py
"""
import json
import os
import re
import shlex
import subprocess
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
MAKEFILES = ["gcc/makefile_boot", "gcc/makefile_appli"]
COMPILERS = ("arm-none-eabi-gcc", "arm-none-eabi-g++")
def dry_run(makefile):
# -B forces every compile command to be printed, -n executes nothing
out = subprocess.run(
["make", "-r", "-B", "-n", "-f", makefile, "build_executable"],
cwd=ROOT, capture_output=True, text=True,
).stdout
return re.sub(r"\\\n\s*", " ", out).splitlines()
def main():
entries = []
seen = set()
for makefile in MAKEFILES:
for line in dry_run(makefile):
line = line.strip()
if not line.startswith(COMPILERS) or " -c " not in f" {line} ":
continue
args = shlex.split(line)
source = next((a for a in args if a.endswith((".c", ".cpp", ".s"))), None)
if not source or source in seen:
continue
seen.add(source)
entries.append({
"directory": ROOT,
"arguments": args,
"file": os.path.join(ROOT, source),
})
path = os.path.join(ROOT, "compile_commands.json")
with open(path, "w") as f:
json.dump(entries, f, indent=1)
print(f"{len(entries)} entries written to {path}")
if __name__ == "__main__":
main()
+39 -37
View File
@@ -1,38 +1,40 @@
stm32cube_programmer_path := STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
stm32cube_programmer_filename := STM32_Programmer_CLI.exe
stm32cube_programmer_filepath := $(stm32cube_programmer_path)/$(stm32cube_programmer_filename)
stm32cube_loader_relative_path := ExternalLoader/$(stldr)
stm32cube_loader := $(stm32cube_programmer_path)/$(stm32cube_loader_relative_path)
program_files_win32 = /c/Program Files (x86)
program_files_win64 = /c/Program Files
program_files_CLT = /c/ST/STM32CubeCLT/STM32CubeCLT/
# Check which tools are installed
ifneq ("$(shell find "$(program_files_win64)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_win64)
else ifneq ("$(shell find "$(program_files_win32)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_win32)
else ifneq ("$(shell find "$(program_files_CLT)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_CLT)
endif
st_stm32cube_programmer_path := $(program_files_path)/$(stm32cube_programmer_path)
st_stm32cube_programmer_filepath := $(program_files_path)/$(stm32cube_programmer_filepath)
st_stm32cube_external_loader := $(program_files_path)/$(stm32cube_loader)
# define variable n as some line breaks for the error message
define error_msg
****************************************************************************************************************************
* *
* STM32CubeProgrammer is not found. Make sure the STM32CubeProgrammer is installed in its default directory. *
* You can download it at https://www.st.com/en/development-tools/stm32cubeprog.html *
* *
****************************************************************************************************************************
stm32cube_programmer_path := STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
stm32cube_programmer_filename := STM32_Programmer_CLI.exe
stm32cube_programmer_filepath := $(stm32cube_programmer_path)/$(stm32cube_programmer_filename)
stm32cube_loader_relative_path := ExternalLoader/$(stldr)
stm32cube_loader := $(stm32cube_programmer_path)/$(stm32cube_loader_relative_path)
program_files_win32 = /c/Program Files (x86)
program_files_win64 = /c/Program Files
program_files_CLT = /c/ST/STM32CubeCLT/STM32CubeCLT/
# Check which tools are installed (Windows only; macOS/Linux flash through gcc/flash.sh)
ifeq ($(OS),Windows_NT)
ifneq ("$(shell find "$(program_files_win64)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_win64)
else ifneq ("$(shell find "$(program_files_win32)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_win32)
else ifneq ("$(shell find "$(program_files_CLT)/$(stm32cube_programmer_filepath)" 2> nul )","")
program_files_path := $(program_files_CLT)
endif
endif
st_stm32cube_programmer_path := $(program_files_path)/$(stm32cube_programmer_path)
st_stm32cube_programmer_filepath := $(program_files_path)/$(stm32cube_programmer_filepath)
st_stm32cube_external_loader := $(program_files_path)/$(stm32cube_loader)
# define variable n as some line breaks for the error message
define error_msg
****************************************************************************************************************************
* *
* STM32CubeProgrammer is not found. Make sure the STM32CubeProgrammer is installed in its default directory. *
* You can download it at https://www.st.com/en/development-tools/stm32cubeprog.html *
* *
****************************************************************************************************************************
endef
+17 -10
View File
@@ -1,10 +1,17 @@
_extflash_:
ifeq ($(program_files_path),)
$(error $(error_msg))
endif
@cd "$(st_stm32cube_programmer_path)" && ./$(stm32cube_programmer_filename) -c port=SWD ap=1 -d $(application_path)/$(binary_output_path)/target.hex -el $(stm32cube_loader_relative_path) -hardRst
_intflash_:
ifeq ($(program_files_path),)
$(error $(error_msg))
endif
@cd "$(st_stm32cube_programmer_path)" && ./$(stm32cube_programmer_filename) -c port=SWD ap=1 -d $(application_path)/$(binary_output_path)/intflash.hex -el $(stm32cube_loader_relative_path) -hardRst
ifeq ($(OS),Windows_NT)
_extflash_:
ifeq ($(program_files_path),)
$(error $(error_msg))
endif
@cd "$(st_stm32cube_programmer_path)" && ./$(stm32cube_programmer_filename) -c port=SWD ap=1 -d $(application_path)/$(binary_output_path)/target.hex -el $(stm32cube_loader_relative_path) -hardRst
_intflash_:
ifeq ($(program_files_path),)
$(error $(error_msg))
endif
@cd "$(st_stm32cube_programmer_path)" && ./$(stm32cube_programmer_filename) -c port=SWD ap=1 -d $(application_path)/$(binary_output_path)/intflash.hex -el $(stm32cube_loader_relative_path) -hardRst
else
# macOS/Linux: delegate to gcc/flash.sh (finds STM32_Programmer_CLI, uses ap=1 mode=UR)
flash_project := $(if $(findstring Appli,$(binary_output_path)),appli,boot)
_extflash_ _intflash_:
@"$(application_path)/gcc/flash.sh" $(flash_project)
endif
-1
View File
@@ -1 +0,0 @@
find: /c/ST/STM32CubeCLT/STM32CubeCLT//STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI.exe: No such file or directory