2021-06-14 06:19 AM
I'm trying to write and read some data into flash. But not work. Anybody help me?
I'm using Cubeide and STM32F429 board.
char test_data[]="TEST";
char test_data2[5];
uint32_t PAGEError = 0;
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS ;
EraseInitStruct.Sector = FLASH_SECTOR_0;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, 0x08000020, test_data);
HAL_FLASH_Lock();
*test_data2 = *(__IO uint32_t *)0x08000020;
HAL_UART_Transmit(&huart1, (uint8_t *) test_data2, 5,500);
2021-06-14 06:30 AM
Your program probably resides in the same FLASH_SECTOR_0 which you are trying to erasing. Use a different sector.
JW