Have fun!
+Resetting the chip from GDB
+===========================
+
+You may reset the chip using GDB if you want. You'll need to use `target
+extended-remote' command like in this session:
+(gdb) target extended-remote localhost:1111
+Remote debugging using localhost:1111
+0x080007a8 in _startup ()
+(gdb) kill
+Kill the program being debugged? (y or n) y
+(gdb) run
+Starting program: /home/whitequark/ST/apps/bally/firmware.elf
+
+Remember that you can shorten the commands. `tar ext :1111' is good enough
+for GDB.
+
Running programs from SRAM
==========================
printf("GDB connected.\n");
+ /*
+ * To allow resetting the chip from GDB it is required to
+ * emulate attaching and detaching to target.
+ */
+ unsigned int attached = 1;
+
while(1) {
char* packet;
}
case 'v': {
- char *separator = strstr(packet, ":"), *params = "";
- if(separator == NULL) {
- separator = packet + strlen(packet);
- } else {
- params = separator + 1;
- }
+ char *params = NULL;
+ char *cmdName = strtok_r(packet, ":;", ¶ms);
- unsigned cmdNameLength = (separator - &packet[1]);
- char* cmdName = calloc(cmdNameLength + 1, 1);
- strncpy(cmdName, &packet[1], cmdNameLength);
+ cmdName++; // vCommand -> Command
if(!strcmp(cmdName, "FlashErase")) {
char *s_addr, *s_length;
} else {
reply = strdup("OK");
}
+ } else if(!strcmp(cmdName, "Kill")) {
+ attached = 0;
+
+ reply = strdup("OK");
}
if(reply == NULL)
reply = strdup("");
- free(cmdName);
-
break;
}
break;
case '?':
- reply = strdup("S05"); // TRAP
+ if(attached) {
+ reply = strdup("S05"); // TRAP
+ } else {
+ /* Stub shall reply OK if not attached. */
+ reply = strdup("OK");
+ }
break;
case 'g':
break;
}
- case 'k': {
- // After this function will be entered afterwards, the
- // chip will be reset anyway. So this is a no-op.
+ case '!': {
+ /*
+ * Enter extended mode which allows restarting.
+ * We do support that always.
+ */
+
+ reply = strdup("OK");
+
+ break;
+ }
+
+ case 'R': {
+ /* Reset the core. */
+
+ stlink_reset(sl);
+ init_code_breakpoints(sl);
+
+ attached = 1;
- close(client);
- return 0;
+ reply = strdup("OK");
+
+ break;
}
default: