mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 03:15:36 +00:00
UV-K5 V3 emulator: QEMU machine for the PY32F071
Adds a QEMU machine for the Puya PY32F071 (Cortex-M0+) so Quansheng UV-K5 V3 firmware can run on a PC. The firmware boots to its main loop in about five seconds and the LCD contents are readable. Register layouts come from the vendor CMSIS header shipped with the firmware rather than guesswork. Modelled: RCC, GPIO, ADC, both SPI controllers, DMA1 and the PY25Q16 flash; everything else answers through a logging catch-all, which is how the next thing worth modelling gets identified. Seven things had to be right before it would boot, each found by watching where the firmware stopped: flash aliased at the application offset, clock ready bits, self-clearing ADC calibration, SPI transfer flags, DMA-driven flash reads, SysTick poll acceleration, and the bit-banged transceiver bus idling low. SysTick needs explanation. SYSTICK_DelayUs polls the counter and accumulates differences; under emulation a register read costs far more relative to guest time, so a measured 120 ms delay would have taken about 7.7 hours. Lowering the clock does not help because the bottleneck is loop iterations, not counter speed. Reporting a value that runs ahead of the real counter does, via a new poll-boost property on SysTick. Guest time therefore runs fast during delays: fine for exercising menus and control flow, wrong for judging signal timing. Also includes the host build of the CW timing chain (harness, stubs, shim, tests), which compiles app/cwkeyer.c and app/cwmacro.c unmodified against stub drivers with a virtual clock and scripted paddle input. Known gap: keypad rows reach the firmware's scan and KEYBOARD_Poll returns the right key code, but the UI does not react yet. Not modelled, and not intended to be: radio behaviour. The transceiver chip has no public datasheet, so keying envelopes and emissions need real hardware.
This commit is contained in:
commit
c0a09827ed
53 files changed
+5068
No files matched your search
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
# Prove whether the keypad sees column changes, by driving a column by hand.
|
||||
#
|
||||
# Holds a key, writes GPIOB's BSRR to pull column 1 (pin 6) low, then reads IDR.
|
||||
# If row0 goes low, the matrix is wired correctly and the earlier samples simply
|
||||
# landed between scans. If it stays high, the column signal is not reaching the
|
||||
# keypad model.
|
||||
#
|
||||
# BSRR: low half sets a pin, high half resets it (py32f071xB.h).
|
||||
set -uo pipefail
|
||||
|
||||
ELF="${ELF:-$HOME/uvk5-port/uvk5-sat/build/CW/nr7y.cw.elf}"
|
||||
KEY="${1:-MENU}"
|
||||
BASE=0x50000400
|
||||
BSRR=$((BASE + 0x18))
|
||||
IDR=$((BASE + 0x10))
|
||||
|
||||
# Hold the key first.
|
||||
python3 - "$KEY" <<'PY'
|
||||
import json, socket, sys
|
||||
key = sys.argv[1]
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.connect("/tmp/uvk5-qmp.sock")
|
||||
buf = b""
|
||||
def rd():
|
||||
global buf
|
||||
while b"\n" not in buf:
|
||||
buf += s.recv(4096)
|
||||
line, buf = buf.split(b"\n", 1)
|
||||
return json.loads(line)
|
||||
rd()
|
||||
for p in ({"execute": "qmp_capabilities"},
|
||||
{"execute": "qom-set", "arguments": {"path": "/machine/keypad",
|
||||
"property": "press", "value": key}}):
|
||||
s.sendall(json.dumps(p).encode() + b"\n")
|
||||
while True:
|
||||
m = rd()
|
||||
if "return" in m or "error" in m:
|
||||
break
|
||||
print(f"holding {key}")
|
||||
PY
|
||||
|
||||
SCRIPT=$(mktemp --suffix=.gdb)
|
||||
trap 'rm -f "$SCRIPT"' EXIT
|
||||
|
||||
{
|
||||
echo "set confirm off"
|
||||
echo "set pagination off"
|
||||
echo "target remote :1234"
|
||||
# Freeze the guest so the firmware's own scan cannot move the columns.
|
||||
echo "interrupt"
|
||||
echo "printf \"before \""
|
||||
echo "x/1xw $IDR"
|
||||
# Pull pin 6 (column 1) low: write bit 6 into the reset half of BSRR.
|
||||
echo "set *(unsigned int *)$BSRR = 0x00400000"
|
||||
echo "printf \"col1 low\""
|
||||
echo "x/1xw $IDR"
|
||||
# Release it again.
|
||||
echo "set *(unsigned int *)$BSRR = 0x00000040"
|
||||
echo "printf \"released\""
|
||||
echo "x/1xw $IDR"
|
||||
echo "detach"
|
||||
echo "quit"
|
||||
} >"$SCRIPT"
|
||||
|
||||
gdb-multiarch -batch -x "$SCRIPT" "$ELF" 2>/dev/null | grep -E "before|col1 low|released|0x5000"
|
||||
Reference in new issue
Block a user