Hi
These are the corrections that I made and tested in the V1.4 project. You will need to add the relevant changes to your V1.3 project (in M5223x.c):
WRITE:
fnSPI_command(WRITE_BUFFER_1, usPageOffset, _EXTENDED_CS ucData, usDataLength);// copy new content
fnSPI_command(PROG_FROM_BUFFER_1, usPageNumber, _EXTENDED_CS 0, 0); // program to main memory
Length -= usDataLength;
ucData += usDataLength;
usPageNumber++;
#ifdef SPI_FLASH_MULTIPLE_CHIPS
if (usPageNumber >= SPI_FLASH_PAGES) { // on reaching the end of an SPI Flash chip, move to next
usPageNumber = 0;
iChipSelect++;
}
#endif
usPageOffset = 0;
The write modification is quite simple; when the page number reaches the end of the present device it needs to be set to zero an dthe chip select count incremented so that the write continues in the next device.
READ:
The read modification is not quite so easy so I have put the listing (with other SPI Flash devices removed for clarity).
It may not be quiet the same in V1.3 but should be quite easily recognisable and thus modifiable -
if (address start is in SPI Flash)
{
#ifdef SPI_FLASH_MULTIPLE_CHIPS
int iChipSelect;
MAX_FILE_LENGTH SPI_FlashLength;
do {
#endif
unsigned short usPageNumber;
unsigned short usPageOffset;
usPageNumber = fnGetSPI_FLASH_location(ParLocation, &usPageOffset EXTENDED_CS);
#ifdef SPI_FLASH_MULTIPLE_CHIPS
#if (defined SPI_FILE_SYSTEM && defined FLASH_FILE_SYSTEM)
SPI_FlashLength = ((FLASH_START_ADDRESS + SIZE_OF_FLASH + SIZE_OF_NVRAM + ((iChipSelect + 1) * SPI_DATA_FLASH_0_SIZE)) - (CAST_POINTER_ARITHMETIC)ParLocation); // the maximum amount of data that can be read from the present SPI Flash
#else
SPI_FlashLength = ((uFILE_START + FILE_SYSTEM_SIZE + ((iChipSelect + 1) * SPI_DATA_FLASH_0_SIZE)) - (CAST_POINTER_ARITHMETIC)ParLocation); // the maximum amount of data that can be read from the present SPI Flash
#endif
if (Size > SPI_FlashLength) { // if the read will overflow the end of the present SPI Flash device
MAX_FILE_LENGTH RemainingLength = (Size - SPI_FlashLength);
Size = SPI_FlashLength; // reduce the first read length to the end of the device
SPI_FlashLength = RemainingLength; // the size remainin to be read from following SPI Flash
}
else {
SPI_FlashLength = 0; // single read only is required
}
#endif
#if SPI_FLASH_PAGE_LENGTH >= 1024 // {23}
fnSPI_command(CONTINUOUS_ARRAY_READ, (unsigned long)((unsigned long)(usPageNumber << 11) | (usPageOffset)), _EXTENDED_CS ptrValue, Size);
#elif SPI_FLASH_PAGE_LENGTH >= 512
fnSPI_command(CONTINUOUS_ARRAY_READ, (unsigned long)((unsigned long)(usPageNumber << 10) | (usPageOffset)), _EXTENDED_CS ptrValue, Size);
#else
fnSPI_command(CONTINUOUS_ARRAY_READ, (unsigned long)((unsigned long)(usPageNumber << 9) | (usPageOffset)), _EXTENDED_CS ptrValue, Size);
#endif
#ifdef SPI_FLASH_MULTIPLE_CHIPS
ParLocation += Size;
ptrValue += Size;
Size = SPI_FlashLength;
} while (SPI_FlashLength != 0);
#endif
return;
}
It should be visible that there is a new do / while loop. If it is detected that it is not possible to read the complete content to the buffer out of the present device the read length is limited to the maximum possible. The loop is then not quit and further reads are made, each time re-calculating the SPI Flash device and address, untill the required amount of data has been returned.
My tests then showed that it could write and read the test file over device boundaries without any errors being detected. However I did note that the test file is not the best for such verification since it contains a lot of FFs - I didn't test with other files though since I could quite clearly see what was going wrong and believe that it is now behaving as it should.
Regards
Mark