Skip to content

Commit

Permalink
Add support for mass erasing second bank on STM32F10x_XL
Browse files Browse the repository at this point in the history
  • Loading branch information
bmellstrom authored and Björn Mellström committed Feb 7, 2019
1 parent 30de1b3 commit 5212937
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ static void set_flash_cr_mer(stlink_t *sl, bool v) {
stlink_write_debug32(sl, cr_reg, val);
}

static void set_flash_cr2_mer(stlink_t *sl, bool v) {
const uint32_t cr_pg = 1 << FLASH_CR_PER;
const uint32_t cr_mer = 1 << FLASH_CR_MER;
uint32_t val;

stlink_read_debug32(sl, FLASH_CR2, &val);
val &= ~cr_pg;
if (v)
val |= cr_mer;
else
val &= ~cr_mer;
stlink_write_debug32(sl, FLASH_CR2, val);
}

static void __attribute__((unused)) clear_flash_cr_mer(stlink_t *sl) {
uint32_t val, cr_reg, cr_mer;

Expand Down Expand Up @@ -1740,6 +1754,14 @@ int stlink_erase_flash_mass(stlink_t *sl) {
/* start erase operation, reset by hw with bsy bit */
set_flash_cr_strt(sl);

if (sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
/* set the mass erase bit in bank 2 */
set_flash_cr2_mer(sl,1);

/* start erase operation in bank 2 */
set_flash_cr2_strt(sl);
}

/* wait for completion */
wait_flash_busy_progress(sl);

Expand All @@ -1749,6 +1771,11 @@ int stlink_erase_flash_mass(stlink_t *sl) {
/* reset the mass erase bit */
set_flash_cr_mer(sl,0);

if (sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
/* reset the mass erase bit in bank 2 */
set_flash_cr2_mer(sl,0);
}

/* todo: verify the erased memory */
}
return 0;
Expand Down

0 comments on commit 5212937

Please sign in to comment.