diff --git a/CHANGELOG.md b/CHANGELOG.md index da4a17f9dd0c18d855c6a48407a89064bae89ceb..d160500442209f1c7c294225bf28713d46804f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- `ls_cmsis_dap`: A tool to enumerate CMSIS-DAP debuggers + ### Changed - `main.py` was moved into an app to allow easier reconfiguration of the default app. The new `main.py` points to the "old" one so behavior is not diff --git a/tools/ls_cmsis_dap/Makefile b/tools/ls_cmsis_dap/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3a1fefe7fa6953d733c704fad77a47a0d34d8449 --- /dev/null +++ b/tools/ls_cmsis_dap/Makefile @@ -0,0 +1,16 @@ +.PHONY: all clean + +all: ls_cmsis_dap-hidraw ls_cmsis_dap-libusb + +clean: + -rm *.o ls_cmsis_dap-hidraw ls_cmsis_dap-libusb + +ls_cmsis_dap.o: ls_cmsis_dap.c + +ls_cmsis_dap-hidraw: LDFLAGS=-lhidapi-hidraw +ls_cmsis_dap-hidraw: ls_cmsis_dap.o + $(CC) $(LDFLAGS) -o $@ $< + +ls_cmsis_dap-libusb: LDFLAGS=-lhidapi-libusb +ls_cmsis_dap-libusb: ls_cmsis_dap.o + $(CC) $(LDFLAGS) -o $@ $< diff --git a/tools/ls_cmsis_dap/ls_cmsis_dap.c b/tools/ls_cmsis_dap/ls_cmsis_dap.c new file mode 100644 index 0000000000000000000000000000000000000000..bd39674f12a5b3174a220fc67f4d96c78a6efc23 --- /dev/null +++ b/tools/ls_cmsis_dap/ls_cmsis_dap.c @@ -0,0 +1,31 @@ +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <hidapi/hidapi.h> + +int main(int argc, char *argv[]) +{ + int rc = 0; + if ((rc = hid_init())) { + fprintf(stderr, "hid_init: %d\n", rc); + goto done; + } + + struct hid_device_info *hid_devs = hid_enumerate(0x0d28, 0x0204); + if (!hid_devs) { + fprintf(stderr, "hid_enumerate: NULL\n"); + rc = 1; + goto done; + } + + for (struct hid_device_info *dev = hid_devs; dev; dev = dev->next) { + fprintf(stdout, "%s\n", dev->path); + } + +done: + if (hid_devs) { + hid_free_enumeration(hid_devs); + } + hid_exit(); + return -1; +}