stm32g0: Made the flash write routine a little more understandable
This commit is contained in:
parent
23cf81eb55
commit
d6c1d8a1cc
|
@ -407,7 +407,7 @@ static int stm32g0_flash_write(target_flash_s *f, target_addr dest, const void *
|
||||||
target *const t = f->t;
|
target *const t = f->t;
|
||||||
stm32g0_priv_s *ps = (stm32g0_priv_s *)t->target_storage;
|
stm32g0_priv_s *ps = (stm32g0_priv_s *)t->target_storage;
|
||||||
|
|
||||||
if ((dest >= (target_addr)FLASH_OTP_START) && !ps->irreversible_enabled) {
|
if (dest >= FLASH_OTP_START && !ps->irreversible_enabled) {
|
||||||
tc_printf(t, "Irreversible operations disabled\n");
|
tc_printf(t, "Irreversible operations disabled\n");
|
||||||
stm32g0_flash_op_finish(t);
|
stm32g0_flash_op_finish(t);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -418,25 +418,25 @@ static int stm32g0_flash_write(target_flash_s *f, target_addr dest, const void *
|
||||||
target_mem_write32(t, FLASH_CR, FLASH_CR_PG);
|
target_mem_write32(t, FLASH_CR, FLASH_CR_PG);
|
||||||
target_mem_write(t, dest, src, len);
|
target_mem_write(t, dest, src, len);
|
||||||
/* Wait for completion or an error */
|
/* Wait for completion or an error */
|
||||||
uint32_t flash_sr;
|
uint32_t status = FLASH_SR_BSY_MASK;
|
||||||
do {
|
while (status & FLASH_SR_BSY_MASK) {
|
||||||
flash_sr = target_mem_read32(t, FLASH_SR);
|
status = target_mem_read32(t, FLASH_SR);
|
||||||
if (target_check_error(t)) {
|
if (target_check_error(t)) {
|
||||||
DEBUG_WARN("stm32g0 flash write: comm error\n");
|
DEBUG_WARN("stm32g0 flash write: comm error\n");
|
||||||
stm32g0_flash_op_finish(t);
|
stm32g0_flash_op_finish(t);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} while (flash_sr & FLASH_SR_BSY_MASK);
|
}
|
||||||
|
|
||||||
if (flash_sr & FLASH_SR_ERROR_MASK) {
|
if (status & FLASH_SR_ERROR_MASK) {
|
||||||
DEBUG_WARN("stm32g0 flash write error: sr 0x%" PRIx32 "\n", flash_sr);
|
DEBUG_WARN("stm32g0 flash write error: sr 0x%" PRIx32 "\n", status);
|
||||||
stm32g0_flash_op_finish(t);
|
stm32g0_flash_op_finish(t);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((dest == (target_addr)FLASH_START) && target_mem_read32(t, FLASH_START) != 0xFFFFFFFF) {
|
|
||||||
uint32_t flash_acr = target_mem_read32(t, FLASH_ACR);
|
if (dest == FLASH_START && target_mem_read32(t, FLASH_START) != 0xFFFFFFFF) {
|
||||||
flash_acr &= ~(uint32_t)FLASH_ACR_EMPTY;
|
const uint32_t acr = target_mem_read32(t, FLASH_ACR) & ~FLASH_ACR_EMPTY;
|
||||||
target_mem_write32(t, FLASH_ACR, flash_acr);
|
target_mem_write32(t, FLASH_ACR, acr);
|
||||||
}
|
}
|
||||||
|
|
||||||
stm32g0_flash_op_finish(t);
|
stm32g0_flash_op_finish(t);
|
||||||
|
|
Loading…
Reference in New Issue