From a6dacdff58ef36fcdac00c53ec27f19de1fbce0d Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Fri, 3 Jan 2020 14:49:16 -0800 Subject: [PATCH] flash/stm32h7x: use alignment infrastructure Report the 32-byte alignemnt requirement via the bank structure rather than enforcing it ad-hoc in the write routine. This allows people to do non-32-byte-aligned writes if they want, with the infrastructure fixing up the addresses passed to the low-level driver. Change-Id: I2c4f532f2000435954a900224dbc9f2c30d1cc94 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5388 Reviewed-by: Tarek BOCHKATI Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/stm32h7x.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 152a154bd0..bf003684cb 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -170,6 +170,9 @@ FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command) stm32x_info->probed = 0; stm32x_info->user_bank_size = bank->size; + bank->write_start_alignment = FLASH_BLOCK_SIZE; + bank->write_end_alignment = FLASH_BLOCK_SIZE; + return ERROR_OK; } @@ -610,17 +613,17 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, return ERROR_TARGET_NOT_HALTED; } - if (offset % FLASH_BLOCK_SIZE) { - LOG_WARNING("offset 0x%" PRIx32 " breaks required 32-byte alignment", offset); - return ERROR_FLASH_DST_BREAKS_ALIGNMENT; - } + /* should be enforced via bank->write_start_alignment */ + assert(!(offset % FLASH_BLOCK_SIZE)); + + /* should be enforced via bank->write_end_alignment */ + assert(!(count % FLASH_BLOCK_SIZE)); retval = stm32x_unlock_reg(bank); if (retval != ERROR_OK) goto flash_lock; uint32_t blocks_remaining = count / FLASH_BLOCK_SIZE; - uint32_t bytes_remaining = count % FLASH_BLOCK_SIZE; /* multiple words (32-bytes) to be programmed in block */ if (blocks_remaining) { @@ -667,25 +670,6 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, blocks_remaining--; } - if (bytes_remaining) { - retval = stm32x_write_flash_reg(bank, FLASH_CR, FLASH_PG | FLASH_PSIZE_64); - if (retval != ERROR_OK) - goto flash_lock; - - retval = target_write_buffer(target, address, bytes_remaining, buffer); - if (retval != ERROR_OK) - goto flash_lock; - - /* Force Write buffer of FLASH_BLOCK_SIZE = 32 bytes */ - retval = stm32x_write_flash_reg(bank, FLASH_CR, FLASH_PG | FLASH_PSIZE_64 | FLASH_FW); - if (retval != ERROR_OK) - goto flash_lock; - - retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT); - if (retval != ERROR_OK) - goto flash_lock; - } - flash_lock: retval2 = stm32x_lock_reg(bank); if (retval2 != ERROR_OK) -- 2.30.2