In write_buffer_to_sram() write as much as possible with write_mem32
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Tue, 17 Jan 2012 20:24:01 +0000 (21:24 +0100)
committerUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Tue, 17 Jan 2012 21:16:55 +0000 (22:16 +0100)
src/stlink-common.c

index 0c391129c1df43cee52e3c508080b08443d79fd2..97bc3e14066e98b577e729a067e6f595aadb5e54 100644 (file)
@@ -864,8 +864,16 @@ on_error:
 
 int write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, size_t size) {
     /* write the buffer right after the loader */
-    memcpy(sl->q_buf, buf, size);
-    stlink_write_mem8(sl, fl->buf_addr, size);
+    size_t chunk = size & ~0x3;
+    size_t rem   = size & 0x3;
+    if (chunk) {
+        memcpy(sl->q_buf, buf, chunk);
+        stlink_write_mem32(sl, fl->buf_addr, chunk);
+    }
+    if (rem) {
+        memcpy(sl->q_buf, buf+chunk, rem);
+        stlink_write_mem8(sl, (fl->buf_addr)+chunk, rem);
+    }
     return 0;
 }