2022-01-18 12:34 AM
Hello,
I've created a custom PCB with a STM32F207 controller on it. With this board I want to address different targets using SWD. My targets are a STM32F407 and a STM32L431 controller. I implemented a custom SWD interface with Timer and DMA on my F207 controller and now I'm able to talk with my targets over their built-in SWD interface. For example I can read the UniqueID of the targets or write into the flash of them.
But I've got a problem with the mass erase of the flash. With the F407 the flash mass erase work fine. It took about 8 sec and then the hole flash is empty. But on the L431 it wont work.
Writing into the empty flash of the L431 works fine.
I take the following steps to perform a mass erase of the flash:
On the F407 this routine works fine. After setting the STRT bit it took about 8 sec. until the BSY flag is cleared. With the L431 on the other hand, mass erase should take only 22 ms (according to a presentation by ST). But it doesn't work at all.
Also the PGSERR bit is set in the FLASH_SR register on the L431. I don't understand the bit in this context, because I don't want to write, I want to delete.
Any ideas?
Thank you
Solved! Go to Solution.
2022-01-18 05:08 AM
Kind of, yes.
I've found my mistake. The PG bit in the FLASH_CR register was set. For the F407 this was not a problem, but the L431 had a problem with it. Wenn the PG bit is cleared, mass erase works as expected. Thank you!
2022-01-18 02:34 AM
Does your code look similar to:
stm32l4_flash_unlock(t);
/* Erase time is 25 ms. No need for a spinner.*/
/* Flash erase action start instruction */
stm32l4_flash_write32(t, FLASH_CR, action);
stm32l4_flash_write32(t, FLASH_CR, action | FLASH_CR_STRT);
/* Read FLASH_SR to poll for BSY bit */
while (stm32l4_flash_read32(t, FLASH_SR) & FLASH_SR_BSY) {
if(target_check_error(t)) {
return false;
}
}
/* Check for error */
uint16_t sr = stm32l4_flash_read32(t, FLASH_SR);
if (sr & FLASH_SR_ERROR_MASK)
return false;
return true;
I have not heard of problems with that code.
2022-01-18 05:08 AM
Kind of, yes.
I've found my mistake. The PG bit in the FLASH_CR register was set. For the F407 this was not a problem, but the L431 had a problem with it. Wenn the PG bit is cleared, mass erase works as expected. Thank you!