elaphureLink

repository·master·Indexed 41 days ago

https://github.com/windowsair/elaphurelink

A CMSIS-DAP compliant debugger solution that enables remote debugging for Arm Keil µVision by bridging TCP/IP connections to the Debug Access Port (DAP). It supports SWD and JTAG debug ports, the ADIv5 debug spec, and ARMv6-M, ARMv7-M, and ARMv8-M architectures. The tool includes a Proxy API for custom application development and a protocol for implementing custom Server Providers.

Tokens
9.2K
Snippets
13
Records
35
Agent score
52%

What's inside elaphureLink

  1. Overview of elaphureLink

    master
    elaphureLink is a CMSIS-DAP compliant debugger solution designed for the Arm® Keil® µVision® IDE. It acts as a bridge that provides conversion between TCP/IP and the Debug Access Port (DAP). It supports SWD and JTAG debug ports, the ADIv5 debug spec, and various ARM architectures including ARMv6-M, ARMv7-M, and ARMv8-M.
  2. Understand the elaphureLink Vendor Command request/response format

    master

    elaphureLink vendor commands extend the native CMSIS-DAP commands. All commands follow a specific binary packet format for requests and responses.

    Request Packet Structure

    • Prefix (8 bits): Must be 0x88 to identify an elaphureLink command.
    • Command Type (8 bits): If the value is 0-127, it is the command type. If the value is 128-255, the following 2 bytes are interpreted as a 16-bit unsigned integer representing the Extended Command Type.
    • Payload Length (16 bits): The length of the payload data.
    • Payload Data (x bytes): Variable length data specific to the command.

    Response Packet Structure

    • Prefix (8 bits): Must be 0x88.
    • Status (8 bits): Indicates the result of the command:
      • 0x0: Success.
      • 0x1: Execution failed.
      • 0x2: Command is pending.
      • Other values: Reserved (may be treated as failure).
    • Payload Length (16 bits): The length of the response payload.
    • Payload Data (x bytes): Variable length data specific to the response.
  3. Execute the Data Transfer phase

    master

    During the data transfer phase, CMSIS-DAP commands are transmitted as-is. To optimize performance, elaphureLink follows these conventions:

    • Command Merging: Multiple CMSIS-DAP commands can be merged into a single packet transmission.
    • Batching: Use the DAP_ExecuteCommands command to transfer multiple commands in one packet.
    • Unpredictable Responses: If a client needs to send a command with an unpredictable response length, that command must be placed last in the packet and can only appear once.

    This approach allows the DAP host to function with little to no modification.

    elaphureLink Proxy (client)          DAP host (server)
             |                                     |
             |       REQ_CMSIS_DAP_COMMAND         |
             | ----------------------------------> |
             |                                     |
             |       RES_CMSIS_DAP_COMMAND         |
             | <---------------------------------- |
             |                                     |
             |       REQ_CMSIS_DAP_COMMAND         |
             | ----------------------------------> |
             |                                     |
             |       RES_CMSIS_DAP_COMMAND         |
             | <---------------------------------- |
  4. Manage elaphureLink vendor scope

    master

    To distinguish elaphureLink vendor commands from native CMSIS-DAP commands, the system uses a "vendor scope". Within this scope, only elaphureLink vendor commands (including native passthrough) are allowed; direct native CMSIS-DAP commands are prohibited.

    Note: Entering or exiting the vendor scope may reset certain debug session states.

    Enter Vendor Scope

    Command Type: 0x2

    • No payload.
    • Response Status: %x0 for success.

    Exit Vendor Scope

    Command Type: 0x3

    • No payload.
    • Response Status: %x0 for success.
  5. Understand the elaphureLink Proxy Protocol architecture

    master

    The elaphureLink proxy protocol uses a server/client architecture over a single TCP/IP connection.

    • Server: Exports the DAP (Debug Access Port) device.
    • Client: Imports the DAP device.

    The protocol is fully compliant with the CMSIS-DAP protocol, meaning all data transmitted through the proxy is valid CMSIS-DAP commands. This allows DAP hosts to interact with the proxy with minimal to no modifications. All packet transmissions should be sent as complete packets at the low-level transport layer to avoid CMSIS-DAP limitations.

  6. How elaphureLink architecture works

    master

    elaphureLink is composed of five main functional components that facilitate remote debugging:

    1. AGDI (elaphureLinkAGDI): The Application Generic Debug Interface. It serves as the bridge between Arm Keil µVision and the RDDI connection. It handles basic debugger features, complex breakpoints, flash programming, and system memory access.
    2. RDDI (elaphureLinkRDDI): The Remote Device Debug Interface. It converts requests into standard CMSIS-DAP commands to allow remote DAP devices to communicate with the debug interface.
    3. Proxy (elaphureLinkProxy): Communicates with the debug unit and exports APIs for connection management. Developers can use these APIs to build custom applications.
    4. Wpf (elaphureLink.Wpf): A GUI wrapper for elaphureLinkProxy that provides utilities for driver management and connection control.
    5. Server Providers: The physical or virtual devices (e.g., DAP probes) that implement CMSIS-DAP to provide debugging capabilities.
  7. Requirements for elaphureLink Service Providers

    master

    When implementing a service provider for elaphureLink, you must adhere to the following two requirements to ensure compatibility with the elaphureLinkProxy and the debug unit:

    1. Buffer Management: elaphureLink ignores the Packet Count and Packet Size information provided in the DAP. You must ensure that you reserve a contiguous buffer larger than 1400 bytes for every packet.
    2. Device Identification: The product name of the DAP device must contain the substring CMSIS-DAP. If this substring is missing, the device will not be recognized correctly.
  8. Understand elaphureLink data type mnemonics

    master

    The elaphureLink vendor command bit-stream uses specific mnemonics to define data types:

    • bslbf: Bit string, left bit first. Represented as '1000 0001'. Blanks are for readability only.
    • word: A 32-bit (4-byte) data type stored in little-endian order.
    • half_word: A 16-bit (2-byte) data type stored in little-endian order.
    • double_word: A 64-bit (8-byte) data type stored in little-endian order.
  9. Implement a custom Debug Unit in DbgCM

    master

    DbgCM provides a high-level driver template with ULINK2-equivalent functionality (Debug, Trace, Flash, and complex trace handling). To adapt DbgCM to a custom hardware debug unit, you must implement the low-level communication layer. The middle and upper layers (run/stop/step, breakpoints, watchpoints, etc.) are already implemented via Memory R/W and do not require modification.

    To integrate your hardware, follow these implementation steps:

    1. Communication Layer: Expose your Debug Unit's communication layer to the driver.
    2. JTAG Support: Implement low-level JTAG functions in JTAG.cpp (Detect Chain, Debug/Access Port R/W, Memory R/W, Register R/W, and Sys Calls).
    3. SWD Support: Implement low-level SWD functions in SWD.cpp (Debug/Access Port R/W, Memory R/W, Register R/W, and Sys Calls).
    4. SWV Support: Implement low-level SWV functions in SWV.cpp (Setup, Read, Flush).
    5. Detection & Selection: Implement debug unit detection and selection (JTAG/SWD) in SetupDbg.cpp (specifically within Update and OnSelchangeConfigUnit).
    6. Target Lifecycle: Implement debug unit init/uninit and target detection in AGDI.cpp (InitTarget, StopTarget).
    7. Target Reset: Implement target reset in AGDI.cpp (ResetTarget).
  10. Flash program sequence using elaphureLink vendor commands

    master

    When performing firmware downloads or flashing operations between a Host and a Target device, all operations must be executed within the elaphureLink vendor scope. The standard sequence for flashing a device involves entering the vendor scope, loading the FlashOS algorithm, performing sector erasures, programming pages, and finally exiting the vendor scope.

    Standard Sequence:

    1. Enter vendor scope (0x2): Transitions the target into the vendor command mode.
    2. Load FlashOS algorithm (0x4): Loads the necessary algorithm into the target.
    3. Erase sector (0x6): Performed in a loop for each sector required.
    4. Program page (0x7): Performed in a loop for each page to be written.
    5. Exit vendor scope (0x3): Returns the target to its normal operating mode.
    sequenceDiagram
        participant Host as Host
        participant Target as Target
    
        Host->>Target: Enter vendor scope (0x2)
        Target-->>Host: Acknowledge
    
        Host->>Target: Load FlashOS algorithm (0x4)
        Target-->>Host: Acknowledge
    
        loop Erase sector
            Host->>Target: Erase sector (0x6)
            Target-->>Host: Acknowledge
        end
    
        loop Program Page
            Host->>Target: Program page (0x7)
            Target-->>Host: Acknowledge
        end
    
        Host->>Target: Exit vendor scope (0x3)
        Target-->>Host: Acknowledge
  11. Download and Install elaphureLink

    master

    elaphureLink is distributed as a portable version. You do not need a traditional installer; simply extract the files and run the executable.

    • Stable Versions: Available via the Releases page.
    • Latest Builds: Available via GitHub Actions (build-binary).
    • Installation: Extract the downloaded package and run elaphureLink.Wpf.exe.
    • Updating: You can check for and apply updates directly through the Info Page within the elaphureLink.Wpf application.