TPL communication not working with S32K312 MCU

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

TPL communication not working with S32K312 MCU

746 Views
Hareesh
Contributor I

Hi NXP team,

We are using S32 design studio v3.5.

From the secure NXP website, we obtained the BCC_S32K144_Monitoring_Diagnostics example code.

Since we are utilizing the S32K312  MCU in this case, we modified the low level peripheral drivers of example code to translate the example code to the S32K312. Now the code is compiling without any errors.

However, the following error message appears and we are not receiving any data on TPL communication:

"LPSPI_IP_TIMEOUT".

My code failing in the following function.

bcc_status_t BCC_MCU_TransferTpl(const uint8_t drvInstance, uint8_t txBuf[],
    uint8_t rxBuf[], const uint16_t rxTrCnt)
{
	(void) drvInstance;

#if defined(TPL)
    int32_t rxTimeout;
    //status_t error;
    Lpspi_Ip_StatusType error;

    DevAssert(txBuf != NULL);
    DevAssert(rxBuf != NULL);
    DevAssert(rxTrCnt > 0);

    /* Transmissions at RX and TX SPI occur almost at the same time. Start
     * reading (response) at RX SPI first. */
   // error = LPSPI_DRV_SlaveTransfer(LPSPISPI_TPL1RX, NULL, rxBuf, rxTrCnt * LPSPI_ALIGNMENT);
     error = Lpspi_Ip_SyncTransmit(&SLAVE_EXTERNAL_DEVICE, NULL, rxBuf, 8U , BCC_RX_COM_TIMEOUT_MS);

    if (error != LPSPI_IP_STATUS_SUCCESS)
    {
        return BCC_STATUS_SPI_FAIL;
    }

    /* Send data via TX SPI. */
    //error = LPSPI_DRV_MasterTransferBlocking(LPSPITPLTX, txBuf, NULL,
      //      LPSPI_ALIGNMENT, BCC_TX_COM_TIMEOUT_MS);

    error = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, txBuf, NULL, 8U , BCC_TX_COM_TIMEOUT_MS);
 
    if (error != LPSPI_IP_STATUS_SUCCESS)
    {
        /* Cancel reception of data. */
       // LPSPI_DRV_SlaveAbortTransfer(LPSPISPI_TPL1RX);
        Lpspi_Ip_Cancel(Lpspi_Ip_DeviceAttributes_SPI_TPL_RX_Instance_3.Instance);

        return (error == LPSPI_IP_TIMEOUT) ? BCC_STATUS_COM_TIMEOUT : BCC_STATUS_SPI_FAIL;
    }

    /* Wait until RX transmission finished. */
    rxTimeout = BCC_RX_COM_TIMEOUT_MS * 1000;
    //while ((LPSPI_DRV_SlaveGetTransferStatus(LPSPISPI_TPL1RX, NULL)
          //  == STATUS_BUSY) && (rxTimeout > 0))
    while ((Lpspi_Ip_GetStatus(3) == LPSPI_IP_BUSY) && (rxTimeout > 0))
    {
        BCC_MCU_WaitUs(10);
        rxTimeout -= 10;

        if(rxTimeout == 0)
            break;
    }

    /* Cancel data reception if the timeout expires. */
    if (rxTimeout <= 0)         // (rxTimeout <= 0)
    {
       // LPSPI_DRV_SlaveAbortTransfer(LPSPISPI_TPL1RX);
        Lpspi_Ip_Cancel(Lpspi_Ip_DeviceAttributes_SPI_TPL_RX_Instance_3.Instance);

        return BCC_STATUS_COM_TIMEOUT;
    }

    return BCC_STATUS_SUCCESS;

#elif defined(SPI)
    return BCC_STATUS_SPI_FAIL;
#endif
}

 

Could you please help me to address this problem?

 

Thanks and regards,

Hareesh

0 Kudos
Reply
7 Replies

699 Views
Hareesh
Contributor I

Hi,

Could someone please assist me in resolving this problem?

 

Best regards,

Hareesh

0 Kudos
Reply

646 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

try to use AsyncTransfer function for Slave device, as it is used in original code, where non-blocking function is called. The Sync function does not finish until transfer is finished or timeout happens, while Async one starts transfer and leave function. User should check for end of transfer either using a callback or calling GetStatus function. Also be sure a LPSPI interrupt is installed/initialized.

BR, Petr 

0 Kudos
Reply

620 Views
Hareesh
Contributor I

Hi @PetrS ,

Thanks for the update.

As per your suggestion we used AsyncTransfer function for Slave device, but we are not getting any data. However we are getting Lpspi_Ip_AsyncTransmit() status as success.

Now it is failing in the following section and it is returning BCC_STATUS_COM_TIMEOUT.

   if (rxTimeout <= 0)         
    {
       // LPSPI_DRV_SlaveAbortTransfer(LPSPISPI_TPL1RX);
        Lpspi_Ip_Cancel(Lpspi_Ip_DeviceAttributes_SPI_TPL_RX_Instance_3.Instance);

        return BCC_STATUS_COM_TIMEOUT;
    }

 

 

Best regards,

Hareesh

0 Kudos
Reply

594 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I can recommend to take scope/analyzer capture of both master/slave SPI signals to know what is generated during your BCC_MCU_TransferTpl. If you passed into master SyncTransmit you should see generated signal on SPI lines, same on slave lines if this responses anything.
If not I can suggest to check LPSPI interrupt configuration.

BR, Petr

 

0 Kudos
Reply

535 Views
Hareesh
Contributor I

Hi @PetrS ,

We tried to capture SPI signals when the BCC_MCU_TransferTpl() function is calling, but we didn't get any response on the SPI lines.

The below section shows the interrupt configurations of SPI module in the code.

	/* Initialize IRQs */
	IntCtrl_Ip_Init(&IntCtrlConfig_0);

	IntCtrl_Ip_InstallHandler(LPSPI0_IRQn , Lpspi_Ip_LPSPI_0_IRQHandler, NULL_PTR);
	IntCtrl_Ip_EnableIrq(LPSPI0_IRQn);
	IntCtrl_Ip_InstallHandler(LPSPI3_IRQn , Lpspi_Ip_LPSPI_3_IRQHandler, NULL_PTR);
	IntCtrl_Ip_EnableIrq(LPSPI3_IRQn);


   /* Initialize LPSPI instances. */
     error_spi = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SPI_MASTER_Instance_0);    //TPL_tx--SPI0

     if (error_spi != LPSPI_IP_STATUS_SUCCESS)
     {
         return;
     }

     error_spi = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SPI_SLAVE_Instance_3);    //TPL_rx--SPI3

     if (error_spi != LPSPI_IP_STATUS_SUCCESS)
     {
         return;
     }

     Lpspi_Ip_UpdateTransferMode(MASTER_EXTERNAL_DEVICE.Instance, LPSPI_IP_INTERRUPT);
     Lpspi_Ip_UpdateTransferMode(SLAVE_EXTERNAL_DEVICE.Instance, LPSPI_IP_INTERRUPT);

 

The below image shows the SPI interrupt configuration.

Screenshot (282).png

 

Also, the following SPI functions are used in BCC_MCU_TransferTpl() function to transmit and receive data.

    error = Lpspi_Ip_AsyncTransmit(&SLAVE_EXTERNAL_DEVICE, NULL, rxBuf, 8U ,NULL);

    if (error != LPSPI_IP_STATUS_SUCCESS)
    {
        return BCC_STATUS_SPI_FAIL;
    }

     error = Lpspi_Ip_AsyncTransmit(&MASTER_EXTERNAL_DEVICE, txBuf, NULL, 8U ,NULL);

    if (error != LPSPI_IP_STATUS_SUCCESS)
    {
        return BCC_STATUS_SPI_FAIL;
    }

 

 

Best regards,

Hareesh

0 Kudos
Reply

388 Views
Hareesh
Contributor I

Hi,

Could someone please assist me in resolving this problem?

 

Best regards,

Hareesh

S32K312EVB-Q172 MC33771C BATTERY-MANAGEMENT-CONTROL 

0 Kudos
Reply

367 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

maybe half duplex operation will be even better for master (tx) and slave (rx), I think.

And you can refer to Lpspi_Ip_HalfDuplexTransfer_S32K344 demo example within RTD. 

BR, Petr

0 Kudos
Reply