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>
This commit is contained in:
parent
2a60ae7fee
commit
a6dacdff58
|
@ -170,6 +170,9 @@ FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command)
|
||||||
stm32x_info->probed = 0;
|
stm32x_info->probed = 0;
|
||||||
stm32x_info->user_bank_size = bank->size;
|
stm32x_info->user_bank_size = bank->size;
|
||||||
|
|
||||||
|
bank->write_start_alignment = FLASH_BLOCK_SIZE;
|
||||||
|
bank->write_end_alignment = FLASH_BLOCK_SIZE;
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,17 +613,17 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
|
||||||
return ERROR_TARGET_NOT_HALTED;
|
return ERROR_TARGET_NOT_HALTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset % FLASH_BLOCK_SIZE) {
|
/* should be enforced via bank->write_start_alignment */
|
||||||
LOG_WARNING("offset 0x%" PRIx32 " breaks required 32-byte alignment", offset);
|
assert(!(offset % FLASH_BLOCK_SIZE));
|
||||||
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
|
|
||||||
}
|
/* should be enforced via bank->write_end_alignment */
|
||||||
|
assert(!(count % FLASH_BLOCK_SIZE));
|
||||||
|
|
||||||
retval = stm32x_unlock_reg(bank);
|
retval = stm32x_unlock_reg(bank);
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
goto flash_lock;
|
goto flash_lock;
|
||||||
|
|
||||||
uint32_t blocks_remaining = count / FLASH_BLOCK_SIZE;
|
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 */
|
/* multiple words (32-bytes) to be programmed in block */
|
||||||
if (blocks_remaining) {
|
if (blocks_remaining) {
|
||||||
|
@ -667,25 +670,6 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
|
||||||
blocks_remaining--;
|
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:
|
flash_lock:
|
||||||
retval2 = stm32x_lock_reg(bank);
|
retval2 = stm32x_lock_reg(bank);
|
||||||
if (retval2 != ERROR_OK)
|
if (retval2 != ERROR_OK)
|
||||||
|
|
Loading…
Reference in New Issue