Hi,
I am working with my K60N512 custom board. Now I am trying to create output for spi example in mqx folder.I found read error like below
-------------- SPI driver example --------------
This example application demonstrates usage of SPI driver.
It transfers data to/from external memory over SPI bus.
The default settings in memory.h apply to TWR-MEM flash memory.
Current baud rate ... 9600000 Hz
Changing the baud rate to 500000 Hz ... OK
Current baud rate ... 500000 Hz
Setting clock mode to SPI_CLK_POL_PHA_MODE0 ... OK
Getting clock mode ... SPI_CLK_POL_PHA_MODE0
Setting endian to SPI_DEVICE_BIG_ENDIAN ... OK
Getting endian ... SPI_DEVICE_BIG_ENDIAN
Setting transfer mode to SPI_DEVICE_MASTER_MODE ... OK
Getting transfer mode ... SPI_DEVICE_MASTER_MODE
Clearing statistics ... OK
Getting statistics:
Rx packets: 0
Tx packets: 0
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
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 0xba to location 0x000000f0 in memory ... done
Read memory status ... 0x00
Read byte from location 0x000000f0 in memory ... 0x00
Byte test ... ERROR
Getting statistics:
Rx packets: 8
Tx packets: 25
IO_IOCTL_SPI_READ_WRITE ... OK
Simultaneous write and read - memory read from 0x000000f0 (10):
Write: 0x03 0x00 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x00
Read : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Simultaneous read/write (data == 0x00) ... ERROR
-------------- End of example --------------
I have asked this 2 times in nxp community nobody answered my questions.
I found strange thing which is like a bug in KDS. In the spi example there is a part of code to define the memory channel:
#if BSP_SPI_MEMORY_CHANNEL == 0
#if ! BSPCFG_ENABLE_SPI0
#error This application requires BSPCFG_ENABLE_SPI0 defined non-zero in user_config.h. Please recompile kernel with this option.
#else
#define TEST_CHANNEL "spi0:"
#endif
#elif BSP_SPI_MEMORY_CHANNEL == 1
#if ! BSPCFG_ENABLE_SPI1
#error This application requires BSPCFG_ENABLE_SPI1 defined non-zero in user_config.h. Please recompile kernel with this option.
#else
#define TEST_CHANNEL "spi1:"
#endif
#elif BSP_SPI_MEMORY_CHANNEL == 2
#if ! BSPCFG_ENABLE_SPI2
#error This application requires BSPCFG_ENABLE_SPI2 defined non-zero in user_config.h. Please recompile kernel with this option.
#else
#define TEST_CHANNEL "spi2:"
#endif
I have defined the macro #define BSP_SPI_MEMORY_CHANNEL (1) in the <board>.h file but look at this screen shot. When I right click on SPI_MEMORY_CHANNEL and click on explore declaratio I found this. That is the macro defined for memory channel two.But I have defined it as 1 in bsp files why is this happening please help...
Hi Yadhukrishnan:
Did you make clean all and rebuild your BSP ?
If you still think BSP_SPI_MEMORY_CHANNEL not right, I suggest you print out this Macro to check it's real value
Regards
Daniel
Hi danielchen@fsl
I did what you said and I got BSP_SPI_MEMORY_CHANNEL as 1. I did the spi example in different computers and I got the same read error.
Please check is there any bug in this revision.I don't know why is this happening.
Hi
I tested this demo with TWR-K65F180M, TWR-K60D100M, TWR-K60N512, not found issue, please see the picture , this is tested with K60N512.
Since you are using your custom board, I suggest you check the 4-wire SPI connection. Does your SPI1 routed to the Memory board correctly?
I checked your error message, it seems the SPI read operation is not right. I remember you are using W25Q64 spi flash, I think you need to check the SPI serial memory instructions from the datasheet, maybe you need to modify them according to your custom board.
/* The SPI serial memory instructions */
#define SPI_MEMORY_WRITE_STATUS 0x01
#define SPI_MEMORY_WRITE_DATA 0x02
#define SPI_MEMORY_READ_DATA 0x03
#define SPI_MEMORY_WRITE_LATCH_DISABLE 0x04
#define SPI_MEMORY_READ_STATUS 0x05
#define SPI_MEMORY_WRITE_LATCH_ENABLE 0x06
#define SPI_MEMORY_CHIP_ERASE 0xC7
Regards
Daniel
danielchen@fsl I am sure the instructions are same,I have checked the datasheet.I am using W25Q64FV spi flash device in the custom board.
Now I think the routing of spi1 is not correct.I defined the pins in init_gpio.c as below
case 1:
/* Configure GPIOE for SPI1 peripheral function */
pctl = (PORT_MemMapPtr)PORTE_BASE_PTR;
pctl->PCR[1] = PORT_PCR_MUX(2); /* SPI1.SOUT */
pctl->PCR[2] = PORT_PCR_MUX(2); /* SPI1.SCK */
pctl->PCR[3] = PORT_PCR_MUX(2); /* SPI1.SIN */
pctl->PCR[0] = PORT_PCR_MUX(2); /* SPI1.PCS0 */
/* Enable clock gate to DSPI1 module */
sim->SCGC6 |= SIM_SCGC6_SPI1_MASK;
break;
Hi
Since you are use PTE4 and PTE5 as SPI1_HLD and SPI1_WP, did you configure PTE4 and PTE5 ?
Another thing you need to check is the SPI instructions and it's sequence. On TWR-MEM board, SPI serial memory is AT26DF081A, Please see the details at http://www.atmel.com/Images/doc3600.pdf
You need to check the difference between them and do some modifications according to your SPI memory chip.
(spi_memory.c and spi_memory.h)
Regards
Daniel