Hello,
The code below is an example of writing a file to a flash IC connected to EVE:
int Utils_Write_File_To_Flash(uchar8_t *fileName, uint32_t addr, uint32_t tmp_ram_addr)
{
FILE *fp;
uint32_t fileLen, ret, progress = 0;
uint8_t pBuff[(1024 * 32)];
fp = fopen(fileName, "rb+");
if (fp) {
fseek(fp, 0, SEEK_END);
ret = fileLen = ftell(fp);
fseek(fp, 0, SEEK_SET);
while (fileLen > 0)
{
progress = (ret - fileLen) * 100 / ret;
fprintf(stderr, "Progress PROG %d\n", progress);
fflush(stderr);
int32_t ramlen = 0;
tmp_ram_addr = 0;
while ((ramlen < (1024 * 1024)) && (fileLen > 0))
{
uint32_t blocklen = fileLen > (1024 * 32) ? (1024 * 32) : fileLen;
fread(pBuff, 1, blocklen, fp);
fileLen -= blocklen;
Gpu_Hal_WrMem(phost, tmp_ram_addr, pBuff, blocklen); //write data to RAM_G
tmp_ram_addr += blocklen;
ramlen += blocklen;
}
ramlen = (ramlen + 4095) & (~4095);//to ensure 4KB alignment
Gpu_CoCmd_FlashHelper_Update(phost, addr, 0, ramlen); // CMD_FLASHUPDATE
addr += ramlen;
}
fclose(fp);
}
else {
printf("Unable to open file: %s\n", fileName);
}
return ret; /* File size */
}
Please note, this is from our EAB flash programming utility which requires a USB connection to a module. However the same steps will work when updating a flash IC from an MCU. Unfortunately however you may be required to expand the storage of your MCU if the flash file is significantly larger than the storage available, adding an SD card to your configuration may be a suitable solution.
Best Regards,
BRT Community