HALF_DUPLEX deploys a shared line per backend. The hardware USART takes the library's .half_duplex turn-around — RXD and TXD tied off-chip, each reply byte held to transmit-complete before the line can be released (m8 404 B, m328P 440, 1284P 460; the window poll runs through the outlined release-line call at 18 or 22 cycles a poll, measured off the built loops and held per chip by pureboot.window.halfduplex). The software and autobaud links fold onto the RX pin — RX == TX spells the same — and cost nothing: the frame's direction wrap is what the dropped second-pin init paid, and the worst image in the space is unchanged at the 1284s' 502 of 512, now with its one-wire twin proven equal across the exhaustive matrix. The host gains --one-wire, the echo discard a shared line requires: the adapter's echo is matched byte for byte and a reply interleaving a blind write — a loader already in session re-prompts inside the knock — is held for the reader. The device runner models the shared line by direction (drives only while the firmware's DDR reads input, decodes only while the firmware owns it, supplies the host-side echo), extends the USART pin-ownership model to RXEN's hold on RXD, and starts the pty USART from the datasheet's zeroed UCSR#B: simavr's TXEN-set reset plus its clear-UDRE-on-TXEN-drop otherwise wedges the first transmitter after a receiver-only program, which the half-duplex window gate caught as a banner that never came. v7 is tagged at its era's last commit; v8 changes nothing on the wire. 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()
|