From 079148247ce01c8b2ca0f8622e3d754d1f0ed3f3 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Tue, 17 Jan 2012 21:24:01 +0100 Subject: [PATCH] In write_buffer_to_sram() write as much as possible with write_mem32 --- src/stlink-common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stlink-common.c b/src/stlink-common.c index 0c39112..97bc3e1 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -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; } -- 2.47.2