Support "force debug" command, required by gdb server
authorKarl Palsson <karlp@tweak.net.au>
Wed, 12 Oct 2011 19:56:19 +0000 (19:56 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Wed, 12 Oct 2011 19:56:19 +0000 (19:56 +0000)
usb implementation provided by Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>

Glued together again by me.  With this change, gdbserver actually enters debug and gdbserver
stays open!

src/stlink-common.c
src/stlink-common.h
src/stlink-sg.c
src/stlink-usb.c

index a3170074e402c3ea939ef684c1a097152d17d83b..53a359bb6c876a7d92c4c24a70b1e5943b4a9619 100644 (file)
@@ -272,6 +272,12 @@ void stlink_enter_swd_mode(stlink_t *sl) {
     sl->backend->enter_swd_mode(sl);
 }
 
+// Force the core into the debug mode -> halted state.
+void stlink_force_debug(stlink_t *sl) {
+    D(sl, "\n*** stlink_force_debug_mode ***\n");
+    sl->backend->force_debug(sl);
+}
+
 void stlink_exit_dfu_mode(stlink_t *sl) {
     D(sl, "\n*** stlink_exit_dfu_mode ***\n");
     sl->backend->exit_dfu_mode(sl);
index a716f4d45b9b3d07b799bea26cca75e07ef20672..37de9fc12f7600a015cdc02cdd0344697e563505 100644 (file)
@@ -123,6 +123,7 @@ extern "C" {
         void (*write_reg) (stlink_t *sl, uint32_t reg, int idx);
         void (*step) (stlink_t * stl);
         int (*current_mode) (stlink_t * stl);
+        void (*force_debug) (stlink_t *sl);
     } stlink_backend_t;
 
     struct _stlink {
@@ -187,11 +188,10 @@ extern "C" {
     void stlink_write_reg(stlink_t *sl, uint32_t reg, int idx);
     void stlink_step(stlink_t *sl);
     int stlink_current_mode(stlink_t *sl);
+    void stlink_force_debug(stlink_t *sl);
 
 
     // unprocessed
-    void stlink_force_debug(stlink_t *sl);
-
     int stlink_erase_flash_mass(stlink_t* sl);
     int stlink_write_flash(stlink_t* sl, stm32_addr_t address, uint8_t* data, unsigned length);
     
index 891d16e1b7c08cbeef6d62100774f0f8fd7e88ef..320fb780a9b55126191c6a041b96d44b4b2b4992 100644 (file)
@@ -403,7 +403,7 @@ void _stlink_sg_status(stlink_t *sl) {
 
 // Force the core into the debug mode -> halted state.
 
-void stlink_force_debug(stlink_t *sl) {
+void _stlink_sg_force_debug(stlink_t *sl) {
     struct stlink_libsg *sg = sl->backend_data;
     D(sl, "\n*** stlink_force_debug ***\n");
     clear_cdb(sg);
@@ -718,7 +718,8 @@ stlink_backend_t _stlink_sg_backend = {
     _stlink_sg_read_reg,
     _stlink_sg_write_reg,
     _stlink_sg_step,
-    _stlink_sg_current_mode
+    _stlink_sg_current_mode,
+    _stlink_sg_force_debug
 };
 
 stlink_t* stlink_open(const char *dev_name, const int verbose) {
index 90d5913bb882e2b6bc97870b62abbf7286237d2b..16f934304027f9a90ef1fb71dbf12e7aeb6e9d67 100644 (file)
@@ -238,6 +238,23 @@ void _stlink_usb_status(stlink_t * sl) {
 
 }
 
+void _stlink_usb_force_debug(stlink_t *sl) {
+    struct stlink_libusb *slu = sl->backend_data;
+    unsigned char* const buf = sl->q_buf;
+    ssize_t size;
+
+    memset(buf, 0, sizeof (sl->q_buf));
+
+    buf[0] = STLINK_DEBUG_COMMAND;
+    buf[1] = STLINK_DEBUG_FORCEDEBUG;
+    size = send_recv(slu, buf, STLINK_CMD_SIZE, buf, sizeof (sl->q_buf));
+    if (size == -1) {
+        printf("[!] send_recv\n");
+        return;
+    }
+}
+
+
 void _stlink_usb_enter_swd_mode(stlink_t * sl) {
     struct stlink_libusb * const slu = sl->backend_data;
     unsigned char* const buf = sl->q_buf;
@@ -400,7 +417,8 @@ stlink_backend_t _stlink_usb_backend = {
     _stlink_usb_read_reg,
     _stlink_usb_write_reg,
     _stlink_usb_step,
-    _stlink_usb_current_mode
+    _stlink_usb_current_mode,
+    _stlink_usb_force_debug
 };