STM32L431 mass erase over SWD not working
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:
- Unlock the write access to the flash register (works, because the LOCK bit is not set anymore and I can write to the flash).
- Then I check if the BSY bit in the flash status register is set. When it's set, I wait until it's cleared.
- Then I'm clearing the ICEN and DCEN bits in the FLASH_ACR register. This is not mentioned in the reference manual, but ST is doing this in the HAL functions. But it makes no difference whether I delete the bits or not, deleting the flash does not work in either case.
- Now im clearing every error bit in the flash status register
- Setting the MER1 bit in the flash control register (and then read out the flash control register to check whether the bit has been set)
- And finally set the STRT bit in the FLASH_CR register
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