X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fst-term.c;h=bbf7ea37ef714a7e39062c5ee6ee5f173d44e0b0;hb=3652f98a5d6c8bbe4707c5764b10e5bb9a13c370;hp=9be3263afde7d8d4b8771810d2c4825a7fa2f4a1;hpb=596fb35916ef2f1da8b817fa4b6e365e71c0fc5a;p=fw%2Fstlink diff --git a/src/st-term.c b/src/st-term.c index 9be3263..bbf7ea3 100644 --- a/src/st-term.c +++ b/src/st-term.c @@ -1,4 +1,5 @@ #include +#include /* According to POSIX.1-2001 */ #include #include @@ -12,6 +13,11 @@ #define STLINKY_MAGIC 0xDEADF00D +#define READ_UINT32_LE(buf) ((uint32_t) ( buf[0] \ + | buf[1] << 8 \ + | buf[2] << 16 \ + | buf[3] << 24)) + struct stlinky { stlink_t *sl; uint32_t off; @@ -25,11 +31,11 @@ struct stlinky* stlinky_detect(stlink_t* sl) static const uint32_t sram_base = 0x20000000; struct stlinky* st = malloc(sizeof(struct stlinky)); st->sl = sl; - printf("sram: 0x%x bytes @ 0x%x\n", sl->sram_base, sl->sram_size); + printf("sram: 0x%x bytes @ 0x%zx\n", sl->sram_base, sl->sram_size); uint32_t off; for (off = 0; off < sl->sram_size; off += 4) { stlink_read_mem32(sl, sram_base + off, 4); - if ( STLINKY_MAGIC== *(uint32_t*) sl->q_buf) + if (STLINKY_MAGIC == READ_UINT32_LE(sl->q_buf)) { printf("stlinky detected at 0x%x\n", sram_base + off); st->off = sram_base + off; @@ -120,6 +126,7 @@ static int keep_running = 1; static int sigcount=0; void cleanup(int dummy) { + (void) dummy; sigcount++; keep_running = 0; printf("\n\nGot a signal\n");