2020-09-17 03:14 AM
Hello! I'm using the STM32F767ZI Nucleo board. I'm trying to test an IAP using LwIP. Since I can only get LwIP working in a FreeRTOS environment., that's what I'm using, I have the following code which I cannot get to even do a simple mass write of FF's in the Flash area..
/* init flash */
FLASH_If_Init();
/* erase user flash area */
FLASH_If_Erase(0x8020000);
temp_address = 0x8020000;
for(int j = 0; j < len; j++)
{
ret_cnt += HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, temp_address, 0XFF);
temp_address += 4;
}
temp_address = 0x8020000;
for(int j = 0; j < count; j++)
{
ret_cnt += HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, temp_address, 0XFFFFFFFF);
temp_address += 4;
}
Count is 200, len is 800. Nothing is being written to the memory area. But the value of the call always return 0. As you can see I'm attempting the same write twice. But it does not change any memory.
Any ideas?
Thanks
2020-09-17 12:43 PM
The value of the flash after erase is 0xFF. Ensure the flash is actually being erased by FLASH_If_Erase before you write to it. Check write protection. See if FLASH_If_Erase returns a success/failure value. Step through the code.
Note that writing 0xFF to flash will never have an effect, since bits can only be changed from 0 to 1 by an erase.
2020-09-17 12:50 PM
You only get to write once.
You will need to unlock Flash
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
...
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
{
Address = Address + 4;
}
...
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
See also
STM32Cube_FW_F7_V1.16.0\Projects\STM32F767ZI-Nucleo\Examples\FLASH\FLASH_EraseProgram\Src\main.c
2020-09-18 04:03 AM
So yesterday I played further and eventually I received a DEV_TARGET_NOT_HALTED error. Then when I googled I saw that it helps to do a mass erase with the STM32CubeProgrammer which I did.
Somehow things started to work since then. The Flash area now is correctly written. I'm having program execution problems but I'll ask about that in a different question.
Thanks