Can someone tell me what stupid thing I am doing wrong or understanding? As a test, I am trying to write a simple number into flash and retrieve it. Once successful, I will expand this to 6 signed values. My device is an STM32L476RG
uint64_t data = 88;
Erase_Flash();
HAL_FLASH_Unlock();
Address = ADDR_FLASH_PAGE_256;
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, Address, data) != HAL_OK)
serprintf("Error writing flash.");
HAL_FLASH_Lock();
uint8_t *flash_biases = (uint8_t*) (ADDR_FLASH_PAGE_256);
Based on what I've read, I should be able to access the flash memory like I have. But it's not retrieving the value I expect.
The Erase_Flash() function looks like this:
void Erase_Flash() {
HAL_FLASH_Unlock();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_MASSERASE;
EraseInitStruct.Banks = FLASH_BANK_2;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) {
serprintf("Error erasing flash.");
}
HAL_FLASH_Lock();
}
Erase_Flash()
? IsAddress
of typeuint32_t
? What is the byte value atAddress
right before invokingHAL_FLASH_Program()
(should be 0xFF)? Is the flash sector read/write protected (check option bytes)? Is the flash sector really unused (check linker script)? – relFLASH_Program_DoubleWord()
orHAL_FLASH_Program()
withFLASH_TYPEPROGRAM_DOUBLEWORD
, check: github.com/STMicroelectronics/STM32CubeL4/blob/master/Drivers/… . In fast programming modeHAL_FLASH_Program()
interprets the third parameter as a pointer! Quite confusing. Fast programming is not available on all STM32 variants... See also:3.3.7 Flash main memory programming sequences
in the RM0351 Reference manual. – rel