firmware: debug/test build profiles with real behavioural differences

This commit is contained in:
Lars Nolden
2026-09-01 11:23:28 +02:00
parent 31c7aa7d02
commit c835c62172
9 changed files with 133 additions and 13 deletions
+4
View File
@@ -2,5 +2,9 @@ captures/
logs/
result*
firmware/build/
firmware/build-*/
firmware/sdkconfig
firmware/sdkconfig.test
firmware/sdkconfig.debug
firmware/sdkconfig.old
__pycache__/
+23
View File
@@ -102,3 +102,26 @@ inject sleep -> heartbeat chip_mode=0, config_intact=false
-> radio_recovery level 1 -> failed (correctly refuses)
-> radio_recovery level 2 -> rx_restored
```
## Build profiles
```
./tools/build.sh test # default; the configuration all HIL numbers use
./tools/build.sh debug # verbose diagnostics, assertions, per-TX dumps
./tools/flash.sh [test|debug]
```
Differences are behavioural, not cosmetic:
| | test | debug |
|---|---|---|
| `verbose` at boot | off | on |
| `tx_diag` after every TX | only on failure | always |
| raw frame hex in events | yes (HIL needs it) | yes |
| optimisation / log level | size, warn | debug, info |
| task watchdog | 15 s | 30 s |
`hil/run.sh` always builds and flashes the `test` profile, so reported
timing is never perturbed by debug serial traffic. Build directories are
separate (`build-test`, `build-debug`) so profiles cannot silently reuse a
stale sdkconfig.
+27
View File
@@ -0,0 +1,27 @@
menu "wM-Bus repeater"
config WMBUS_VERBOSE_DEFAULT
bool "Verbose diagnostics enabled at boot"
default n
help
Emit dropped-frame reasons, suppressed duplicates, rx_ready timing
and unexpected-IRQ events by default. Can always be toggled at
runtime with "set verbose 0|1".
config WMBUS_TX_DIAG_ALWAYS
bool "Always emit tx_diag after every transmission"
default n
help
Logs polled IRQ state, DIO1 level, chip mode and device errors for
every TX. Useful when bringing up a new board revision; adds one
serial line per repeat, which perturbs timing measurements.
config WMBUS_LOG_RAW_FRAMES
bool "Include raw frame hex in wmbus_rx / wmbus_tx events"
default y
help
Required by the HIL correlator to compare bytes against the SDR.
Disable only for a quiet production-style build; doing so makes
hil/correlate.py unable to match frames.
endmenu
+26 -6
View File
@@ -22,7 +22,11 @@ repeater_cfg_t g_cfg = {
.repeat_delay_ms = 50,
.tx_power_dbm = -9,
.repeat_enabled = true,
#ifdef CONFIG_WMBUS_VERBOSE_DEFAULT
.verbose = true,
#else
.verbose = false,
#endif
.whitelist = {0},
.whitelist_len = 0,
};
@@ -219,10 +223,18 @@ static const char *do_tx(const uint8_t *payload, int payload_len,
*tx_done_us = notify_seen ? s_irq_ts : esp_timer_get_time();
fem_set_tx(false);
sx126x_clear_irq(SX126X_IRQ_ALL);
LOGJ("\"event\":\"tx_diag\",\"irq\":%u,\"notify\":%s,\"dio1_high_seen\":%s,"
"\"max_chip_mode\":%u,\"device_errors\":%u",
irq, notify_seen ? "true" : "false", dio1_seen ? "true" : "false",
max_mode, sx126x_get_device_errors());
#ifdef CONFIG_WMBUS_TX_DIAG_ALWAYS
const bool want_diag = true;
#else
// otherwise only when something went wrong, so timing stays clean
const bool want_diag = g_cfg.verbose || !(irq & SX126X_IRQ_TX_DONE);
#endif
if (want_diag) {
LOGJ("\"event\":\"tx_diag\",\"irq\":%u,\"notify\":%s,"
"\"dio1_high_seen\":%s,\"max_chip_mode\":%u,\"device_errors\":%u",
irq, notify_seen ? "true" : "false", dio1_seen ? "true" : "false",
max_mode, sx126x_get_device_errors());
}
if (irq & SX126X_IRQ_TX_DONE) {
g_stats.tx_success++;
return notify_seen ? "ok" : "ok_polled";
@@ -247,11 +259,15 @@ static void log_tx(const char *result, uint32_t hash, int len,
(long long)(tx_start - rx_ts), len, hash,
(int)g_cfg.tx_power_dbm,
(long long)(tx_done > tx_start ? tx_done - tx_start : 0), result);
#ifdef CONFIG_WMBUS_LOG_RAW_FRAMES
if (payload && payload_len > 0) {
printf(",\"tx_payload\":\"");
print_hex(payload, payload_len);
printf("\"");
}
#else
(void)payload; (void)payload_len;
#endif
printf("}\n");
fflush(stdout);
}
@@ -421,12 +437,16 @@ static void handle_rx(int64_t rxdone_ts)
printf("{\"seq\":%" PRIu32 ",\"event\":\"wmbus_rx\",\"timestamp_us\":%lld,"
"\"rxdone_us\":%lld,\"frequency_hz\":868950000,\"format\":\"%c\","
"\"length\":%d,\"rssi_dbm\":%d,\"crc_ok\":%s,"
"\"hash\":\"%08" PRIx32 "\",\"raw\":\"",
"\"hash\":\"%08" PRIx32 "\"",
s_seq++, (long long)frame_end_ts, (long long)rxdone_ts,
fmt == WMBUS_FRAME_A ? 'A' : 'B', total, rssi,
crc_ok ? "true" : "false", hash);
#ifdef CONFIG_WMBUS_LOG_RAW_FRAMES
printf(",\"raw\":\"");
print_hex(frame, total);
printf("\"}\n");
printf("\"");
#endif
printf("}\n");
fflush(stdout);
if (!g_cfg.repeat_enabled || !crc_ok) return;
+9
View File
@@ -0,0 +1,9 @@
# Debug profile: verbose diagnostics, assertions, per-TX register dumps.
# Extra serial traffic perturbs timing -- do not use for timing measurements.
CONFIG_WMBUS_VERBOSE_DEFAULT=y
CONFIG_WMBUS_TX_DIAG_ALWAYS=y
CONFIG_WMBUS_LOG_RAW_FRAMES=y
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_COMPILER_OPTIMIZATION_DEBUG=y
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
CONFIG_ESP_TASK_WDT_TIMEOUT_S=30
+7
View File
@@ -0,0 +1,7 @@
# Release/test profile: the configuration all HIL measurements are taken
# with. Structured JSON only, no per-TX register dumps, size-optimised.
CONFIG_WMBUS_VERBOSE_DEFAULT=n
CONFIG_WMBUS_TX_DIAG_ALWAYS=n
CONFIG_WMBUS_LOG_RAW_FRAMES=y
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
+7 -3
View File
@@ -64,12 +64,16 @@ grep -q "SDR_HEALTH=ok" "$RUN_DIR/sdr_health.txt" || {
# --- 4-6. build + flash + reset --------------------------------------------
if [ "$FLASH" = 1 ]; then
(cd firmware && idf.py build) > "$RUN_DIR/build.log" 2>&1
if ! (cd firmware && idf.py -p "$DUT_PORT" flash) >> "$RUN_DIR/build.log" 2>&1; then
# always the "test" profile: the configuration every reported number
# is measured with (see firmware/sdkconfig.defaults.test)
./tools/build.sh test > "$RUN_DIR/build.log" 2>&1
if ! (cd firmware && idf.py -B build-test -p "$DUT_PORT" flash) \
>> "$RUN_DIR/build.log" 2>&1; then
# the port re-enumerates when entering download mode; rediscover once
sleep 2
eval "$(./tools/discover_devices.sh)"
(cd firmware && idf.py -p "$DUT_PORT" flash) >> "$RUN_DIR/build.log" 2>&1
(cd firmware && idf.py -B build-test -p "$DUT_PORT" flash) \
>> "$RUN_DIR/build.log" 2>&1
fi
sleep 2
eval "$(./tools/discover_devices.sh)"
Executable
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Build a named firmware profile.
# ./tools/build.sh test (default) - configuration all HIL numbers use
# ./tools/build.sh debug - verbose, assertions, per-TX dumps
# Build dirs are kept separate so switching profiles cannot silently reuse
# a stale sdkconfig.
set -euo pipefail
cd "$(dirname "$0")/../firmware"
PROFILE=${1:-test}
case "$PROFILE" in
test|debug) ;;
*) echo "unknown profile: $PROFILE (use test|debug)" >&2; exit 2 ;;
esac
export SDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.$PROFILE"
exec idf.py -B "build-$PROFILE" -D SDKCONFIG="sdkconfig.$PROFILE" "${@:2}" build
+15 -4
View File
@@ -1,11 +1,22 @@
#!/usr/bin/env bash
# Build + flash the firmware to the discovered DUT. Refuses ambiguous devices.
# Build + flash a firmware profile to the discovered DUT.
# ./tools/flash.sh [test|debug]
# Refuses ambiguous serial devices (see tools/discover_devices.sh).
set -euo pipefail
cd "$(dirname "$0")/.."
PROFILE=${1:-test}
eval "$(./tools/discover_devices.sh)"
echo "Flashing DUT: $DUT_PORT" >&2
echo "Flashing profile '$PROFILE' to: $DUT_PORT" >&2
./tools/build.sh "$PROFILE"
cd firmware
idf.py build
idf.py -p "$DUT_PORT" flash
if ! idf.py -B "build-$PROFILE" -p "$DUT_PORT" flash; then
# entering download mode re-enumerates the USB device; rediscover once
sleep 2
cd ..
eval "$(./tools/discover_devices.sh)"
cd firmware
idf.py -B "build-$PROFILE" -p "$DUT_PORT" flash
fi