Skip to content

Commit

Permalink
stm32wb0: Implemented mass erase
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed Sep 4, 2024
1 parent 533dbc8 commit 47bcd96
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/target/stm32wb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
static bool stm32wb0_enter_flash_mode(target_s *target);
static bool stm32wb0_flash_erase(target_flash_s *flash, target_addr_t addr, size_t len);
static bool stm32wb0_flash_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t len);
static bool stm32wb0_mass_erase(target_s *target);

static void stm32wb0_add_flash(target_s *const target, const size_t length)
{
Expand Down Expand Up @@ -129,6 +130,7 @@ bool stm32wb0_probe(target_s *const target)
target_mem32_write16(target, STM32WB0_PWRC_DBGR, STM32WB0_PWRC_DBGR_DEEPSTOP2);

target->driver = "STM32WB0";
target->mass_erase = stm32wb0_mass_erase;
target->enter_flash_mode = stm32wb0_enter_flash_mode;

const uint32_t signature = target_mem32_read32(target, STM32WB0_FLASH_FLASH_SIZE);
Expand Down Expand Up @@ -205,3 +207,17 @@ static bool stm32wb0_flash_write(
}
return true;
}

static bool stm32wb0_mass_erase(target_s *const target)
{
/* To start the mass erase, prep the controller */
if (!stm32wb0_enter_flash_mode(target))
return false;

platform_timeout_s timeout;
platform_timeout_set(&timeout, 500U);
/* Set up and run the mass erase */
target_mem32_write32(target, STM32WB0_FLASH_COMMAND, STM32WB0_FLASH_COMMAND_MASS_ERASE);
/* Then wait for the erase to complete and report any errors */
return stm32wb0_flash_wait_complete(target, &timeout);
}

0 comments on commit 47bcd96

Please sign in to comment.