Author Topic: Problem with ST FLASH  (Read 15358 times)

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Problem with ST FLASH
« on: September 01, 2008, 06:49:56 AM »
Hallo.
I have choose:
#define SPI_FILE_SYSTEM
#define FLASH_FILE_SYSTEM

with STM25P80 and now simulator breaks when I want to connect with ftp.
When I choose STM25P16 and bigger FLASH every thing is ok. What is wrong??

Pls help me!
robo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Problem with ST FLASH
« Reply #1 on: September 01, 2008, 12:07:20 PM »
Hi Robo

I am not sure what you mean by 'breaks' but it sounds as though there is maybe an exception when you connect with FTP. There will usually be a directory listing returned and it is probably the file system search which is failing somewhere.

When changing memory configurations it is advisable to delete the files FLASH_M5223X.ini and STM25PXXX.ini in the directory \Applications\uTaskerV1.3\Simulator otherwise there may be something which doesn't match the setup primed to the simulated FLASH.

If you still have the problem after performing the previous point could you indicate what the 'break' is telling you?

Regards

Mark

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Problem with ST FLASH
« Reply #2 on: September 01, 2008, 12:17:53 PM »
Hi Mark!

It means that some error occur.
Before changing memory configurations I delete files FLASH_LM3SXXXX.ini and STM25PXXX.ini beacouse I'm using LM3S6965.

Regards,
robo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Problem with ST FLASH
« Reply #3 on: September 01, 2008, 01:46:22 PM »
Hi Robo

I haven't been able to reproduce any problem with this configuration. Please can you give more details about the error?
Perhaps a screen shot, or the line of code which the simulator is experiencing the problem with?

Regards

Mark

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Problem with ST FLASH
« Reply #4 on: September 01, 2008, 02:03:34 PM »
here is screen:


problem is in line:
unsigned char ucValue = ucSTM25PXXX[(usPage[iSel]* SPI_FLASH_PAGE_LENGTH) + usOffset[iSel] + ulDeviceOffset];
« Last Edit: September 01, 2008, 02:05:24 PM by robo »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Problem with ST FLASH
« Reply #5 on: September 01, 2008, 05:48:16 PM »
Hi Robo

Now I can reproduce a problem with the LM3S project with certain FLASH types. The reason for the crash is that the file system is configured to be larger than the physical memory when the smaller types are used. The simulator will crash (because there is an access outside of the simulated SPI FLASH memory) whereas a target will probably wrap-around and cause data corruption.

When configuring for a certain SPI FLASH size it is also necessary to configure the file system size accordingly. Here is an example of setting the largest file system size with the M25P40 and the M25PE40 - note that the PE types are data flash types and the P types are code FLASH types; the PE devices have smaller blocks which can be individually deleted and so are more suited for storing data rather than the large block granularity (64k) in the code FLASH devices.

The example is basically valid for all processor projects but I have used the defines from the LM3S project.

#define SPI_FLASH_STM25P40    // in app_hw_lm3sxxxx.h
This defines the type used and so the memory size. The memory size is 4MBit (512kByte)
#define SPI_FLASH_PAGES             (8*256) is selected automatically for this chip, which specifies that it has 2k pages.
#define SPI_FLASH_PAGE_LENGTH 256 // is a fixed value, so the total memory size if 2k pages of 256 bytes = 512kbytes
#define SPI_DATA_FLASH_0_SIZE   (SPI_FLASH_PAGES*SPI_FLASH_PAGE_LENGTH)

In config.h you have specified that the chip is an ST type (#define SPI_FLASH_ST) and you can distinguish between code flash and data flash using #define SPI_DATA_FLASH. This define shouldn't change the FLASH size but does inform the code that it can delete sub-sectors rather than only sectors:
    #ifdef SPI_DATA_FLASH
        #define SPI_FLASH_SECTOR_LENGTH (16*SPI_FLASH_PAGE_LENGTH)       // sub-sector size of data FLASH
    #else
        #define SPI_FLASH_SECTOR_LENGTH (256*SPI_FLASH_PAGE_LENGTH)      // sector size of code FLASH
    #endif

Here you see (in app_hw_lm3sxxxx.h) that the sector length is automatically adapted (64k for the code flash and 4k for the data flash)

The file system is defined also in config.h
#define uFILE_SYSTEM_START (MEMORY_RANGE_POINTER)(uFILE_START)
#define uFILE_SYSTEM_END   (MEMORY_RANGE_POINTER)(uFILE_START + FILE_SYSTEM_SIZE)


In it is important that the FILE_SYSTEM_SIZE corresponds to the physically available memory. Note that if there are multiple SPI FLASH chips defined this corresponds to the total amount of memory available. In the case of one M25P(E)40 the size should not exceed 512k if the file system is exclusively in the SPI FLASH (again there are exceptions if the file system is defined to start in internal FLASH and continue in SPI FLASH).

Searching through the project you will find
        #define FILE_SYSTEM_SIZE (32*SINGLE_FILE_SIZE)                   // 512k reserved for file system
where
        #define SINGLE_FILE_SIZE (FILE_GRANULARITY)                      // each file a multiple of 16k
and
        #define FILE_GRANULARITY (SPI_FLASH_BLOCK_LENGTH)
and
        #define SPI_FLASH_BLOCK_LENGTH  SPI_FLASH_SECTOR_LENGTH

This means that FILE_SYSTEM_SIZE = 32 x SPI_FLASH_SECTOR_LENGTH: 2Meg for code Flash or 128k for data flash

So basically the define for FILE_SYSTEM_SIZE and its comment are not correct. It depends on whether code or data flash is being used and its comment would be 128/2M respectively.
This does however explain why defining the M25P16 (2MByte type) then works!

So to cut a long story short, the configuration is not correct for ST Flash (although fine for ATMEL). To correct this (to achieve the 512k file system as default) the following 2 changes are proposed:

1. In config.h
        #if defined SPI_FLASH_ST
            #if defined SPI_DATA_FLASH
                #define FILE_GRANULARITY (4*SPI_FLASH_BLOCK_LENGTH)      // (4 x 4096 byte blocks) file granularity is equal to a multiple of the FLASH granularity (as defined by the device)
            #else
                #define FILE_GRANULARITY (SPI_FLASH_BLOCK_LENGTH)        // (65535 byte blocks) file granularity is equal to a multiple of the FLASH granularity (as defined by the device)
            #endif


2. In app_hw_lm3sxxxx.h
        #if defined SPI_FLASH_ST && defined SPI_DATA_FLASH
            #define FILE_SYSTEM_SIZE (32*SINGLE_FILE_SIZE)               // 512k reserved for file system
        #else
            #define FILE_SYSTEM_SIZE (8*SINGLE_FILE_SIZE)                // 512k reserved for file system
        #endif


This ensures that code/data flash is respected and corrects the size for the ST devices. Note that there are only up to 8 (64k) files in the code Flash type but up to 32k (16k) files in the data Flash type. By changing the file granularity in the data FLASH case this can also be adjusted for more or less.

I tested M25P40 and M25PE40 configurations and these seemed to operate correctly in the simulator. Of course this set up is default for the demo project and can be modified to suit real needs. The information above should be useful for anyone wanting to change the configuration.

Regards

Mark

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Problem with ST FLASH
« Reply #6 on: September 01, 2008, 07:08:12 PM »
Thanks for your help Mark!

Regards,
robo

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Problem with ST FLASH
« Reply #7 on: September 04, 2008, 07:38:51 AM »
Hi Mark!

I have one more question: how to use SPI ST FLASH without uFiles system (I want to have uFaileSystem in internal LM3S6965 FLASH - like it is in demo, and useing external SPI ST FLASH for storing data). I now that there are low level functions (fnEraseFlashSector, fnWriteBytesFlash, fnGetParsFile), but what I should make do use them?? How will look configuration?

Regards,
robo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Problem with ST FLASH
« Reply #8 on: September 04, 2008, 08:31:06 PM »
Hi Robo

To use the SPI FLASH for data storage, outside of the file system, you can use the low level commands as you have already noted.
To use them, you define the file system as normal - entirely in internal FLASH memory area.

SPI FLASH is then 'pseudo'-memory mapped. It should always start at an address higher than the internal FLASH end address. It is defined by SPI_FLASH_START, where it often is simply defined to start after the internal FLASH as follows:
#define SPI_FLASH_START  (FLASH_START_ADDRESS + SIZE_OF_FLASH)
The actual size of the SPI FLASH depends on the size of the SPI FLASH chip itself, and how many there are (if multiple chips are used).:SPI_DATA_FLASH_SIZE

When using the low level commands (like fnWriteBytesFlash()), the routine will automatically program the FLASH memory (either internal FLASH or SPI FLASH) depending on the address written to.

Therefore, if you write data to locations referenced to SPI_FLASH_START (up to SPI_FLASH_START + SPI_DATA_FLASH_SIZE) you will automatically be writing to the SPI FLASH. The same is valid for erase and read operations. Since the locations are outside of the file system the data content is not defined in any way so can be used by the application in the manor the application wants to use it. The only restrictions are due to the FLASH sector size since your application must be aware that it can only delete block sizes defined by the FLASH chips capabilities (granularity). Although it is usually possible to program individual bits from '1' to '0' the application must be aware that programming from '0' to '1' is only possible by first performing a delete of the section that the byte is in...some SPI FLASH chips offer methods for operating like 'pseudo-EEPROM' but these require more low level commands (fnSPI_command() - static function in the driver) and detailed knowledge fo the chip being used.

Regards

Mark


Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Problem with ST FLASH
« Reply #9 on: September 18, 2008, 09:42:16 AM »
Hi Mark,

Can I have uFileSystem in my LM3S6965 flash (160K like is in demo) and continuation of uFileSystem in ST SPI flash?

Regards,
robo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Problem with ST FLASH
« Reply #10 on: September 18, 2008, 10:04:37 AM »
Hi Robo

Yes, this is possible. You will however need to chose a File Granularity which suits both internal and external FLASH.

Regards

Mark