I need to take backup of my FLASH before writing the FIRMWARE to my STM32F411CEUx.
I have written a test program for reading initial 1024 bytes (1KB) of my bootloader program itself and writing to binary file in PC to check my program’s correctness.
Communication parameters:
BaudRate = 9600
Parity = NONE
Stop bit = 1
Flow control = NONE
Problem:
-
On comparing the binary files loaded in micro controller and this backup binary file, there is difference on BYTE 0x198 till 8 bytes (compared using STLINK Utility).
I checked the outputs of both the programs and they are printing identical. Below is the debug prints from both PC as well as STM32
PC TOOL output:
Address [00000188] : 0x 00 00 00 00
Address [0000018C] : 0x 00 00 00 00
Address [00000190] : 0x D1 0B 00 08
Address [00000194] : 0x D1 0B 00 08
Address [00000198] : 0x FF FF FF FF
Address [0000019C] : 0x FF FF FF FF
Address [000001A0] : 0x 10 B5 05 4C
Address [000001A4] : 0x 23 78 33 B9
Address [000001A8] : 0x 04 4B 13 B1
Address [000001AC] : 0x 04 48 AF F3
STM32 output:
Address [00000188] : 0x 00 00 00 00
Address [0000018C] : 0x 00 00 00 00
Address [00000190] : 0x D1 0B 00 08
Address [00000194] : 0x D1 0B 00 08
Address [00000198] : 0x FF FF FF FF
Address [0000019C] : 0x FF FF FF FF
Address [000001A0] : 0x 10 B5 05 4C
Address [000001A4] : 0x 23 78 33 B9
Address [000001A8] : 0x 04 4B 13 B1
Address [000001AC] : 0x 04 48 AF F3
Please help on where I am missing, Thank you 🙂
Attached code of program on PC side is attached here
Code on my STM32F411CEUx is as below:
bool BackupFlashApp()
{
int i=0;
unsigned int bytes_to_read=1024;
unsigned int dataindex=0;
unsigned char Tx_Buffer[bytes_to_read];
volatile uint32_t *memptr = (uint32_t *)(FLASH_BASE);
memset( Tx_Buffer, 0, bytes_to_read );
while(dataindex<bytes_to_read)
{
flashmem_data.data_word = *memptr++;
Tx_Buffer[i++] = flashmem_data.data_bytes[0];
Tx_Buffer[i++] = flashmem_data.data_bytes[1];
Tx_Buffer[i++] = flashmem_data.data_bytes[2];
Tx_Buffer[i++] = flashmem_data.data_bytes[3];
dataindex +=4;
}
print_m_buf(Tx_Buffer, bytes_to_read);
dataindex=0;
while ( dataindex <bytes_to_read)
{
while( !( USART1->SR & USART_SR_TXE) ) {}; //wait till transmit buffer is empty
USART1->DR = Tx_Buffer[dataindex];
dataindex +=1;
}
return true;
}