dat mismatch when reading .bin file in stm32 for FOTA
Hi, I want to implement FOTA in stm32, for that I am reading .bin file and send to the controller through UART. And Write that file to the flash memory,
All Ihave done this, but there mismatch data beetween .bin file data written on flash.
the reading and sending . bin file have done this using GCC compiler.
below the function code.
int main(int argc, char *argv[])
{
int comport;
int bdrate = 115200; /* 115200 baud */
char mode[]={'8','N','1',0}; /* *-bits, No parity, 1 stop bit */
char bin_name[1024];
int ex = 0;
FILE *Fptr = NULL;
do
{
if( argc <= 2 )
{
printf("Please feed the COM PORT number and the Application Image....!!!\n");
printf("Example: .\\etx_ota_app.exe 8 ..\\..\\Application\\Debug\\Blinky.bin");
ex = -1;
break;
}
//get the COM port Number
comport = atoi(argv[1]) -1;
strcpy(bin_name, argv[2]);
// ex = sizeof(ETX_OTA_HEADER_);
// printf("Opening COM%d...\n", ex );
printf("Opening COM%d...\n", comport+1 );
if( RS232_OpenComport(comport, bdrate, mode, 0) )
{
printf("Can not open comport\n");
ex = -1;
break;
}
//send OTA Start command
ex = send_ota_start(comport);
if( ex < 0 )
{
printf("send_ota_start Err\n");
break;
}
printf("Opening Binary file : %s\n", bin_name);
Fptr = fopen(bin_name,"rb");
if( Fptr == NULL )
{
printf("Can not open %s\n", bin_name);
ex = -1;
break;
}
fseek(Fptr, 0L, SEEK_END);
uint32_t app_size = ftell(Fptr);
fseek(Fptr, 0L, SEEK_SET);
printf("File size = %d\n", app_size);
//Send OTA Header
meta_info ota_info;
ota_info.package_size = app_size;
ota_info.package_crc = 0; //TODO: Add CRC
ex = send_ota_header( comport, &ota_info );
if( ex < 0 )
{
printf("send_ota_header Err\n");
break;
}
//read the full image
if(fread( APP_BIN, 1, app_size, Fptr ) != app_size )
{
printf("App/FW read Error\n");
ex = -1;
break;
}
for(uint32_t i = 0; i < app_size; i++)
{
printf("%d\r\n",APP_BIN[i]);
}
uint16_t size = 0;
for( uint32_t i = 0; i < app_size; )
{
if( ( app_size - i ) >= ETX_OTA_DATA_MAX_SIZE )
{
size = ETX_OTA_DATA_MAX_SIZE;
}
else
{
size = app_size - i;
}
//printf("%d\r\n", size);
//printf("[%d/%d]\r\n", i/ETX_OTA_DATA_MAX_SIZE, app_size/ETX_OTA_DATA_MAX_SIZE);
ex = send_ota_data( comport, &APP_BIN[i], size );
if( ex < 0 )
{
printf("send_ota_data Err [i=%d]\n", i);
break;
}
i += size;
}
if( ex < 0 )
{
break;
}
//send OTA END command
ex = send_ota_end(comport);
if( ex < 0 )
{
printf("send_ota_end Err\n");
break;
}
} while (false);
if(Fptr)
{
fclose(Fptr);
}
if( ex < 0 )
{
printf("OTA ERROR\n");
}
return(ex);
}if any one has faced the same issue can guide me.
thanking you
