Author Topic: FTP File Download Across Multiple Flash  (Read 8958 times)

Offline ctkian

  • Newbie
  • *
  • Posts: 20
    • View Profile
FTP File Download Across Multiple Flash
« on: September 27, 2011, 08:12:59 AM »
Hi All,

I am using uTasker v1.3_SP6 and I found that when I try to throw in a big file into SPI Flash that is located at end of 1st flash, continue to the start section of 2nd flash, the file transfer is corrupted. When I move the start of the file to point to start of 2nd flash, then the file can transfer without any problem.

Does anyone having similar problem? How should I solve this issue? Currently I am using MCF52233 with 2 SPI flash.

Thank you very much.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: FTP File Download Across Multiple Flash
« Reply #1 on: September 27, 2011, 08:29:13 AM »
Hi

Can you simulate this and get the same effect?

What SPI Flash type are you using?

Does the corruption have a pattern?

Multiple SPI Flash devices have been used in various projects - moving from one Flash to another involves setting the CS line correctly and also calculating the page in the device correctly. Check carefully that the configuration is accurate. If you can simulate this it will make it easier to identify.

If you show me the relevant setup details in the config.h and app_hw_m5223x.h files and send me the test file and the address that it is being sent to I may be able to simulate it too.

Regards

Mark

Offline ctkian

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: FTP File Download Across Multiple Flash
« Reply #2 on: September 28, 2011, 12:50:26 PM »
Hi,

Yes, the problem is reproducible on every ftp file transfer.

The SPI flash we use is 2 piece of AT45DB642.

The file location is start at page number 7766 of 1first flash, address location is 7766X1056 = 0x7D22C0 (excluding MCF522xx flash size)

Due to the file size larger than 128Kb, I had send to email coldfire_uT@uTasker.com instead.

Thank you very much.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: FTP File Download Across Multiple Flash
« Reply #3 on: September 29, 2011, 11:59:01 PM »
Hi

I have been able to find the problem.

It is a general problem when writing and/or reading blocks of data that start in one chip and end in the next chip, which explains why you see it only when the file starts in one FLASH chip and ends in the other.

I have managed to solve it when writing but I couldn't yet solve it for reading.

Once I have completed the correction I'll report back again. It will be tomorrow evening before I manage to do so but it should be completely solved by then (in fact I had more or less the same problem when developing some new extensions and could correct these in that specific case but the more generic correction wasn't made at the time becasue I didn't realise that it was needed).

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: FTP File Download Across Multiple Flash
« Reply #4 on: October 01, 2011, 12:05:19 AM »
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




Offline ctkian

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: FTP File Download Across Multiple Flash
« Reply #5 on: October 06, 2011, 05:50:47 AM »

Hi Mark,

We only require on the write section, thus had implemented it as per your suggest and works fine.

Thanks a lot!  :)