Commit 125e741
committed
Keep SPI parts working after a simulator restart
AVRSimulator.reset() rebuilds the CPU and every peripheral, which meant a
brand new AVRSPI with its own MISO loopback handler. Parts hook
simulator.spi.onByte once from attachEvents, and DynamicComponent only
re-runs attachEvents when the simulator instance, the hex, or the wiring
changes — a restart changes none of them. So the part kept talking to a
dead peripheral while the MCU talked to a loopback.
Stop calls reset(), so does the Reset button. Every SPI part was
one-run-only on AVR boards: RC522, ILI9341, SD card, e-paper, MAX7219.
With an RC522 that looks like the reader working on the first Run and
then ignoring the card forever, no matter how many times you tap it.
.spi is now a persistent facade and the real peripheral lives in
spiPeripheral. Parts hook the facade and keep it; loadHex/reset swap the
peripheral underneath and re-route its per-byte callback back through the
facade. Same approach as i2cBus, which survives a reset via
attachMaster() — that is why I2C displays never had this problem.
Also fixes the RP2040 MicroPython reset path, which re-wired SPI0 to
plain loopback instead of going through _spiAdapter. Identical bug on the
Reset button there; the Arduino path was already adapter-aware.
Checked with real MFRC522 firmware driving the real rc522-rfid emulation
across Run, Stop, Run, Reset, Run: the UID now reads on every run. Before
the change the sketch booted fine each time but only ever saw the card on
the first run.1 parent 25927e7 commit 125e741
2 files changed
Lines changed: 59 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
305 | 337 | | |
306 | 338 | | |
307 | 339 | | |
| |||
481 | 513 | | |
482 | 514 | | |
483 | 515 | | |
484 | | - | |
485 | | - | |
486 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
487 | 523 | | |
| 524 | + | |
488 | 525 | | |
489 | 526 | | |
490 | 527 | | |
| |||
512 | 549 | | |
513 | 550 | | |
514 | 551 | | |
515 | | - | |
| 552 | + | |
516 | 553 | | |
517 | 554 | | |
518 | 555 | | |
| |||
1017 | 1054 | | |
1018 | 1055 | | |
1019 | 1056 | | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
1023 | 1064 | | |
| 1065 | + | |
1024 | 1066 | | |
1025 | 1067 | | |
1026 | 1068 | | |
| |||
1042 | 1084 | | |
1043 | 1085 | | |
1044 | 1086 | | |
1045 | | - | |
| 1087 | + | |
1046 | 1088 | | |
1047 | 1089 | | |
1048 | 1090 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
787 | 790 | | |
788 | | - | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
789 | 796 | | |
790 | 797 | | |
791 | 798 | | |
| |||
0 commit comments