Skip to content

Commit 29d24d8

Browse files
committed
Confirmed errc works!
1 parent 5da3675 commit 29d24d8

6 files changed

Lines changed: 115 additions & 7 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,5 @@ build_logs/
253253
# Doxygen output
254254
html/
255255
docs/
256-
# End of https://www.toptal.com/developers/gitignore/api/cmake,c,c++,clion,macos
256+
# End of https://www.toptal.com/developers/gitignore/api/cmake,c,c++,clion,macos
257+
*.bin

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "openocd dev debug CM7",
66
"cwd": "${workspaceRoot}",
7-
"executable": "/Users/mahiremran/Desktop/GitHub/titan/build/test_spi.elf",
7+
"executable": "/Users/mahiremran/Desktop/GitHub/titan/build/test_errc.elf",
88
"armToolchainPath": "/Applications/ArmGNUToolchain/14.3.rel1/arm-none-eabi/bin",
99
"request": "launch",
1010
"type": "cortex-debug",
@@ -21,7 +21,7 @@
2121
{
2222
"name": "openocd test debug CM7",
2323
"cwd": "${workspaceRoot}",
24-
"executable": "/Users/mahiremran/Desktop/GitHub/titan/build/test_spi.elf",
24+
"executable": "/Users/mahiremran/Desktop/GitHub/titan/build/test_errc.elf",
2525
"armToolchainPath": "/Applications/ArmGNUToolchain/14.3.rel1/arm-none-eabi/bin",
2626
"request": "attach",
2727
"type": "cortex-debug",
@@ -42,5 +42,5 @@
4242
]
4343
}
4444
],
45-
"project.debugTarget": "/Users/mahiremran/Desktop/GitHub/titan/build/test_pwm.elf"
45+
"project.debugTarget": "/Users/mahiremran/Desktop/GitHub/titan/build/test_errc.elf"
4646
}

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ add_firmware_target(test_pwm ${CMAKE_SOURCE_DIR}/test/test_pwm.c)
101101
add_firmware_target(test_spi ${CMAKE_SOURCE_DIR}/test/test_spi.c)
102102
add_firmware_target(test_usart ${CMAKE_SOURCE_DIR}/test/test_usart.c)
103103
add_firmware_target(test_oscilloscope ${CMAKE_SOURCE_DIR}/test/test_oscilloscope.c)
104+
add_firmware_target(test_errc ${CMAKE_SOURCE_DIR}/test/test_errc.c)
104105

105106
# Native host unit test: test_alloc (compiled with system gcc, not the ARM cross-compiler)
106107
add_custom_command(

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LOG_FILE="$LOG_DIR/build_$(date +%Y%m%d_%H%M%S).log"
1212
exec > >(tee -a "$LOG_FILE") 2>&1
1313

1414
FW_TARGET="${1:-${FW_TARGET:-titan}}"
15-
FW_TARGETS=(titan test_pwm test_spi test_usart test_oscilloscope)
15+
FW_TARGETS=(titan test_pwm test_spi test_usart test_oscilloscope test_errc)
1616
MAX_ATTEMPTS=3
1717
UPDATE_DEBUG_TARGET=false
1818

@@ -24,11 +24,11 @@ done
2424

2525
# ── Target validation ──────────────────────────────────────────────────────────
2626
case "$FW_TARGET" in
27-
titan|test_pwm|test_spi|test_usart|test_oscilloscope|commit_check|all|clean|docs)
27+
titan|test_pwm|test_spi|test_usart|test_oscilloscope|test_errc|commit_check|all|clean|docs)
2828
;;
2929
*)
3030
echo "Unknown target: $FW_TARGET"
31-
echo "Valid targets: titan, test_pwm, test_spi, test_usart, test_oscilloscope, commit_check, all, clean, docs"
31+
echo "Valid targets: titan, test_pwm, test_spi, test_usart, test_oscilloscope, test_errc, commit_check, all, clean, docs"
3232
exit 4
3333
;;
3434
esac

test/test_errc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "peripheral/errc.h"
2+
#include "peripheral/pwm.h"
3+
4+
void _start() {
5+
enum ti_errc_t errc = TI_ERRC_NONE;
6+
(void)ti_log_init();
7+
8+
struct ti_pwm_config_t invalid_pwm = {
9+
.channel = 3,
10+
.instance = 3,
11+
.clock_freq = 4000000,
12+
.freq = 0,
13+
.duty = 250,
14+
};
15+
16+
ti_set_pwm(invalid_pwm, &errc);
17+
18+
while (1) {
19+
asm("BKPT #0");
20+
}
21+
}

tools/decode_errc_log.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""Decode Titan errc flash log dumps into readable entries."""
3+
4+
from __future__ import annotations
5+
6+
import argparse
7+
import struct
8+
from pathlib import Path
9+
10+
TI_LOG_MAGIC = 0xD1A60001
11+
TI_LOG_ENTRY_SIZE = 128
12+
13+
ERRC_NAMES = {
14+
0: "TI_ERRC_NONE",
15+
1: "TI_ERRC_UNKNOWN",
16+
2: "TI_ERRC_INVALID_ARG",
17+
3: "TI_ERRC_BUSY",
18+
4: "TI_ERRC_TIMEOUT",
19+
5: "TI_ERRC_OVERFLOW",
20+
6: "TI_ERRC_NOT_FOUND",
21+
7: "TI_ERRC_INTERNAL",
22+
8: "TI_ERRC_DEVICE",
23+
9: "TI_ERRC_BUS",
24+
10: "TI_ERRC_CHECKSUM",
25+
11: "TI_ERRC_PROTOCOL",
26+
}
27+
28+
29+
def cstr(buf: bytes) -> str:
30+
return buf.split(b"\x00", 1)[0].decode("utf-8", errors="replace")
31+
32+
33+
def decode_entry(entry: bytes) -> tuple[int, int, int, str, str, str]:
34+
magic = struct.unpack_from("<I", entry, 0)[0]
35+
errc = entry[4]
36+
line = struct.unpack_from("<I", entry, 8)[0]
37+
func = cstr(entry[12:40])
38+
file = cstr(entry[40:80])
39+
msg = cstr(entry[80:128])
40+
return (magic, errc, line, func, file, msg)
41+
42+
# Ex command
43+
# ./build.sh test_errc
44+
# openocd -f interface/stlink.cfg -f target/stm32h7x_dual_bank.cfg -c "init; reset halt; dump_image errc_log.bin 0x081E0000 0x20000; shutdown"
45+
# python3 tools/decode_errc_log.py errc_log.bin --limit 20
46+
def main() -> int:
47+
parser = argparse.ArgumentParser(description="Decode Titan errc_log.bin")
48+
parser.add_argument("bin_file", type=Path, help="Path to errc_log.bin")
49+
parser.add_argument("--base", default="0x081E0000", help="Flash base address for display")
50+
parser.add_argument("--limit", type=int, default=32, help="Max entries to print")
51+
args = parser.parse_args()
52+
53+
base_addr = int(args.base, 0)
54+
data = args.bin_file.read_bytes()
55+
56+
printed = 0
57+
for offset in range(0, len(data), TI_LOG_ENTRY_SIZE):
58+
entry = data[offset : offset + TI_LOG_ENTRY_SIZE]
59+
if len(entry) < TI_LOG_ENTRY_SIZE:
60+
break
61+
62+
magic, errc, line, func, file, msg = decode_entry(entry)
63+
64+
if magic == 0xFFFFFFFF:
65+
continue
66+
if magic != TI_LOG_MAGIC:
67+
continue
68+
69+
errc_name = ERRC_NAMES.get(errc, f"UNKNOWN({errc})")
70+
abs_addr = base_addr + offset
71+
print(
72+
f"0x{abs_addr:08X} {errc_name:<18} line={line:<5} "
73+
f"file={file:<20} func={func:<24} msg={msg}"
74+
)
75+
printed += 1
76+
if printed >= args.limit:
77+
break
78+
79+
if printed == 0:
80+
print("No valid log entries found (magic mismatch or region empty).")
81+
return 0
82+
83+
84+
if __name__ == "__main__":
85+
raise SystemExit(main())

0 commit comments

Comments
 (0)