Writing to flash bricks stm32G030 and stm32G031
If I create a program using stmcubeIDE and ADD the code below it bricks the processor . I gather in some way I am overwritting the bootloader that controls stlink and get the error
Target no device found
Error in initializing ST-LINK device.
Reason: No device found on target
Error in final launch sequence:
Failed to execute MI command:
target remote localhost:61234
Error message from debugger back end:
localhost:61234: Connection timed out.
Failed to execute MI command:
target remote localhost:61234
Error message from debugger back end:
localhost:61234: Connection timed out.
localhost:61234: Connection timed out.
/* USER CODE BEGIN 2 */
uint32_t address=0x8005800;
uint64_t data=0x0807060504030201DU;
HAL_FLASH_Unlock(); // Unlock the flash memory for write access
// Erase the page that contains the specified address
FLASH_EraseInitTypeDef erase_init;
erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
erase_init.Page = address & ~(FLASH_PAGE_SIZE - 1); // Round down to page boundary
erase_init.NbPages = 1;
uint32_t page_error;
HAL_FLASHEx_Erase(&erase_init, &page_error);
// Write the data to the specified address this is a 64bit number
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
HAL_FLASH_Lock();
/* USER CODE END 2 */
