Forced to mass erase after successfully programming flash on STM32F401RE
Hello,
I am trying program the flash memory on an STM32f401RE.
After successfully programming sector 7 I cannot flash a new application to my board, instead I am met with :

Error: ST-LINK error (DEV_TARGET_NOT_HALTED)
I can flash new code after a mass erase with cube programmer but this shouldn't be necessary.


Here is the code I am using.
FLASH_EraseInitTypeDef erase_op;
erase_op.TypeErase = FLASH_TYPEERASE_SECTORS;
erase_op.Sector = FLASH_SECTOR_7;
erase_op.NbSectors = 1;
erase_op.VoltageRange = FLASH_VOLTAGE_RANGE_3;
uint32_t err;
if(HAL_FLASH_Unlock() == HAL_OK)
printf("Unlocked flash!\r\n");
if(HAL_FLASHEx_Erase(&erase_op, &err) == HAL_OK)
printf("Erased memory!\r\n");
char str[] = "Hell";
uint64_t data = 0;
memcpy(&data, str, 4);
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, 0x08060000, data) == HAL_OK)
printf("Flash programming was successful!\r\n");
printf("Flash error : %lu\r\n", HAL_FLASH_GetError());
if(HAL_FLASH_Lock() == HAL_OK)
printf("Locked flash!\r\n");
Here is the layout in memory of my application :

Like I said, there isn't anything here that be affected with me erasing sector 7.
I've already written to flash on a STM32L031K6 and had no issues, I'm not sure what I'm doing wrong on this one.
Thank you.
