Hi everyone,
Thank you very much to you all for your help!
To recap, my MCU does indeed have a 2 MB flash die. But only the first four sectors of each bank are tested and recommended to work with.
When the bin file is generated, the gap between the two banks is filed with 0x00.
The solution we have used is:
The bootloader reads the bin file piece by piece and write it to the flash, then increment it. When it starts reading the part corresponding to the gap, it stops writing until it reaches the second bank start address.
uint32_t ram_address = 0, last_pga_address = 0, read_size = 0;
bool read_flag = true;
/** RAM Address initialization */
ram_address = (uint32_t)(&RamBuffer);
/** Programm address init */
last_pga_address = APPLICATION_STARTADDRESS;
while(read_flag == true)
{
if(iap_read_file(RamBuffer, IAP_BUFFER_SIZE, &read_size) != RET_OK)
{
return RET_ERROR;
}
/* The read data < "BUFFER_SIZE" Kbyte */
if(read_size < IAP_BUFFER_SIZE)
{
read_flag = false;
}
/* Ignore addresses between 0x08080000 and 0x08100000 */
if((last_pga_address < FLASH1_M_ENDADDRESS) || (last_pga_address >= FLASH2_M_STARTADDRESS))
{
if(Flash_Write(last_pga_address, read_size, ram_address) != RET_OK)
{
return RET_ERROR;
}
}
/* Update last programmed address value */
last_pga_address += read_size;
}
That wasn't a big deal, but I really wanted to understand why/how it worked when it wasn't supposed to.
Thank you all again.