cancel
Showing results for 
Search instead for 
Did you mean: 

Can not write data in flash of STM32G030C8T6

Pzhu.1
Associate II

This is my code;it when run to the code in the picture, the MCU will deadvoid Flash_Test(void)

{

  U32  Write_Addr = FLASH_USER_START_ADDR; //FLASH_USER_START_ADDR=((uint32_t)0x0800E000)

  uint64_t data64=0x1234567812345678;

  EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;

  EraseInitStruct.Page = FLASH_USER_START_ADDR;

  EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;

  HAL_FLASH_Unlock();

   if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)

   {

     //HAL_FLASH_Lock();

     // return 0;----

   }

   HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Write_Addr, data64);

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

>  EraseInitStruct.Page = FLASH_USER_START_ADDR;

Pretty sure page should be an integer between 0 and the number of pages, not an address.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

>  EraseInitStruct.Page = FLASH_USER_START_ADDR;

Pretty sure page should be an integer between 0 and the number of pages, not an address.

If you feel a post has answered your question, please click "Accept as Solution".
Pzhu.1
Associate II

Thanks very much!!!​