AnsweredAssumed Answered

STM32 HAL_FLASH_Program() not working as expected

Question asked by Adam Dibin on Jan 30, 2018
Latest reply on Jan 30, 2018 by Doug Kehn

I'm trying to program FLASH using HAL_FLASH_Program() function. Precisely speaking, I've written a function which is expected to write two measurements to flash at a set time interval (e.g. 3 seconds). However, when called, the function manages to write only the first one while ignoring the second one. Can't HAL_FLASH_Program be used twice? What am I doing wrong? I just want to mention that I'm utterly new to STM32 programming, so any helpful suggestions would be much appreciated. Here is the code:


void writeFlash() {
mem = returnPointerToFirstEmptyAddressInSector(); Address = (uint32_t)mem; var1.f = Temperature; var2.f = SD; HAL_FLASH_Unlock(); __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR);  HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, var1.i );  Address++;   HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, var2.i);    HAL_FLASH_Lock();