How armmbed/daplink works
Project Type and Purpose
• This is an embedded interface‐firmware project (“DAPLink”) that runs on a secondary MCU (HIC), exposes a USB composite device to the host (PC), and bridges to a target MCU via SWD/JTAG.
• Key use cases: MSC (mass‐storage drag-and-drop programming), CDC (virtual COM port), CMSIS-DAP debug channels (HID, WinUSB, WebUSB).
File Structure—Top-Level Modules
• source/board → board-specific initialization and overrides
• source/target → target configuration abstraction
• source/family → per-vendor flash blobs and target reset logic
• source/hic_hal → hardware-abstraction layer (GPIO, USB PHY, peripheral drivers)
• source/cmsis-core → ARM CMSIS core headers and startup code
• source/rtos* → RTOS kernels (CMSIS-RTOS1 and RTOS2)
• source/daplink → main interface logic (USB interface dispatch, settings, flash manager)
• source/usb → USB device stack and class drivers (MSC, CDC, HID, WebUSB)
• tools/ → Python and shell scripts for generating configs, building, packaging
• test/ → Python test harnesses and unit tests
• docs/ → user, developer, board-porting, troubleshooting guides
README for Insights
• Confirms the four host interfaces (MSC, CDC, CMSIS-DAPv1 HID, CMSIS-DAPv2 WinUSB, WebUSB).
• Mentions quarterly and on-demand releases, CI via GitHub Actions.
• Points to developers’ guide for build and test flows.
Main Components & Their Interactions
a. Hardware Abstraction Layer (HAL)
• Board-specific code (source/board) + family flash blobs (source/family) + hic_hal drivers → sets up clocks, pins, USB PHY, memory.
b. RTOS Kernel
• CMSIS-RTOS1 or RTOS2 scheduler (source/rtos, source/rtos2) → task scheduling, inter-task messaging.
c. DAPLink Core
• Main interface (source/daplink/main_interface.c) → initializes USB stack, RTOS, modules; dispatches USB events; manages settings (flash storage).
• Settings Manager (source/daplink/settings) → reads/writes device configuration in non-volatile storage.
• Flash Manager / Drag-n-Drop (source/daplink/drag-n-drop) → virtual FS, flash programming via in-application programming (IAP) through SWD.
d. USB Device Stack
• Core USB (source/usb/usbd_core) → enumeration, endpoint management.
• Class Drivers: MSC, CDC, HID (CMSIS-DAP), WebUSB, WinUSB → expose endpoints to host.
e. CMSIS-DAP Host Driver
• Implements SWD/JTAG protocol over HID or vendor bulk → source/daplink/cmsis-dap & hic_hal/SWD host driver.
f. Target Communication
• Runs via SWD/JTAG port on application MCU → uses flash algorithms (source/family) and target_reset code (source/target).
g. Build & Test Infrastructure
• YAML board definitions (projects.yaml + records/) + Python tools (tools/generate_config.py) → generate per-board build configs.
• CI pipelines (.github/workflows) → build, test on Linux/Windows.
• Unit and acceptance tests (test/) → validate USB classes, board logic.
Architectural Patterns & Principles
• Layered Architecture: HAL → RTOS → Core → Interfaces → USB Stack → Host.
• Plugin-style Extensibility: board/family modules loaded at build time based on YAML configs.
• Separation of Concerns: distinct modules for USB, flash, settings, SWD transport.
• Build-time Meta-Programming: Python tools generate C headers from YAML.
Technologies & Frameworks
• C language, GCC/ArmCC/ArmClang toolchains
• CMSIS-Core & CMSIS-Driver
• CMSIS-RTOS1 and RTOS2 (RTX)
• USB device stack (USBD library)
• Python 3 for tools and tests
• GitHub Actions for CI