title: STM32 - writing and reading flash
body: <p>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</p>
  <pre><code>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(&quot;Error writing flash.&quot;);
  
  HAL_FLASH_Lock();
  uint8_t *flash_biases = (uint8_t*) (ADDR_FLASH_PAGE_256);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/lQMb1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lQMb1.png" alt="enter image description here" /></a></p>
  <p>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.</p>
  <p>The Erase_Flash() function looks like this:</p>
  <pre><code>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(&amp;EraseInitStruct, &amp;PAGEError) != HAL_OK) {
          serprintf(&quot;Error erasing flash.&quot;);
      }
      HAL_FLASH_Lock();
  }
  </code></pre>