diff --git a/src/target/hc32l110.c b/src/target/hc32l110.c index aa9025808f1..7a6da03cf17 100644 --- a/src/target/hc32l110.c +++ b/src/target/hc32l110.c @@ -157,13 +157,24 @@ static void hc32l110_add_flash(target *t, uint32_t flash_size) f->blocksize = HC32L110_BLOCKSIZE; f->writesize = HC32L110_BLOCKSIZE; // TODO f->erased = 0xffU; + f->erase = hc32l110_flash_erase; f->write = hc32l110_flash_write; f->prepare = hc32l110_flash_prepare; f->done = hc32l110_flash_done; + target_add_flash(t, f); } +bool hc32l110_enter_flash_mode(target *t) +{ + // the MCU required to have PC outside of the flash region to unlock + // that one specific region + + uint32_t pc = 0xFFFFFFFE; + return t->reg_write(t, REG_PC, &pc, sizeof(pc)) == sizeof(pc); +} + bool hc32l110_probe(target *t) { uint32_t flash_size = target_mem_read32(t, HC32L110_ADDR_FLASH_SIZE); @@ -180,6 +191,8 @@ bool hc32l110_probe(target *t) default: return false; } + + t->enter_flash_mode = hc32l110_enter_flash_mode; hc32l110_add_flash(t, flash_size); return true; }