cancel
Showing results for 
Search instead for 
Did you mean: 

HAL EEPROM Driver on STM32L151xB

sschocke
Associate
Posted on December 01, 2015 at 08:41

While trying to use the HAL drivers to access the EEPROM section of the FLASH memory, I have come across a very weird issue

When trying to program a zero(0) to an address, the HAL driver follows a special code path only on these specific part numbers. I can't for the life of me understand why it would be this way, as I can't imagine it would be faster... and on top of that, it doesn't work properly. Here is the offending code from the FLASH_DATAEEPROM_ProgramByte function:

#if defined(STM32L100xB) || defined(STM32L151xB) || defined(STM32L152xB)
if
(Data != (uint8_t) 0x00)
{ 
*(__IO uint8_t *)Address = Data;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
}
else
{
tmpaddr = Address & 0xFFFFFFFC;
tmp = * (__IO uint32_t *) tmpaddr;
tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));
tmp &= ~tmpaddr; 
status = HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEERASEDATA_WORD, Address & 0xFFFFFFFC);
status = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_FASTWORD, (Address & 0xFFFFFFFC), tmp);
}
#else /* Not Cat1*/
*(__IO uint8_t *)Address = Data;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
#endif /* STM32L100xB || STM32L151xB || STM32L152xB */

If I execute the following code, both the bytes are zero(0) after programming:

HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, 0x08080000, 3);
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, 0x08080001, 0);

If I execute this code, it works as expected:

HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, 0x08080000, 3);
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, 0x08080001, 1);

I hope someone can explain to me why the special code path is in there... Regards, Sebastian #eeprom #bug #stm32cube
0 REPLIES 0