Reset CPU before and after flash writing.
authorPeter Zotov <whitequark@whitequark.org>
Wed, 16 Feb 2011 11:28:20 +0000 (14:28 +0300)
committerPeter Zotov <whitequark@whitequark.org>
Wed, 16 Feb 2011 11:28:20 +0000 (14:28 +0300)
src/gdb-server.c

index af78ee2305280d07d219531e225693410bd997a3..1c9cd4c69f43b053a3568232a6d96ab6ab3e0e1b 100644 (file)
@@ -223,6 +223,9 @@ static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
 static int flash_go(struct stlink* sl) {
        int error = -1;
 
+       // Some kinds of clock settings do not allow writing to flash.
+       stlink_reset(sl);
+
        for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
                #ifdef DEBUG
                printf("flash_do: block %08x -> %04x\n", fb->addr, fb->length);
@@ -236,6 +239,8 @@ static int flash_go(struct stlink* sl) {
                }
        }
 
+       stlink_reset(sl);
+
        error = 0;
 
 error:
@@ -451,8 +456,6 @@ int serve(struct stlink* sl, int port) {
                                } else {
                                        reply = strdup("OK");
                                }
-
-                               stlink_reset(sl);
                        }
 
                        if(reply == NULL)