projects
/
fw
/
openocd
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
optimize: replace while loop by memcpy
[fw/openocd]
/
src
/
flash
/
nor
/
stm32lx.c
diff --git
a/src/flash/nor/stm32lx.c
b/src/flash/nor/stm32lx.c
index 8a6ad7bcb3a04e8120401c7a87ae7d1dd8d10d42..29a7aac9fc91abf73472c35000348c8ee861c040 100644
(file)
--- a/
src/flash/nor/stm32lx.c
+++ b/
src/flash/nor/stm32lx.c
@@
-464,17
+464,12
@@
static int stm32lx_write(struct flash_bank *bank, uint8_t *buffer,
if (bytes_remaining)
{
if (bytes_remaining)
{
- uint32_t value = 0;
- for (int i = 0; i < 4; i++)
- {
- if (bytes_remaining)
- {
- value += (buffer[i] << (8 * i));
- bytes_remaining--;
- }
- }
+ uint8_t last_word[4] = {0xff, 0xff, 0xff, 0xff};
- retval = target_write_u32(target, address, value);
+ /* copy the last remaining bytes into the write buffer */
+ memcpy(last_word, buffer+bytes_written, bytes_remaining);
+
+ retval = target_write_buffer(target, address, 4, last_word);
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;