K70, MQX 4.1 SPI I/O Drivers, Codewarrior CW 10.6 GCC

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

K70, MQX 4.1 SPI I/O Drivers, Codewarrior CW 10.6 GCC

Jump to solution
698 Views
louiemoye
Contributor III

Hello,

I've read several posts on this forum where others are experiencing the same issue as I am having.  Unfortunately, they are working with different versions of MQX and processor.  I'm reying to use MQX 4.1 SPI IO driver on K70, to read a serial Flash part (Micron M25P20).  I believe I have everything cpnfigured properly as I am seeing exactly what I expect on the SPI bus: Setting the WEL bit to the status register, then reading the status register.  I expect 0x02, and this is what I'm seeing on the MISO line.  /CS, SCLK, MOSI, and MISO timing and data look correct, however, the read buffer always report 0x00.  I've tried _io_ioctl  without success (following).   Below is my actual read function.  Any help would be great,

Regards,

Louie

/* Test simultaneous write and read to stat reg */

  memset (send_buffer, 0, sizeof (send_buffer));

  memset (recv_buffer, 0, sizeof (recv_buffer));

  send_buffer[0] = SPI_MEMORY_READ_STATUS;

  rw.BUFFER_LENGTH = 1;

  rw.WRITE_BUFFER = (char *)send_buffer;

  rw.READ_BUFFER = (char *)recv_buffer;

  printf ("IO_IOCTL_SPI_READ_WRITE ... ");

  if (SPI_OK == _io_ioctl (m_spifd, IO_IOCTL_SPI_READ_WRITE, &rw))

  {

  printf ("OK\n");

  }

  else

  {

  printf ("ERROR\n");

  }

  _io_fflush (m_spifd);

unsigned char SerialEEPROM::ReadStatus()

{

  _mqx_int result;

  uint8_t rxVal = 0xFF;

  spiTxBuf = new unsigned char[SPI_TMP_BUF_SIZE];

  spiRxBuf = new unsigned char[SPI_TMP_BUF_SIZE];

  spiTxBuf[0] = STATUS_REG;

  result = _io_write(m_spifd, spiTxBuf, 1);

  result = _io_read(m_spifd, spiRxBuf, 1);

  _io_fflush(m_spifd);

  rxVal = spiRxBuf[0];

  delete(spiTxBuf);

  delete(spiRxBuf);

  return rxVal;

}

0 Kudos
1 Solution
503 Views
louiemoye
Contributor III

I resolved this issue by disabling the SPIMaster (SPI2) component in ProcessorExpert, and modifying init_gpio.c in the BSP_Files directory

Changed to PORTF configuration:

/* Configure GPIOF for DSPI2 peripheral function     */

pctl = (PORT_MemMapPtr)PORTF_BASE_PTR;

pctl->PCR[16] = PORT_PCR_MUX(2);    /* DSPI2.PCS0   */

pctl->PCR[17] = PORT_PCR_MUX(2);    /* DSPI2.SCK    */

pctl->PCR[18] = PORT_PCR_MUX(2);    /* DSPI2.SOUT   */

pctl->PCR[19] = PORT_PCR_MUX(2);    /* DSPI2.SIN    */

pctl->PCR[20] = PORT_PCR_MUX(2);    /* DSPI2.PCS1   */

Was:

/* Configure GPIOD for DSPI2 peripheral function     */

pctl = (PORT_MemMapPtr)PORTD_BASE_PTR;

pctl->PCR[11] = PORT_PCR_MUX(2);    /* DSPI2.PCS0   */

pctl->PCR[12] = PORT_PCR_MUX(2);    /* DSPI2.SCK    */

pctl->PCR[13] = PORT_PCR_MUX(2);    /* DSPI2.SOUT   */

pctl->PCR[14] = PORT_PCR_MUX(2);    /* DSPI2.SIN    */

pctl->PCR[15] = PORT_PCR_MUX(2);    /* DSPI2.PCS1   */

View solution in original post

0 Kudos
1 Reply
504 Views
louiemoye
Contributor III

I resolved this issue by disabling the SPIMaster (SPI2) component in ProcessorExpert, and modifying init_gpio.c in the BSP_Files directory

Changed to PORTF configuration:

/* Configure GPIOF for DSPI2 peripheral function     */

pctl = (PORT_MemMapPtr)PORTF_BASE_PTR;

pctl->PCR[16] = PORT_PCR_MUX(2);    /* DSPI2.PCS0   */

pctl->PCR[17] = PORT_PCR_MUX(2);    /* DSPI2.SCK    */

pctl->PCR[18] = PORT_PCR_MUX(2);    /* DSPI2.SOUT   */

pctl->PCR[19] = PORT_PCR_MUX(2);    /* DSPI2.SIN    */

pctl->PCR[20] = PORT_PCR_MUX(2);    /* DSPI2.PCS1   */

Was:

/* Configure GPIOD for DSPI2 peripheral function     */

pctl = (PORT_MemMapPtr)PORTD_BASE_PTR;

pctl->PCR[11] = PORT_PCR_MUX(2);    /* DSPI2.PCS0   */

pctl->PCR[12] = PORT_PCR_MUX(2);    /* DSPI2.SCK    */

pctl->PCR[13] = PORT_PCR_MUX(2);    /* DSPI2.SOUT   */

pctl->PCR[14] = PORT_PCR_MUX(2);    /* DSPI2.SIN    */

pctl->PCR[15] = PORT_PCR_MUX(2);    /* DSPI2.PCS1   */

0 Kudos