From 468b756f8d81b638ef604ec9c52e321439b1e79f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 15 May 2022 18:48:50 -0400 Subject: [PATCH] stm32: Avoid alignment issues in flash_read_block() Use a regular memcpy() call to avoid issues with pointer alignment. Signed-off-by: Kevin O'Connor --- src/stm32/flash.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/stm32/flash.c b/src/stm32/flash.c index ef1ae4e..4896786 100644 --- a/src/stm32/flash.c +++ b/src/stm32/flash.c @@ -4,9 +4,10 @@ // // This file may be distributed under the terms of the GNU GPLv3 license. -#include "flash.h" -#include "autoconf.h" -#include "internal.h" +#include // memcpy +#include "autoconf.h" // CONFIG_MACH_STM32F103 +#include "flash.h" // flash_write_page +#include "internal.h" // FLASH uint32_t flash_get_page_size(void) @@ -72,8 +73,5 @@ flash_write_page(uint32_t page_address, uint16_t *data) void flash_read_block(uint32_t block_address, uint32_t *buffer) { - uint32_t* block_addr = (uint32_t*)block_address; - - for (uint8_t i = 0; i < CONFIG_BLOCK_SIZE / 4; i++) - buffer[i] = block_addr[i]; + memcpy(buffer, (void*)block_address, CONFIG_BLOCK_SIZE); }