I am using STM32F407 development board and I am trying to do flash read write operation but I am facing problem to erase a sector but am not able to do that.
Hi All,
I am using STM32F407 development board and I am trying to do flash write operation but I am facing problem to erase a sector (I am using Sector no - 11 Block base addresses -0x080E 0000 - 0x080F FFFF size-128 Kbytes ) so that I can perform multiple write operations :
According to PM0059 Programming manual:
Sector Erase To erase a sector, follow the procedure below:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register
2. Set the SER bit and select the sector (out of the 12 sectors in the main memory block) you wish to erase (SNB) in the FLASH_CR register
3. Set the STRT bit in the FLASH_CR register
4. Wait for the BSY bit to be cleared
But, while performing step no 3 from above mention steps it causing an error while debugging
"cannot access target shutting down debugging section".
and its come out of debug session

I am using code generator by STM32cubeMX
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
{
uint32_t tmp_psize = 0U;
/* Check the parameters */
assert_param(IS_FLASH_SECTOR(Sector));
assert_param(IS_VOLTAGERANGE(VoltageRange));
if(VoltageRange == FLASH_VOLTAGE_RANGE_1)
{
tmp_psize = FLASH_PSIZE_BYTE;
}
else if(VoltageRange == FLASH_VOLTAGE_RANGE_2)
{
tmp_psize = FLASH_PSIZE_HALF_WORD;
}
else if(VoltageRange == FLASH_VOLTAGE_RANGE_3)
{
tmp_psize = FLASH_PSIZE_WORD;
}
else
{
tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
}
/* If the previous operation is completed, proceed to erase the sector */
CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
FLASH->CR |= tmp_psize;
CLEAR_BIT(FLASH->CR, FLASH_CR_SNB);
FLASH->CR |= FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos);
FLASH->CR |= FLASH_CR_STRT; // this line causing above error
}
I am using user defined header file for flash read write operation
resource : https://github.com/MYaqoobEmbedded/STM32-Tutorials/tree/master/Tutorial%2030%20-%20FLASH%20Memory
With all due respect your help is all I need,
Thanking you.
