imx8's M4 controls the LPSPI2 for a period of time and the program terminates

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

imx8's M4 controls the LPSPI2 for a period of time and the program terminates

947 Views
3131734215
Contributor II

1.My program uses M4 of i.mx8Q to control LPSPI2 to repeatedly send and receive one word,SIN and SOUT short,the waveform and baud rate with an oscilloscope are correct,But the program terminates after running for a while?

2.Program path: \Samples_Documents\Samples\boards\mekmimx8qx\driver_examples\lpspi_myadd\interrput_5\master\iar

3.I need help about why the program stopped,thank you very much!

4.The debug information of LPUART of M4 is as follows:

>$ SystemCoreClock = 264000000, LPSPI2_freq_48MHZ = 47407407,DEMO_ADMA_LPSPI_CLK_FREQ = 47407407


0
1  LPSPI_FlushFifo 


i=1 rDat = 0x102 


0


i=2 rDat = 0x102 


0


i=3 rDat = 0x102 
 
.
.
.
 
 
0


i=2792 rDat = 0x102 


0


i=2793 rDat = 0x102 


0


i=2794 rD
0 Kudos
Reply
4 Replies

810 Views
igorpadykov
NXP Employee
NXP Employee

Hi Lin

one can try with lpspi driver from SDK_2.5.3_MEK-MIMX8QX available on

Welcome | MCUXpresso SDK Builder 

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

0 Kudos
Reply

810 Views
3131734215
Contributor II

Hi igorpadykov

      I have  try with lpspi driver from SDK_2.5.3_MEK-MIMX8QX ,it is same as before that the program terminates after running for a while,I want to solve this problem.

#define EXAMPLE_DELAY_COUNT (SystemCoreClock / 100U)

void delay(void)
{
   volatile uint32_t i = 0;
    for (i = 0; i < EXAMPLE_DELAY_COUNT; ++i)
   {
     __asm("NOP"); /* delay */
    }
}

int main(void)
{
lpspi_master_config_t masterConfig;
sc_ipc_t ipc;
uint32_t freq;

ipc = BOARD_InitRpc();
BOARD_InitPins(ipc);
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
//BOARD_InitMemory();

if (sc_pm_set_resource_power_mode(ipc, SC_R_SPI_2, SC_PM_PW_MODE_ON) != SC_ERR_NONE)
{
PRINTF("Error: Failed to power on FSPI2\r\n");
}
if((freq = CLOCK_SetIpFreq(kCLOCK_DMA_Lpspi2, SC_48MHZ)) == 0)
{
PRINTF("Error: Failed to set FSPI0 frequency\r\n");
return;
}
sc_pm_clock_enable(ipc, SC_R_SPI_2, SC_PM_CLK_MST_BUS, true, 0);


LPSPI_MasterGetDefaultConfig(&masterConfig);
//masterConfig.baudRate = ADMA_LPSPI_BAUD;
//masterConfig.direction = 0;
LPSPI_MasterInit(DEMO_ADMA_LPSPI, &masterConfig, DEMO_ADMA_LPSPI_CLK_FREQ);
PRINTF("SystemCoreClock = %d, LPSPI2_freq_48MHZ = %d,DEMO_ADMA_LPSPI_CLK_FREQ = %d\r\n",SystemCoreClock, freq, DEMO_ADMA_LPSPI_CLK_FREQ );
delay();

uint32_t i=0,rDat=0;
while(1)
{
rDat = LPSPI_MasterReadWrite(DEMO_ADMA_LPSPI, 0x0102);
i++;
PRINTF("i=%d rDat = 0x%x \r\n",i, rDat);
}
PRINTF("Error: Exit\r\n");
}

uint32_t LPSPI_MasterReadWrite(LPSPI_Type *base, uint32_t data)
{
static uint8_t i=0;
uint32_t readData=0,num=0;
uint32_t fifoSize = 64;
PRINTF("\r\n\r\n0\r\n");

if(i == 0)
{
/*The TX and RX FIFO sizes are always the same*/
fifoSize = LPSPI_GetRxFifoSize(base);
LPSPI_FlushFifo(base, true, true);
//i=1;
PRINTF("1 LPSPI_FlushFifo \r\n");
}

/* Wait that LPSPI is not busy.*/
while(LPSPI_GetStatusFlags(base) & kLPSPI_ModuleBusyFlag)
{
;
PRINTF("2 \r\n");
}

// /*Wait until TX FIFO is not full*/
// while (LPSPI_GetTxFifoCount(base) == fifoSize)
// {
// PRINTF("3 \r\n");
// }

if(i == 1)
{
while (!(LPSPI_GetStatusFlags(base) & kLPSPI_TransferCompleteFlag))
{
PRINTF("3 \r\n");
}
}
else if(i == 0)
{
i = 1;
}
LPSPI_ClearStatusFlags(base, (LPSPI_SR_WCF_MASK | LPSPI_SR_FCF_MASK |LPSPI_SR_TCF_MASK | LPSPI_SR_REF_MASK) );


LPSPI_WriteData(base, data);
PRINTF("4 \r\n");

// while (!(LPSPI_GetStatusFlags(base) & kLPSPI_RxDataReadyFlag))
// {
// ;
// PRINTF("5 \r\n");
// }

while((base->RSR)& 0x02 ) //P7937,0b - RX FIFO is not empty; 1b - RX FIFO is empty
{
;
PRINTF("5-1 \r\n");
}

// num = LPSPI_GetRxFifoCount(base);
// PRINTF("6 GetRxFifoCount = %d \r\n",num);

readData = LPSPI_ReadData(base);

PRINTF("7 \r\n");
return readData;
}

0 Kudos
Reply

810 Views
igorpadykov
NXP Employee
NXP Employee

Hi Lin

 

could you  try with i.MX8QXP MEK reference board.

Best regards

igor

0 Kudos
Reply

810 Views
3131734215
Contributor II

Hi igorpadykov

     Thank you for your reply, SDK_2.5.3_MEK-MIMX8QX I will try it later, but can you tell me the reason why the program terminated?

Thank you!

0 Kudos
Reply