99. USB mode does have an exit, and it is gated on the command state being zero¶
Section 97 ended by saying a polite session end is a reboot or nothing, and offered finding what
writes the top level mode variable as the third option. Taken immediately, and it overturns the
conclusion: the exit exists, the firmware polls for the cable itself, and what stops it running is
one byte that 0xE0 0x01 clears.
The mode loop, and what mode 1 is¶
0x315 on the One is a three valued mode selected at 0x28C9C. Mode 3 is the reset, section 97.
Mode 1 is USB mode, and its body polls a port pin and the USB module:
28cf2: 80 50 MOVF PORTA,W
28cf4: 10 0b ANDLW 0x10 ; PORTA bit 4
28cf6: 0b e1 BNZ 0x28d0e
28cf8: 80 50 MOVF PORTA,W ; read again
28cfa: 10 0b ANDLW 0x10
28cfc: 0c e1 BNZ 0x28d16
28cfe: 01 0e MOVLW 0x01
28d00: 00 6e MOVWF 0x00
28d02: 65 50 MOVF UCON,W
28d04: 02 0b ANDLW 0x02 ; SUSPND
28d06: 01 e0 BZ 0x28d0a
28d08: 01 0e MOVLW 0x01
28d0a: 00 5c SUBWF 0x00,W
28d0c: 04 e1 BNZ 0x28d16
28d0e: b3 ec 31 f1 CALL 0x26366 ; clear the command state, then leave
28d12: 06 d0 BRA 0x28d20
The polarity of PORTA bit 4 is deliberately not claimed. This project has twice recorded a bit
sense being inverted in its own notes, and nothing here establishes whether the pin is high or low
when a cable is present. What the structure states without needing the polarity is that mode 1
watches a pin and the USB SUSPND bit, and has two ways to reach the exit at 0x28D20.
The two ways out, and only one of them is unconditional¶
28d16: 84 51 MOVF 0x284,W ; the command state variable
28d18: 01 e1 BNZ 0x28d1e ; not idle: go round again, stay in USB mode
28d1c: 01 d0 BRA 0x28d20 ; idle: leave
28d20: 43 ec 5b f1 CALL 0x2b686 ; and the exit releases the pins and drops the mode
28d24: 93 8c BSF TRISB,6
28d26: 8a 8c BSF LATB,6
28d28: 29 d0 BRA 0x28d7c ; CLRF 0x315
0x26366, the routine the other path calls first, is a full command reset: it clears 0x284, the
three address bytes, three counters, and sets 0x28B. So one path clears the gate and then leaves,
and the other leaves only if the gate is already clear.
Once 0x315 is zero the top level loop is back at its guard chain, which can enter mode 2 when two
routines report ready, two deferred work flags at 0x25D and 0x25E are clear, and 0x2628E
reports idle. Mode 2 is the application.
Why a remote can be left stuck, without needing any of that polarity¶
Every command body sets 0x284 to its own state number, and the shared exit at 0x267E4 clears it
only when the packet was not handled:
267e4: 21 51 MOVF 0xd21,W ; the packet handled flag
267e6: 04 e1 BNZ 0x267f2 ; handled: skip the clear
267ea: 84 6b CLRF 0x284
267ee: 8b 69 SETF 0x28b
So a handled command leaves the state variable holding its own number unless its own body clears it. That is the byte the conditional exit tests. A session that ends by closing a handle leaves whatever the last command set, and if that is nonzero the remote takes the conditional path and stays where it is, which is what section 95 recorded twice on the bench.
What is not established from the firmware alone is which commands leave 0x284 nonzero at the
moment a host walks away. READ_FLASH ends by clearing its state, docs/usb-protocol.md, so a
plain read may well leave the gate open; the bench observation on 9 August 2026 followed exactly
such a read and the remote still stuck, which means either the polarity puts that case on the
conditional path with something else set, or the clear does not happen where it is assumed to. That
is one hardware experiment, and it is not this section's to run.
What it changes¶
The polite end is 0xE0 0x01, and it is not a reboot. It is the one command that clears the
gate, and clearing the gate is the difference between a remote that leaves USB mode when its cable
goes and one that does not. Section 97 called that command "the one that is not a reset" and could
not say what it was for; this is what it is for.
It stays behind WRITES_ENABLED, because it changes a device's state and this project's rails do
not bend for convenience. But the decision it feeds is no longer "reboot or nothing": it is whether
a read only product may send one command whose whole effect is to zero a state variable, which is a
far easier thing to argue than a reset. A judgment call, and it is now a cheap experiment: send
it, pull the cable, see whether the remote leaves USB mode.
The experiment, prepared, with the prediction committed first¶
packages/usb/bin/end-session-experiment.ts runs it, and it exists in this commit so that the
prediction below is on record before any remote is attached. That ordering is the probe-remote
skill's rule and it is what makes the answer worth having: a measurement that confirms a number
nobody committed to in advance is worth much less.
The prediction: the remote leaves USB mode when the cable is pulled, and returns to its normal
display without needing its batteries out. The reasoning is section 99's chain: the last command the
script sends before the cable comes out is 0xE0 0x01, which clears 0x284, and the conditional
exit at 0x28D16 leaves USB mode exactly when 0x284 is zero.
What each outcome means, written down now so that none of them can be fitted afterwards:
- It leaves USB mode. The chain holds end to end, and the session end question becomes a policy question rather than a technical one: one command, no reboot, no storage touched.
- It stays in USB mode. Then the gate is not the only thing holding it, and the next suspect is the pin polarity this section deliberately declined to claim, or the guard chain in front of mode 2 rather than the exit from mode 1. The correction goes in this section, not into the script.
- It leaves USB mode without the command, which the script cannot tell on its own and which one extra run answers: pull the cable after a plain read and see. If that also works, then the two bench observations on 9 August 2026 had a cause this section has not found, and the command is irrelevant rather than sufficient. This is the control, and it is worth running first, because it costs nothing and it is the only run that can make the other two meaningless.
The script identifies the unit from its config rather than from its port, refuses to run without
HARMONY_ENABLE_WRITES=1, and reads the same window before and after the command so that "cleared a
variable" is distinguishable from "left the command layer confused". Sending it needs
assertSessionEndAllowed, which refuses the two reboot sub-commands by number, refuses arch 9
because nobody has read its escape, and refuses anything but the spare remote until the policy
question is decided.
The control ran first, three times, and it is the outcome that makes the experiment unnecessary¶
10 August 2026, on the spare, each round sending nothing but one 32 byte READ_FLASH of the config
base and then closing the handle. The screen is the evidence; enumeration after a replug is a proxy,
because a remote stuck in USB mode does not come back on the bus.
| round | how | cable out | screen | replug proxy |
|---|---|---|---|---|
| 1 | read-window by hand |
left USB mode | not run | |
| 2 | session-end-control.ts |
after 19 s | left USB mode | enumerated after 17 s, agrees |
| 3 | session-end-control.ts |
after 7 s | left USB mode | reported nothing in 25 s, wrong |
Three of three, so this is measured rather than observed. A clean read only session does not strand a remote.
Round three's proxy was a false negative and the tool was at fault, which is worth recording rather than quietly fixing. The replug window was 25 seconds, chosen because section 95's stuck remote had been polled for sixteen, and that is not margin: it has to cover somebody walking to the desk and finding the socket, which round two shows takes 17 seconds. So the window turned "the remote is stuck" and "the cable was not in yet" into one output and the script reported the interesting one. It waits two minutes now and names both possibilities. A script that cannot tell two outcomes apart must not report one of them, and this one did for exactly one round.
A fourth run is deliberately not counted. It was started by accident while checking that the script refuses with nothing attached, on a bench where something was attached, so no one was watching the screen. It was a read and the config came back identical, but an unobserved round is not a round. The rule it broke is this project's own: enumerating is not opening, and "checking that it refuses" is not a reason to open an irreplaceable device.
So the premise is gone. No command was needed. The third outcome written down above was the one that "can make the other two meaningless", and it is the one that happened, so the session-end experiment was not run: it would now be asking whether a command also achieves something the remote already does by itself.
And the chain in this section survives it intact, which is worth being clear about because it
would be easy to read this as the section being wrong. READ_FLASH clears its own state when it
completes, docs/usb-protocol.md, so after a completed read the gate at 0x284 is open and the
unconditional exit is available. The control is what section 99 predicts for a clean session. What
was wrong was section 95's inference, and mine on top of it, that the disconnect alone strands a
remote.
What it points at instead, as a hypothesis with a read only test¶
Both sticking occurrences followed a session containing a deliberate odd count hang, and the
session that contained none did not stick. Section 96 says what such a read does: it walks an
unbounded write pointer up through data memory from 0x046A, writing flash content over whatever it
passes.
0x284, 0x315 and the deferred work flags at 0x25D and 0x25E all sit below 0x046A, so
the runaway cannot reach them. 0x2628E's four idle flags do not: they are 0xED5, 0xED6,
0xEDC and 0xEDD, and that routine returns 1 only when all four are zero. It is one of the two
ways the guard chain in front of mode 2 can be satisfied. So a remote whose runaway left any of those
four nonzero cannot enter the application by that route, and would sit wherever it is until a power
cycle clears data memory. That fits the shape of what was seen: not "the cable did not register" but
"there was nowhere to go".
Unconfirmed, and it is a hypothesis rather than a finding, because one session of each is not two
samples of anything. What makes it worth stating is that the test is a read: READ_MISC selector
0x07 returns any data address, so reading 0xED5, 0xED6, 0xEDC and 0xEDD after a hang and
comparing them against a healthy remote settles it without writing anything. It does need a
deliberate hang, which is a judgment call and not something to schedule here.
The test, prepared, and its predictions committed first¶
packages/usb/bin/idle-flags-after-hang.ts, gated on HARMONY_ODD_READ_EXPERIMENT=1. Four steps: a
baseline on a healthy remote, the deliberate hang at page 0xFF offset 0x1000, the same reads
after it recovers, and a window of data memory compared against the page 0xFF image. Every step is
a READ_MISC or a READ_FLASH; nothing is written.
Prediction one, the hypothesis itself: at least one of the four idle flags reads nonzero
afterwards, where all four read zero before. 0x2628E returns "idle" only when all four are zero,
and that routine is one of the two ways the guard chain in front of the application can be satisfied.
Prediction two, the negative control: 0x284 and 0x315 are unchanged. Both sit below 0x046A
and the write pointer only climbs, so the runaway cannot reach them. If they move, the model of where
the pointer goes is wrong and prediction one means nothing either way.
Prediction three, and this is the sharp one: a window of data memory reproduces a known stretch of
flash, byte for byte. The runaway deposits what it reads. Its pointer starts at 0x046A and the
chunk that never terminates starts at page offset 0x1000 + 62, so data address a should hold page
0xFF byte 0x103E + (a - 0x046A). The script reads 48 bytes from 0x0480, which is above the few
bytes each reply overwrites in the endpoint buffer and below 0xD31 where the runaway corrupts its
own address and the correspondence stops. 48 of 48 or the model is wrong, and unlike the other two
this one cannot be explained by anything else: data memory containing a predictable stretch of program
flash is not a coincidence available to any other reading.
What each failure would mean, written down so none of them can be fitted afterwards:
- Flags nonzero, controls unchanged, window matches. The mechanism is confirmed end to end, and the stranding of 9 August 2026 has a cause. Section 95's story becomes a consequence of section 96.
- Window matches, flags still zero. The deposit is real and reaches data memory as described, but
it is not those four flags that strand a remote, so the guard chain needs reading further:
0x27826and0x2A942are the other two conditions and neither has been opened. - Window does not match, flags nonzero anyway. Then something else disturbs the flags and the deposit model is wrong, which is the worst outcome because it makes section 96's arithmetic suspect where 23 measurements currently support it.
- Everything unchanged. The recovery is a real device reset rather than a re-enumeration, and data memory is reinitialised before anything can be read. That is separable and costs nothing to check: a real reset also resets the remote's clock, so the screen answers it.
The last outcome is the likeliest way this experiment fails to say anything, and it is worth stating in advance rather than discovering: everything here is read after the remote comes back, and if coming back means resetting, the evidence is gone by then. If that is what happens, the next version has to read the flags while the remote is still hung, which the USB layer cannot do, and the question would go back to the firmware.
What it already changes for FreeHarmony is the part that mattered. A read only session that ends normally does not strand a remote, so version 1 needs to send nothing at the end, and the awkward choice section 95 posed does not arise. The gentle escape stays implemented, gated and unused, which is the right place for it.
Section 98 | the archive | section 100. Section 99 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.