The pin crosses libavr's phase 6 - the renamed system surface, the named serial configs, the receiver-tolerance table, the paged SPM receipts - and every loader image comes out size-identical: the full matrix on six representative chips (the exhaustive cross product on three of them), the stock and autobaud columns untouched, the four tsb tiers back on their recorded floors at 510/526/638/836. Byte parity was not free, and the two libavr defects it surfaced were fixed there rather than absorbed here. The EEPROM write procedure's step 2 - the SPMEN spin - had landed unconditionally and cost every build six bytes for a wait a polled loader can never take; it is scoped now, and the loaders state the datasheet's own omission clause (spm_interlock::omitted, DS40002061B 8.6.3). The blocking page erase/write grew an internal wait the tiers' settle() already provides, so the tiers issue the command form and pureboot keeps its host-driven sp_spm path. What the port states rather than inherits: the stock 115200 at 16 MHz sits +2.1 % past the receiver-tolerance table libavr now holds rates to, so the hardware links say .allow_baud_error = true - the same 2.5 % envelope pureboot_baud_feasible() has always enforced, proven on silicon across the fleet. rx_ready() reads readable() now. Alongside the pin: rule 33's ASCII sweep over every source (docs keep their typography), rule 34's InsertBraces in .clang-format with the tree reformatted, std::array over the simavr runners' raw buffers, and the stale Studio size in ide/README.md replaced by the claim its check-flags gate actually holds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
80 lines
3.1 KiB
Python
80 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Hand-over with a USART left enabled on the loader's own pins.
|
|
|
|
A software or autobaud link deployed on a USART's TxD is mute if an
|
|
application hands over with that USART still enabled: TXEN keeps the USART
|
|
owning the pin, so the bit-banged transmitter's port writes go nowhere and the
|
|
loader receives and obeys while answering nothing. The link's init releases it.
|
|
|
|
The state is reached the way silicon reaches it - an application that sets up
|
|
its USART and jumps in with no reset between, so nothing clears UCSRnB for it.
|
|
The pin ownership itself is modelled by the device runner: simavr wires a
|
|
USART through IRQs alone and never takes the pin from the port, so without
|
|
that the mute could not happen here at all (test/pureboot_device.cpp).
|
|
|
|
Usage: pbmute.py <device_bin> <pureboot_elf> <mcu> <hz> <base_hex> <page>
|
|
<baud> <app_bin> <tool_py> <workdir> <link>
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
|
|
def fail(message):
|
|
print(f"FAIL: {message}")
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
device_bin, elf, mcu, hz, base_hex, page, baud, app_bin, tool, workdir, link = sys.argv[1:]
|
|
page, baud = int(page), int(baud)
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(tool)))
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import pbsim
|
|
import pureboot as pb
|
|
|
|
if "@" not in link:
|
|
fail(f"the link {link} names no owning USART - nothing would be under test")
|
|
# A shared line (RX == TX) echoes the host's own bytes; discard them the
|
|
# way the shipped --one-wire mode does.
|
|
one_wire = re.fullmatch(r"sw:([A-H][0-7]),\1@[01]", link) is not None
|
|
|
|
os.makedirs(workdir, exist_ok=True)
|
|
dump = os.path.join(workdir, "dump.bin")
|
|
|
|
device = pbsim.Device(device_bin, elf, mcu, hz, base_hex, page, baud, dump, link=link)
|
|
try:
|
|
port = pb.Port(device.pty, baud)
|
|
if one_wire:
|
|
port = pb.OneWirePort(port)
|
|
loader = pb.Loader(port)
|
|
loader.connect(25)
|
|
resident = loader.info.version
|
|
|
|
# Install the fixture and let it take over. It brings up the USART
|
|
# that owns these pins and jumps straight back in.
|
|
pb.op_flash(loader, app_bin, erase=False, verify=True)
|
|
loader.run_application()
|
|
|
|
# The loader is running again with that USART enabled behind it. Only
|
|
# the release makes it audible; without it the connect times out.
|
|
loader = pb.Loader(port)
|
|
try:
|
|
loader.connect(25)
|
|
except pb.Error as error:
|
|
fail(f"the loader never answered after the hand-over - the USART still owns its TX pin ({error})")
|
|
if loader.info.version != resident:
|
|
fail(f"identity changed across the hand-over: {resident} then {loader.info.version}")
|
|
|
|
# Answering is not enough: it has to still be a working loader.
|
|
pb.verify_pages(loader, pb.plan_flash(open(app_bin, "rb").read(), loader.info))
|
|
port.close()
|
|
finally:
|
|
device.stop()
|
|
print("pbmute: a loader on a USART's own pins answers after a hand-over that left it enabled")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|