2023-04-10 07:52 PM
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 */
2023-04-10 08:53 PM
Perhaps check error codes?
This is WRONG
erase_init.Page = address & ~(FLASH_PAGE_SIZE - 1); // Round down to page boundary
2023-04-12 10:04 PM
Further it now get what looks like a stack overflow
Break at address "0xfffffffe" with no debug information available, or outside of program code.
No source available for "<signal handler called>() at 0xfffffff1"
Break at address "0xfffffffe" with no debug information available, or outside of program code.
No source available for "<signal handler called>() at 0xfffffff9"
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE); Line 197 in stm32g0xx_hal_flash_ex.c
this is called by
if (HAL_FLASHEx_Erase(&erase_init, &PAGEError) != HAL_OK)
{
/*Error occurred while page erase.*/
return HAL_FLASH_GetError();
}
the compete code is which is added to a fresh project created by codeMX
/* USER CODE BEGIN 2 */
uint32_t address=0x08005800;
uint64_t data=0x08070605040302010;
HAL_FLASH_Unlock(); // Unlock the flash memory for write access
// Erase the page that contains the specified address
FLASH_EraseInitTypeDef erase_init;
for (int indx=0; indx<128; indx++)
{
if((address < (0x08000000 + (FLASH_PAGE_SIZE *(indx+1))) ) && (address >= (0x08000000 + FLASH_PAGE_SIZE*indx)))
{
erase_init.Page=0x08000000 + FLASH_PAGE_SIZE*indx;
}
}
erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
//erase_init.Page = address & ~(FLASH_PAGE_SIZE - 1); // Round down to page boundary
erase_init.Banks=FLASH_BANK_1;
erase_init.NbPages = 1;
uint32_t PAGEError;
if (HAL_FLASHEx_Erase(&erase_init, &PAGEError) != HAL_OK)
{
/*Error occurred while page erase.*/
return HAL_FLASH_GetError();
}
// Write the data to the specified address this is a 64bit number
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
HAL_FLASH_Lock();
//uint64_t dataout= *(__IO float *)address;
/* USER CODE END 2 */
2023-04-12 10:26 PM
Page isn't an address
Surely
erase_init.Page = address / FLASH_PAGE_SIZE;