SPi Flash Memory Read error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPi Flash Memory Read error

Jump to solution
3,002 Views
davidzhou
Contributor V

Hi,

I have K60 tower. I tried example code in the folder Freescale_MQX_4_2\mqx\examples\spi_legacy

I have three issues:

1. in spi.c code, I have to comment out the following code snippet:

if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_STATS, &stats))   {   // Get statistics

   printf ("Interrupts:   %d\n", stats.INTERRUPTS);

   printf ("Rx packets:   %d\n", stats.RX_PACKETS);

   printf ("Rx overflow:  %d\n", stats.RX_OVERFLOWS);

   printf ("Tx packets:   %d\n", stats.TX_PACKETS);

   printf ("Tx aborts :   %d\n", stats.TX_ABORTS);

   printf ("Tx underflow: %d\n", stats.TX_UNDERFLOWS);

}

because the stats structure doesn't include INTERRUPTS, RX_OVERFLOWS, TX_ABORTS, and TX_UNDERFLOWS.

After commented out, it runs. I have SPI0 channel enabled. Program runs with Write Returns successfully, and Read Back as 0's.

2.

Read memory status ... 0x00

Enable write latch in memory ... OK

Read memory status ... 0x00

Write unprotect memory ... OK

Enable write latch in memory ... OK

Read memory status ... 0x00

Erase whole memory chip:

Read memory status ... 0x00

Erase chip ...OK

Enable write latch in memory ... OK

Read memory status ... 0x00

Write byte to location 0x00100000 in memory ... [0xBA]

Read memory status ... 0x00

Read byte from location 0x00100000 in memory ... [0x00]

Writing [Hello,World!]

Enable write latch in memory ... OK

Read memory status ... 0x00

Page write 12 bytes to location 0x001001f0 in memory:

Hello,World!

Read memory status ... 0x00

Reading 12 bytes from location 0x001001f0 in memory:

Read []        -- Error Here --- it shall read back Hello,World!, instead of empty string

Enable write latch in memory ... OK

Read memory status ... 0x00

Page write 16 bytes to location 0x001002f0 in memory:

ABCDEFGHIJKLMNOP

Enable write latch in memory ... OK

Read memory status ... 0x00

Page write 56 bytes to location 0x00100300 in memory:

QRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz1234567890

Read memory status ... 0x00

Reading 72 bytes from location 0x001002f0 in memory:

IO_IOCTL_SPI_READ_WRITE ... OK

Simultaneous write and read - memory read from 0x00100000 (10):

Write: 0x03 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

Read : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

Simultaneous read/write (data == 0x00) ... ERROR

3. In Interrupt Mode, according to the readme.pdf in the spi_legacy folder, BSPCFG_ENABLE_ISPI0 macros must be set to non-zero in the user_config.h

I have problems with BSPCFG_ENABLE_ISPI0. The parameter is not defined in the user_config.h file, if I added a line after #define BSPCFG_ENABLE_SPI0  1

#define BSPCFG_ENABLE_ISPI0  1

then it seems has problem with graphical view of the user_config.h, at least the BSPCFG_ENABLE_ISPI0 is not displayed.

Thank you,

David Zhou

0 Kudos
1 Solution
1,683 Views
soledad
NXP Employee
NXP Employee

Hello David,

Sorry for my delay.

There are two spi.h files one for the new spi driver (C:\Freescale\Freescale_MQX_4_2\mqx\source\io\spi) and the other one for the legacy spi (C:\Freescale\Freescale_MQX_4_2\mqx\source\io\spi_legacy).

MQX v4.2 supports the new SPI driver so if you enable the spi0 in the user_confing.h (#define BSPCFG_ENABLE_SPI0 0) you are implementing the new spi driver. This means that when you create a new project and uses the #include <spi.h> the project is pointing to the new spi.h file.

Please check the below thread and let me know if this helps.

https://community.freescale.com/thread/331576


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
4 Replies
1,683 Views
soledad
NXP Employee
NXP Employee

Hello David:

Could you explain a little more the questions 1 and 2??

For question 3, the example shows two mechanisms associated with SPI peripheral module: polling and interrupt.

If you want to select polling mode you need to enable only  the spi0  #define BSPCFG_ENABLE_SPI0  1

if you want to select interrupt mode you need to enable only isp0      #define BSPCFG_ENABLE_ISPI0  1

Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,684 Views
davidzhou
Contributor V

Hi Sol,

Sorry for not making myself clear.

1. in the spi.c code (from mqx/example/spi_legacy, or spi folder),

  the stats variable is defined as SPI_STATISTICS_STRUCT type. But the struct SPI_STATISTICS_STRUCT is defined in the spi.h as following:

/*

** SPI_STATISTICS_STRUCT

**

** This is used to get statistics data from SPI device using IO_IOCTL_SPI_GET_STATS.

*/

typedef struct spi_statistics_struct

{

   /* Number of valid frames received (not dummy receives) */

   uint32_t          RX_PACKETS;

   /* Number of valid frames transmitted (not dummy transmits) */

   uint32_t          TX_PACKETS;

} SPI_STATISTICS_STRUCT, * SPI_STATISTICS_STRUCT_PTR;

which doesn't have stats.INTERRUPTS, etc. members. Only two members RX_PACKETS and TX_PACKETS are defined in the

SPI_STATISTICS_STRUCT structure. So original spi.c in the example folder can not be compiled. I had to comment these lines out, in order to compile the example code.

2. Those are the messages output from the spi.c example program. The only change I made was the flash address to 0x100000. You can see that all outputs are OK, until

Write byte to location 0x00100000 in memory ... [0xBA]   --0xBA is the byte written into memory 0x00100000 on flash

Read memory status ... 0x00

Read byte from location 0x00100000 in memory ... [0x00]  - this shall be 0xBA, but it reads beack [0x00]

3. this is minor issue.

Thank you,

David Zhou

0 Kudos
1,684 Views
soledad
NXP Employee
NXP Employee

Hello David,

Sorry for my delay.

There are two spi.h files one for the new spi driver (C:\Freescale\Freescale_MQX_4_2\mqx\source\io\spi) and the other one for the legacy spi (C:\Freescale\Freescale_MQX_4_2\mqx\source\io\spi_legacy).

MQX v4.2 supports the new SPI driver so if you enable the spi0 in the user_confing.h (#define BSPCFG_ENABLE_SPI0 0) you are implementing the new spi driver. This means that when you create a new project and uses the #include <spi.h> the project is pointing to the new spi.h file.

Please check the below thread and let me know if this helps.

https://community.freescale.com/thread/331576


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,684 Views
davidzhou
Contributor V

Hi Soledad,

Thank you for your support.

David Zhou

0 Kudos