Skip to content

Commit

Permalink
hc32l110: set pc outside of flash range before flashing
Browse files Browse the repository at this point in the history
  • Loading branch information
vesim987 committed Sep 15, 2022
1 parent ae6fdcc commit d78d032
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/target/hc32l110.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

0 comments on commit d78d032

Please sign in to comment.