board_test
birdnet_stm32.deploy.board_test
¶
Board test: standalone firmware on STM32N6570-DK.
Full on-device pipeline — nothing is precomputed on the host: 1. Deploy model: stedgeai generate → patch NPU_Validation project → n6_loader build + flash. 2. Firmware on board: read WAV from SD card → STFT on Cortex-M55 → NPU inference → results over UART. 3. This script captures UART output and parses per-file predictions.
Requires: - USB-connected STM32N6570-DK with SD card containing audio/ and labels.txt. - pyserial (pip install pyserial).
BoardTestConfig
dataclass
¶
Configuration for standalone on-board inference tests.
Attributes:
| Name | Type | Description |
|---|---|---|
deploy_cfg |
DeployConfig
|
Base deployment configuration (paths to tools, model, etc.). |
model_config_path |
str
|
Path to the _model_config.json file. |
labels_path |
str
|
Path to the _labels.txt file. |
serial_port |
str
|
Serial port for UART capture (e.g. /dev/ttyACM0). |
top_k |
int
|
Number of top predictions to show per file. |
score_threshold |
float
|
Minimum score to display. |
timeout |
int
|
Maximum seconds to wait for firmware to finish. |
Source code in birdnet_stm32/deploy/board_test.py
load_model_config(config_path)
¶
Load model configuration from JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to _model_config.json. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with model configuration. |
Source code in birdnet_stm32/deploy/board_test.py
load_labels(labels_path)
¶
Load class labels from a labels.txt file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels_path
|
str
|
Path to _labels.txt (one label per line). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of label strings. |
Source code in birdnet_stm32/deploy/board_test.py
patch_project(project, model_cfg, num_classes, labels)
¶
Copy firmware sources into the NPU_Validation project and patch build files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Path
|
Path to the NPU_Validation project root. |
required |
model_cfg
|
dict
|
Model configuration dict from _model_config.json. |
required |
num_classes
|
int
|
Number of output classes. |
required |
labels
|
list[str]
|
Ordered list of class label strings. If empty, generates
placeholder |
required |
Returns a list of .bak paths that must be passed to restore_project.
Source code in birdnet_stm32/deploy/board_test.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
restore_project(backups)
¶
Undo all project patches by restoring .bak files and removing new files.
For each entry in backups:
- If it is a directory (FatFs), remove it entirely.
- If it is a .bak path and the .bak exists, move it back over the original.
- If it is a .bak path but no .bak was created (file was new), delete
the original that we copied in.
Source code in birdnet_stm32/deploy/board_test.py
parse_serial_output(lines, labels, top_k=5, threshold=0.01)
¶
Parse firmware UART output into structured results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list[str]
|
Raw serial lines captured from the board. |
required |
labels
|
list[str]
|
Class label list (for reference; firmware already prints names). |
required |
top_k
|
int
|
Max detections per file to keep. |
5
|
threshold
|
float
|
Minimum score fraction (0–1) to include. |
0.01
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with 'results' (list of per-file dicts), 'processed', 'errors', |
dict
|
'raw_lines'. |
Source code in birdnet_stm32/deploy/board_test.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
run_board_test(cfg)
¶
Execute the full on-board inference test.
Steps: 1. stedgeai generate → produce NPU binary from the TFLite model. 2. Patch NPU_Validation project with our firmware sources. 3. n6_loader: copy network.c, build firmware, flash, run. 4. Capture UART output until '=== DONE ===' marker. 5. Restore the NPU_Validation project to its original state. 6. Parse and report results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
BoardTestConfig
|
Board test configuration. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with 'results', 'processed', 'errors', 'raw_lines', 'labels'. |
Source code in birdnet_stm32/deploy/board_test.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |