From e8fd493f414afd2f03ee1a117d3b508ccd714412 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 16 Jun 2022 18:58:10 +0200 Subject: [PATCH] cpu/sam0_common: mtd_sdhc: ensure source address alignment The source / destination address of the SDHC transfer needs to be word-aligned. Use the mtd buffer to fix the alignment if `mtd_write_page` is used, otherwise return -ENOTSUP. --- cpu/sam0_common/sam0_sdhc/mtd_sdhc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/sam0_common/sam0_sdhc/mtd_sdhc.c b/cpu/sam0_common/sam0_sdhc/mtd_sdhc.c index 0a58e495ac..591301ca85 100644 --- a/cpu/sam0_common/sam0_sdhc/mtd_sdhc.c +++ b/cpu/sam0_common/sam0_sdhc/mtd_sdhc.c @@ -69,7 +69,7 @@ static int _read_page(mtd_dev_t *dev, void *buff, uint32_t page, DEBUG("%s(%lu, %lu, %lu)\n", __func__, page, offset, size); /* emulate unaligned / sub-page read */ - if (pages == 0 || offset) { + if (pages == 0 || offset || ((uintptr_t)buff & 0x3)) { #if IS_USED(MODULE_MTD_WRITE_PAGE) if (dev->work_area == NULL) { DEBUG("mtd_sdhc: no work area\n"); @@ -105,7 +105,7 @@ static int _write_page(mtd_dev_t *dev, const void *buff, uint32_t page, DEBUG("%s(%lu, %lu, %lu)\n", __func__, page, offset, size); /* emulate unaligned / sub-page write */ - if (pages == 0 || offset) { + if (pages == 0 || offset || ((uintptr_t)buff & 0x3)) { #if IS_USED(MODULE_MTD_WRITE_PAGE) if (dev->work_area == NULL) { DEBUG("mtd_sdhc: no work area\n");