Why does data get corrupted while reading from internal flash memory of STM32 Blue-Pill

399 Views Asked by At

I am writing and reading from internal flash memory of STM32 Blue Pill. Writing is successfully done. but while reading data, only specific bytes of data get corrupted.

Code block for reading data from flash memory:

uint8_t *Read_Buffer;
uint16_t Read_Size = 8192;
uint32_t Internal_Flash_Address = 0x0800C000;
Read_Buffer = (uint8_t *) malloc(Read_Size * sizeof(uint8_t));

for(uint16_t j=0; j<Read_Size; j++){
    Read_Buffer[j] = *(__IO uint8_t *)Internal_Flash_Address;
    Internal_Flash_Address++;
}
while(CDC_Transmit_FS(Read_Buffer, Read_Size) != USBD_OK){};
free(Read_Buffer);

Data I write:
enter image description here

Data read back, memory locations marked with yellow are wrongly received data:
enter image description here

Although, the data is written accurately in the memory which I can confirm by checking the memory in STMCubeProgrammer:
enter image description here I doubt this is data corruption because when reading 8KB of flash only 156-Bytes are corrupted, and every time this exact memory locations are causing problem while reading back, but memory still holds proper data as per STM32CubeProgrammer.

What can be other reasons for such data corruption while reading back data using pointers pointing at memory locations in the memory?

0

There are 0 best solutions below