From badeef227a1705d9ecb5521266b88065b8b59795 Mon Sep 17 00:00:00 2001 From: Onno Kortmann Date: Fri, 6 Dec 2013 20:30:01 -0800 Subject: [PATCH] Properly detect and warn if multiple stlinky magic bytes are detected Stlinky can silently fail if its magic bytes are present anywhere else in the SRAM. This change makes st-term detect all stlinky structures, warn about multiple occurences and will use the last one detected. --- src/st-term.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/st-term.c b/src/st-term.c index bbf7ea3..a6a97fc 100644 --- a/src/st-term.c +++ b/src/st-term.c @@ -30,6 +30,7 @@ struct stlinky* stlinky_detect(stlink_t* sl) { static const uint32_t sram_base = 0x20000000; struct stlinky* st = malloc(sizeof(struct stlinky)); + int multiple=0; st->sl = sl; printf("sram: 0x%x bytes @ 0x%zx\n", sl->sram_base, sl->sram_size); uint32_t off; @@ -37,14 +38,22 @@ struct stlinky* stlinky_detect(stlink_t* sl) stlink_read_mem32(sl, sram_base + off, 4); if (STLINKY_MAGIC == READ_UINT32_LE(sl->q_buf)) { + if (multiple > 0) + printf("WARNING: another "); printf("stlinky detected at 0x%x\n", sram_base + off); st->off = sram_base + off; stlink_read_mem32(sl, st->off + 4, 4); st->bufsize = (size_t) *(unsigned char*) sl->q_buf; printf("stlinky buffer size 0x%zu \n", st->bufsize); - return st; + multiple++; } } + if (multiple > 0) { + if (multiple > 1) { + printf("Using last stlinky structure detected\n"); + } + return st; + } return NULL; } -- 2.30.2