cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412 Internal Flash Write is not working

Rajesh Kannan
Associate II

Hi ,

I am preparing flash the binary using the USB in STM32L412.

I checked STM32 USB DFU code. It is working only read. I couldn't write in the STMDFU application.

I tried to write to flash ,But i am getting HAL_ERROR and read the FLASH SR register shows 0xA8 ( Programming error)

Please help for flash write from bootloader code.

Please check below API for testing flash.

 

 

uint16_t MEM_Write_Flash_64(uint32_t address, uint8_t *dest)
{
  /* USER CODE BEGIN 3 */
uint32_t i = 0;
uint64_t WrBuffer64;
uint8_t WrBuffer16[8];
address = 0x0800C000;

/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
//WrBuffer16[0] = (uint16_t)(dest[index]);
//WrBuffer16[1] = (uint16_t)(internalBuffer[index+1]);
//WrBuffer16[2] = (uint16_t)(internalBuffer[index+2]);
//WrBuffer16[3] = (uint16_t)(internalBuffer[index+3]);
  HAL_FLASH_Unlock();
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
//WrBuffer64 = (uint64_t)(((dest[7])<<56) | ((dest[6])<<48) | ((dest[5])<<40) |((dest[4])<<32) |((dest[3])<<24) |((dest[2])<<16) |((dest[1])<<8) | dest[0]);
WrBuffer64 = A1A2A3A4A5A6A7A8;
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, WrBuffer64) == HAL_OK)
{
//address = address + 8;
}

return 1;
}

 

 

 

1 REPLY 1

The address needs to be on an 8-byte boundary, and the FLASH memory you are writing too needs to have been erased. You can't rewrite to the same address more than once without erasing it first.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..