AnsweredAssumed Answered

STM32L152 Flash Access

Question asked by TheMeerd on Aug 27, 2014
Latest reply on Aug 27, 2014 by Clive One
Hello Everyone,

I am working on an STM32L152 based platform and trying place some data inside internal flash. As you may know, when a page is erased, in stm32L1, each bit is set to 0x00 instead of 0xFF. After erasing a page, I am trying to set each bit of a flash word respectively. Here is my test code:


void *dest = (void *) 0x08030000;
uint32_t max = (uint32_t) ~0;
uint32_t value = 0;
 
HAL_FlashErase(dest, 1); /* STM32 Lib Function Wrapper */
 
while (value < max) {
  value = (value << 1) | 1;
  HAL_FlashWriteWord(dest, value); /* Yet another wrapper function */
  printf("value: %u | flash: %u\n", value , *(volatile uint32_t *) dest);
}

When I have a look at the output, always I see inconsistent/incorrect values. Here is the short part of the output:

value: 1 | flash: 1
value: 3 | flash: 3
value: 7 | flash: 15 /* Not same */
value: 15 | flash: 15
value: 31 | flash: 31
value: 63 | flash: 127 /* Not same again */

What could be the underlying reason for this? 

Thanks in advance.

Outcomes