From becfb8ae06f4cc97ff1314b1a8a823567bc64796 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 9 Oct 2022 12:37:59 +0000 Subject: [PATCH] Fixed bug #1238. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15814 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c | 42 ++++++++++---------- os/hal/ports/STM32/LLD/SDMMCv2/hal_sdc_lld.c | 42 ++++++++++---------- readme.txt | 1 + 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c b/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c index 12c20d9db..4e70bcc26 100644 --- a/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c +++ b/os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c @@ -906,21 +906,20 @@ bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t blocks) { #if STM32_SDC_SDMMC_UNALIGNED_SUPPORT - if (((unsigned)buf & 3) != 0) { - uint32_t i; - for (i = 0; i < blocks; i++) { - if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1)) - return HAL_FAILED; - memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE); - buf += MMCSD_BLOCK_SIZE; - startblk++; - } - return HAL_SUCCESS; + uint32_t i; + for (i = 0; i < blocks; i++) { + if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1)) + return HAL_FAILED; + memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE); + buf += MMCSD_BLOCK_SIZE; + startblk++; } + return HAL_SUCCESS; #else /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ osalDbgAssert((((unsigned)buf & 3) == 0), "unaligned buffer"); -#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ + return sdc_lld_read_aligned(sdcp, startblk, buf, blocks); +#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ } /** @@ -941,21 +940,20 @@ bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t blocks) { #if STM32_SDC_SDMMC_UNALIGNED_SUPPORT - if (((unsigned)buf & 3) != 0) { - uint32_t i; - for (i = 0; i < blocks; i++) { - memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE); - buf += MMCSD_BLOCK_SIZE; - if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1)) - return HAL_FAILED; - startblk++; - } - return HAL_SUCCESS; + uint32_t i; + for (i = 0; i < blocks; i++) { + memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE); + buf += MMCSD_BLOCK_SIZE; + if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1)) + return HAL_FAILED; + startblk++; } + return HAL_SUCCESS; #else /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ osalDbgAssert((((unsigned)buf & 3) == 0), "unaligned buffer"); -#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ + return sdc_lld_write_aligned(sdcp, startblk, buf, blocks); +#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ } /** diff --git a/os/hal/ports/STM32/LLD/SDMMCv2/hal_sdc_lld.c b/os/hal/ports/STM32/LLD/SDMMCv2/hal_sdc_lld.c index a8204badf..4d4b50f8b 100644 --- a/os/hal/ports/STM32/LLD/SDMMCv2/hal_sdc_lld.c +++ b/os/hal/ports/STM32/LLD/SDMMCv2/hal_sdc_lld.c @@ -785,21 +785,20 @@ bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t blocks) { #if STM32_SDC_SDMMC_UNALIGNED_SUPPORT - if (((unsigned)buf & 3) != 0) { - uint32_t i; - for (i = 0; i < blocks; i++) { - if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1)) - return HAL_FAILED; - memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE); - buf += MMCSD_BLOCK_SIZE; - startblk++; - } - return HAL_SUCCESS; + uint32_t i; + for (i = 0; i < blocks; i++) { + if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1)) + return HAL_FAILED; + memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE); + buf += MMCSD_BLOCK_SIZE; + startblk++; } + return HAL_SUCCESS; #else /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ osalDbgAssert((((unsigned)buf & 3) == 0), "unaligned buffer"); -#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ + return sdc_lld_read_aligned(sdcp, startblk, buf, blocks); +#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ } /** @@ -820,21 +819,20 @@ bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t blocks) { #if STM32_SDC_SDMMC_UNALIGNED_SUPPORT - if (((unsigned)buf & 3) != 0) { - uint32_t i; - for (i = 0; i < blocks; i++) { - memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE); - buf += MMCSD_BLOCK_SIZE; - if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1)) - return HAL_FAILED; - startblk++; - } - return HAL_SUCCESS; + uint32_t i; + for (i = 0; i < blocks; i++) { + memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE); + buf += MMCSD_BLOCK_SIZE; + if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1)) + return HAL_FAILED; + startblk++; } + return HAL_SUCCESS; #else /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ osalDbgAssert((((unsigned)buf & 3) == 0), "unaligned buffer"); -#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ + return sdc_lld_write_aligned(sdcp, startblk, buf, blocks); +#endif /* !STM32_SDC_SDIO_UNALIGNED_SUPPORT */ } /** diff --git a/readme.txt b/readme.txt index 585e731bc..025d4f4bb 100644 --- a/readme.txt +++ b/readme.txt @@ -127,6 +127,7 @@ - NEW: Increased stacks size in RT test suite from 128 to 192. added an option to override the stack size by defining THREADS_STACK_SIZE in the makefile. +- FIX: Fixed problems with cache in STM32 SDMMC drivers (bug #1238)(***********TODO*********** backported to 21.11.3). - FIX: Fixed missing clock enables for some GPIOS on some STM32L4s (bug #1237) (backported to 20.3.5)(backported to 21.11.3). - FIX: Fixed old bugs in serial driver header (bug #1236)