From f81fbab9f00cf5c01975a8bbc53a037a705f1d0b Mon Sep 17 00:00:00 2001 From: Leszek Rusinowicz Date: Tue, 16 Apr 2019 11:20:11 +0200 Subject: [PATCH] FUTURE_SEQUANA: Fix flash_api bug introduced with e16d2d81d9 PDL Flash API requires that the data buffer is 32-bit aligned, otherwise programming can hung. Buffer declared as uint8_t array is not always properly aligned, e.g. with gcc 6 when -Os option is used. --- targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c b/targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c index f4726dbbba..0e3e2f206c 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/flash_api.c @@ -48,7 +48,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, { (void)(obj); int32_t status = 0; - static uint8_t prog_buf[CY_FLASH_SIZEOF_ROW]; + static uint32_t prog_buf[CY_FLASH_SIZEOF_ROW / sizeof(uint32_t)]; while (size) { uint32_t offset = address % CY_FLASH_SIZEOF_ROW; uint32_t chunk_size; @@ -59,7 +59,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, } uint32_t row_address = address / CY_FLASH_SIZEOF_ROW * CY_FLASH_SIZEOF_ROW; memcpy(prog_buf, (const void *)row_address, CY_FLASH_SIZEOF_ROW); - memcpy(prog_buf + offset, data, chunk_size); + memcpy((uint8_t *)prog_buf + offset, data, chunk_size); if (Cy_Flash_ProgramRow(row_address, (const uint32_t *)prog_buf) != CY_FLASH_DRV_SUCCESS) { status = -1;