()
| 163 | |
| 164 | |
| 165 | def main() -> int: |
| 166 | p = argparse.ArgumentParser() |
| 167 | p.add_argument("--port", default=DEFAULT_PORT) |
| 168 | p.add_argument("--baud", default=DEFAULT_BAUD, type=int) |
| 169 | p.add_argument( |
| 170 | "--tx-pin", |
| 171 | default=10, |
| 172 | type=int, |
| 173 | help="LPC845 GPIO PIO0_n driven by bit-bang TX (default: P0_10)", |
| 174 | ) |
| 175 | p.add_argument( |
| 176 | "--rx-pin", |
| 177 | default=11, |
| 178 | type=int, |
| 179 | help="LPC845 GPIO PIO0_n routed to SCT input 0 for capture " |
| 180 | "(default: P0_11; any PIO0_n works via SWM)", |
| 181 | ) |
| 182 | args = p.parse_args() |
| 183 | |
| 184 | if serial is None: |
| 185 | print( |
| 186 | "ERROR: pyserial not installed. Run: uv pip install pyserial", |
| 187 | file=sys.stderr, |
| 188 | ) |
| 189 | return 2 |
| 190 | |
| 191 | print(f"[lpc-pin-toggle-rx] opening {args.port} @ {args.baud}") |
| 192 | try: |
| 193 | s = serial.Serial(args.port, args.baud, timeout=0.1) |
| 194 | except serial.SerialException as e: |
| 195 | print(f"ERROR: could not open {args.port}: {e}", file=sys.stderr) |
| 196 | return 2 |
| 197 | |
| 198 | with s: |
| 199 | # The LPC845-BRK uses a CMSIS-DAP USB-CDC bridge; DTR/RTS toggles |
| 200 | # reset the target. Hold them de-asserted and let the boot banner |
| 201 | # drain before sending any RPC. This matches the bring-up echo |
| 202 | # test's open sequence (phases.py::_run_bring_up_tests). |
| 203 | s.dtr = False |
| 204 | s.rts = False |
| 205 | time.sleep(0.5) |
| 206 | s.reset_input_buffer() |
| 207 | time.sleep(2.0) |
| 208 | s.reset_input_buffer() |
| 209 | |
| 210 | # Health check via the bring-up sketch's echo RPC. Confirms the |
| 211 | # serial pipe + JSON-RPC parser are alive before we trust the |
| 212 | # pinToggleRx result. |
| 213 | echo = send_rpc(s, "echo", args=[42], request_id=1, timeout=5.0) |
| 214 | if not echo or echo.get("result") != 42: |
| 215 | print( |
| 216 | "ERROR: echo failed; is AutoResearchLpc flashed and " |
| 217 | f"running? Got: {echo}", |
| 218 | file=sys.stderr, |
| 219 | ) |
| 220 | return 2 |
| 221 | print("[lpc-pin-toggle-rx] echo ok") |
| 222 |
no test coverage detected