Merge pull request #185 from ouah/master
authortexane <texane@gmail.com>
Sun, 27 Oct 2013 16:10:16 +0000 (09:10 -0700)
committertexane <texane@gmail.com>
Sun, 27 Oct 2013 16:10:16 +0000 (09:10 -0700)
Restore gdb-server cleanup handlers for MinGW

gdbserver/gdb-server.c
src/st-term.c
src/stlink-common.h
src/stlink-usb.c

index a6de1b20d2db8f68fc6f2891e2b5e1f338ce809e..7e8bb685a7ab7e7e12a931ce7fd7fd6cd86e834d 100644 (file)
@@ -7,6 +7,7 @@
 */
 
 #include <getopt.h>
+#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -18,7 +19,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <signal.h>
 #endif
 
 #include <stlink-common.h>
@@ -57,7 +57,6 @@ typedef struct _st_state_t {
 int serve(stlink_t *sl, st_state_t *st);
 char* make_memory_map(stlink_t *sl);
 
-#ifndef __MINGW32__
 static void cleanup(int signal __attribute__((unused))) {
     if (connected_stlink) {
         /* Switch back to mass storage mode before closing. */
@@ -68,7 +67,6 @@ static void cleanup(int signal __attribute__((unused))) {
 
     exit(1);
 }
-#endif
 
 
 
@@ -174,7 +172,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
 
 
 int main(int argc, char** argv) {
-       uint32_t voltage;
+       int32_t voltage;
 
        stlink_t *sl = NULL;
 
@@ -198,10 +196,8 @@ int main(int argc, char** argv) {
     }
 
     connected_stlink = sl;
-#ifndef __MINGW32__
     signal(SIGINT, &cleanup);
     signal(SIGTERM, &cleanup);
-#endif
 
     if (state.reset) {
                stlink_reset(sl);
index 346cca58ffb398fd66f5f3bcc7e8d9c7760d1484..bbf7ea37ef714a7e39062c5ee6ee5f173d44e0b0 100644 (file)
 
 #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;
@@ -26,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;
@@ -121,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");
index edf8c6733b46a43288a6ccc1670c884fd45d8d8e..579622892b38ccb4858a50636f454f0537003663 100644 (file)
@@ -397,7 +397,7 @@ static const chip_params_t devices[] = {
         void (*step) (stlink_t * stl);
         int (*current_mode) (stlink_t * stl);
         void (*force_debug) (stlink_t *sl);
-        uint32_t (*target_voltage) (stlink_t *sl);
+        int32_t (*target_voltage) (stlink_t *sl);
     } stlink_backend_t;
 
     struct _stlink {
index fa2bd7e081c50154fbd3164ce7250ed334b737fe..ec4053ac7bd050bd3d4f0f91b750084902e7a94a 100644 (file)
@@ -203,7 +203,7 @@ void _stlink_usb_version(stlink_t *sl) {
     }
 }
 
-int _stlink_usb_target_voltage(stlink_t *sl) {
+int32_t _stlink_usb_target_voltage(stlink_t *sl) {
     struct stlink_libusb * const slu = sl->backend_data;
     unsigned char* const rdata = sl->q_buf;
     unsigned char* const cmd  = sl->c_buf;