Skip to content

Commit

Permalink
Merge pull request #442 from bitdump/bug-fix-stm32f030-erase-error
Browse files Browse the repository at this point in the history
Fix an erase error in stm32f030 device.
  • Loading branch information
texane authored Jun 25, 2016
2 parents 4341d63 + c61f160 commit 96554d9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,29 @@ static void __attribute__((unused)) clear_flash_cr_per(stlink_t *sl) {
}

static void set_flash_cr_mer(stlink_t *sl) {
uint32_t val, cr_reg, cr_mer;
uint32_t val, cr_reg, cr_mer, cr_pg;

if (sl->flash_type == STLINK_FLASH_TYPE_F4) {
cr_reg = FLASH_F4_CR;
cr_mer = 1 << FLASH_CR_MER;
cr_pg = 1 << FLASH_CR_PG;
} else if (sl->flash_type == STLINK_FLASH_TYPE_L4) {
cr_reg = STM32L4_FLASH_CR;
cr_mer = (1 << STM32L4_FLASH_CR_MER1) | (1 << STM32L4_FLASH_CR_MER2);
cr_pg = 1 << STM32L4_FLASH_CR_PG;
} else {
cr_reg = FLASH_CR;
cr_mer = 1 << FLASH_CR_MER;
cr_pg = 1 << FLASH_CR_PG;
}

stlink_read_debug32(sl, cr_reg, &val);
if (val & cr_pg) {
/* STM32F030 will drop MER bit if PG was set */
val &= ~cr_pg;
stlink_write_debug32(sl, cr_reg, val);
}

val |= cr_mer;
stlink_write_debug32(sl, cr_reg, val);
}
Expand Down

0 comments on commit 96554d9

Please sign in to comment.