/** * (c) 2026, Micro:bit Educational Foundation and contributors * * Derived from dapjs (https://github.com/ARMmbed/dapjs) which is * Copyright (c) Arm Limited 2018 * Copyright (c) Microsoft Corporation * * SPDX-License-Identifier: MIT * * See arm-debug.ts for the full dapjs license. * * DAPLink serial and flash access via CMSIS-DAP vendor commands. * * DAPLink is the interface firmware running on the micro:bit's debug chip * (KL27). It extends the standard CMSIS-DAP protocol with vendor-specific * commands (0x80+) for: * * - UART serial pass-through (DapLinkSerial): reading/writing serial data * to the target micro:bit's UART, with configurable baud rate and * polling-based read loop. * * - Hex-file flash streaming (dapLinkFlash): streaming Intel HEX data to * DAPLink which handles erasing, programming, and verifying flash pages. * This is the "full flash" path — as opposed to partial flashing which * writes individual pages via SWD. */ import { Logging } from "../logging.js"; import { type ArmDebug } from "./arm-debug.js"; import { type CmsisDap } from "./cmsis-dap.js"; /** Read the DAPLink unique ID (same string as USB serial number). */ export declare const DAPLINK_VENDOR_READ_UNIQUE_ID = 128; export declare const DAPLINK_VENDOR_READ_SETTINGS = 129; export declare const DAPLINK_VENDOR_WRITE_SETTINGS = 130; export declare const DAPLINK_VENDOR_SERIAL_READ = 131; export declare const DAPLINK_VENDOR_SERIAL_WRITE = 132; export declare const DAPLINK_VENDOR_FLASH_RESET = 137; export declare const DAPLINK_VENDOR_FLASH_OPEN = 138; export declare const DAPLINK_VENDOR_FLASH_CLOSE = 139; export declare const DAPLINK_VENDOR_FLASH_WRITE = 140; export declare class DapLinkSerial { private dap; private logging; private polling; constructor(dap: CmsisDap, logging: Logging); getBaudrate(): Promise; setBaudrate(baudrate: number): Promise; read(): Promise; write(data: string): Promise; startPolling(onData: (data: string) => void, serialDelay?: number): Promise; stopPolling(): void; /** * Drain any buffered serial data from DAPLink's UART ring buffer. * Reads and discards until empty. */ drain(): Promise; } export declare function dapLinkFlash(adi: ArmDebug, buffer: Uint8Array, onProgress?: (progress: number) => void): Promise; /** * Read the DAPLink unique ID via vendor command 0x80. Returns the same * 48-char hex string as the USB serial number but isn't affected by * browser anti-fingerprinting. */ export declare function readDaplinkUniqueId(dap: CmsisDap, logging: Logging): Promise; /** * Read a 32-bit word from memory, retrying on transfer errors. * Useful for reads immediately after reset when the target may not * be ready to respond. */ export declare function readMem32WithRetry(adi: ArmDebug, address: number, logging: Logging, maxRetries?: number, delayMs?: number): Promise;