2016-04-20 01:40 PM
Hello everyone,
I'm developing a code in STM32F407VG. this code will erase the flash memory in a first step, and for a further work will upload a code into this memory.
this is my code for erasing the flash memory.
//unlocking the flash memoryif((FLASH->CR & 0x80000000) != 0x0) { FLASH->KEYR = 0x45670123; FLASH->KEYR = 0xCDEF89AB; }//clear the flagsFLASH->SR |= (0x80 | 0x40 | 0x20 | 0x2);// erase all pagesFLASH->CR |= 0x4 | 0x8000;FLASH->CR |= 0x10000; /* Disable the MER Bit */FLASH->CR &= ~(0x4 | 0x8000);// writing//locking flashFLASH_CR |= 0x80000000;
Please, give me where am I wrong.
(I should work directly with registers)
Thank you and Best Regards.2016-04-21 05:43 AM
Hi,
You can refer to this example which describes how to configure and use the FLASH HAL API to erase and program the internal FLASH memory:STM32Cube_FW_F4_V1.11.0\Projects\STM324xG_EVAL\Examples\FLASH\FLASH_EraseProgramIf you are using Standard Peripherals Library, you can found this example in STM32F4xx_DSP_StdPeriph_Lib_V1.6.1 :STM32F4xx_DSP_StdPeriph_Lib_V1.6.1\Project\STM32F4xx_StdPeriph_Examples\FLASHIt may be helpful for you to program the FLASH memory integrated.Regards