I have a problem with writing the binary into the Flash Memory(TMS320C55x, ezDSP5535). i used to write into the Flash Memory using the spiflash_writer which is example code that TI distribute
My problem is that the size of my binary is more than 64K bytes
so i can not write into the Flash memory using the spiflash_writer
because the spiflash_writer does not support that binary which is more than 64K
the spiflash_writer read the binary file from the PC file system using fopen() and fread() function and then load into internal SARAM(128K size)
the spiflash_writer write binary file data into Flash Memory using SPI interface after loading into SARAM
but the spiflash_writer fails in my case that the size of binary is more than 64k
TMS320C55x Core registers are normally 16bits. and char, short, int primitive types are 16 bits only long type is 32 bits.
anyway i think the standard io library(fread, fwrite in the rts55x library) can not suppprt more than 64K files
i really wanna know that those functions does not suppot more than 16bits?
anyway i write following codes. i have a LSM.bin. following codes make an output file LSM.test these two files should be same. it fails in the ezdsp5535 but it succeed in the linux PC
so i think fread and fwrites doens not support more than 16bits.
is that right?
============================== Verification Codes start=============================================================
#include <stdio.h>
typedef unsigned char Uint8; typedef unsigned int Uint32; typedef int Int32;
Uint8 bootImage[80000]; Uint8 fileNameRead[256]; Uint8 fileNameWrite[256];
#define PARTION_SIZE 0x3DF0
// test routine int main(void) { Int32 fileSize = 0, fileSizeTemp; Int32 freadSize, fwriteSize; FILE *fPtrRead, *fPtrWrite; Uint32 *ramPtr;
strcpy((char*) fileNameRead, ".//LSM.bin"); strcpy((char*) fileNameWrite, ".//LSM.test");
fPtrRead = fopen((const char *)fileNameRead, "rb"); fPtrWrite = fopen((const char *)fileNameWrite, "wb");
if(fPtrRead == NULL || fPtrWrite == NULL ) { printf("ERROR: File Open failed\r\n"); return 1; } fileSize = 0; // Initialize size to 0
/* Get file size */ fseek(fPtrRead,0,SEEK_END); fileSize = ftell(fPtrRead);
/* Setup pointer in RAM for temporary storage of data */ ramPtr = (Uint32 *) bootImage;
if(fileSize == 0) // Check if file was found { printf("ERROR: File read failed.. Closing program.\r\n"); fclose (fPtrRead); return 1; }
fseek(fPtrRead,0,SEEK_SET); fileSizeTemp = fileSize; while(fileSizeTemp > 0) { if(fileSizeTemp >= PARTION_SIZE) { freadSize = fread(ramPtr, 1, (size_t)PARTION_SIZE, fPtrRead); fileSizeTemp -= freadSize; ramPtr = (Uint32 *)(ramPtr+(freadSize/4)); } else { freadSize = fread(ramPtr, 1, fileSizeTemp, fPtrRead); fileSizeTemp -= freadSize; }
}
ramPtr = (Uint32 *) bootImage;; fseek(fPtrWrite,0,SEEK_SET); fileSizeTemp = fileSize; while(fileSizeTemp > 0) { if(fileSizeTemp >= PARTION_SIZE) { fwriteSize = fwrite(ramPtr, 1, (size_t)PARTION_SIZE, fPtrWrite); fileSizeTemp -= fwriteSize; ramPtr = (Uint32 *)(ramPtr+(fwriteSize/4)); } else { fwriteSize = fwrite(ramPtr, 1, fileSizeTemp, fPtrWrite); fileSizeTemp -= fwriteSize; }
}
fclose(fPtrRead); fclose(fPtrWrite); return 0; }
============================== Verification Codes end =============================================================
==================== spiflash_writer codes start==================================================
Int16 spiflash_writer( ) { Uint32 i, j, pages; Uint16* pdata; Int32 fileSize = 0; Int32 freadSize; FILE *fPtr; Uint16 *ramPtr; /* Read the filename from host */ printf("Enter the file Name:\r\n"); scanf("%s", fileName); fflush(stdin);
/* Open a File from the hard drive */ printf("Opening file...\r\n"); fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { printf("ERROR: File %s Open failed\r\n", fileName); return 1; } fileSize = 0; // Initialize size to 0
/* Get file size */ fseek(fPtr,0,SEEK_END); fileSize = ftell(fPtr);
/* Setup pointer in RAM for temporary storage of data */ ramPtr = (Uint16*) bootImage; if(fileSize == 0) // Check if file was found { printf("ERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return 1; } fseek(fPtr,0,SEEK_SET);
// fileSize= 64000; freadSize = fread(ramPtr, 1, fileSize, fPtr); if (fileSize != freadSize ) // Read file to ram and check if read properly { printf("WARNING: File Size mismatch.\r\n"); return 1; } fseek(fPtr,0,SEEK_SET);
/* Calculate number of pages */ pages = (fileSize / spiflash_PAGESIZE) + 1;
/* Initialize the SPI interface */ EZDSP5535_SPIFLASH_init( );
/* Erase target area in spiflash */ printf("Erasing target area...\r\n"); EZDSP5535_SPIFLASH_erase( 0, fileSize);
/* Write to SPIFLASH */ printf("Writing file...\r\n"); for ( i = 0 ; i < pages ; i++ ) { /* Write a page */ EZDSP5535_SPIFLASH_write( ((Uint32)bootImage + (i * spiflash_PAGESIZE)), i * spiflash_PAGESIZE, spiflash_PAGESIZE ); }
/* Read and verify SPIFLASH */ printf("Checking file...\r\n"); for ( i = 0 ; i < pages ; i++ ) { /* Read a page */ EZDSP5535_SPIFLASH_read( i * spiflash_PAGESIZE, ( Uint32 )rx, spiflash_PAGESIZE );
/* Check the pattern */ pdata = ( Uint16* )((Uint32)bootImage + (i * spiflash_PAGESIZE)); for ( j = 0 ; j < spiflash_PAGESIZE; j++ ) { if ( ((*pdata++) & 0xFF)!= (rx[j])) return 1; // Fail } } return 0; } ==================== spiflash_writer codes end==================================================