aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Head <chead@zaber.com>2020-01-03 14:49:16 -0800
committerTomas Vanek <vanekt@fbl.cz>2020-02-23 12:38:38 +0000
commita6dacdff58ef36fcdac00c53ec27f19de1fbce0d (patch)
tree5915b1cc0f15b0fd354a4d07897e493304954112
parent2a60ae7fee192db54240e5929d6434c0eb3e190d (diff)
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 <chead@zaber.com> Reviewed-on: http://openocd.zylin.com/5388 Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
-rw-r--r--src/flash/nor/stm32h7x.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c
index 152a154b..bf003684 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)