From 2ea4516a4a30cff5e361f3ecfac2c591ebd05ec4 Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Sat, 9 Jul 2022 12:00:20 +0200 Subject: [PATCH] drivers/flash: stm32g0: Prepare for unaligned accesses in flash writes When using the settings subsystem, the data argument argument passed to flash_stm32_write_range() might not be 8-bytes aligned, causing an unaligned memory access fault. Fix that the same way as it was done for the STM32L4 in commit 652efa530f13e1232350f8e19e78cb03f00fa991. Signed-off-by: Aurelien Jarno --- drivers/flash/flash_stm32g0x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/flash/flash_stm32g0x.c b/drivers/flash/flash_stm32g0x.c index 3486ddf4a2..51482fa290 100644 --- a/drivers/flash/flash_stm32g0x.c +++ b/drivers/flash/flash_stm32g0x.c @@ -194,7 +194,8 @@ int flash_stm32_write_range(const struct device *dev, unsigned int offset, int i, rc = 0; for (i = 0; i < len; i += 8, offset += 8) { - rc = write_dword(dev, offset, ((const uint64_t *) data)[i>>3]); + rc = write_dword(dev, offset, + UNALIGNED_GET((const uint64_t *) data + (i >> 3))); if (rc < 0) { return rc; }