I'm using M4 core's ESCPI in i.max8mq and I want to start with the follow example code:
boards\evkmimx8mq\rtos_examples\freertos_ecspi\ecspi_loopback
boards\evkmimx8mq\driver_examples\ecspi\ecspi_loopback
Both of the 2 demos just run a single test on SPI then hung up CPU, just send 64 bytes and get the data back from internal loop. But the application scenario is to run SPI periodically. So I add a while(1) loop in the demo code, just like the following code segment. But the weird thing is the code stoped after several senonds. If I add the init function before transfer function the code can run all the time. Both the demo for RTOS and non-ROTS has the same issue. Does it nessary to initialise SPI before every signle transfer?
static void ecspi_task(void *pvParameters){
    uint8_t i;
    status_t status;
    ecspi_rtos_handle_t master_rtos_handle;
    ECSPI_MasterGetDefaultConfig(&masterConfig);
    masterConfig.baudRate_Bps   = ECSPI_TRANSFER_BAUDRATE;
    masterConfig.enableLoopback = false;
    for (i = 0; i < ECSPI_TRANSFER_SIZE; i++)    { 
       masterTxData[i] = i;
    }    
while (1){        
if (status != kStatus_Success)        { 
           PRINTF("ECSPI meets error during initialization. \r\n");
            vTaskSuspend(NULL);
       }
        masterXfer.txData   = masterTxData;
        masterXfer.rxData   = masterRxData;
        masterXfer.dataSize = ECSPI_TRANSFER_SIZE;
        masterXfer.channel  = ECSPI_MASTER_TRANSFER_CHANNEL;        /*Start master transfer*/ 
       status = ECSPI_RTOS_Transfer(&master_rtos_handle, &masterXfer);
        if (status != kStatus_Success)
        {            
PRINTF("ECSPI transfer completed with error. \r\n\r\n");
            vTaskSuspend(NULL); 
       }        /* Compare Tx and Rx data. */ 
       for (i = 0; i < ECSPI_TRANSFER_SIZE; i++) 
       {            if (masterTxData[i] != masterRxData[i]) 
           {                break;           
 }        
}        
if (ECSPI_TRANSFER_SIZE == i)  
      {            
PRINTF("\r\nFreeRTOS ECSPI loopback test pass!");    
    }        else    
    {            PRINTF("\r\nFreeRTOS ECSPI loopback test fail!");     
   }    }  
  vTaskSuspend(NULL);
} 
					
				
		
 igorpadykov
		
			igorpadykov
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi Wen
there is ECSPI_Deinit() function in ecspi_loopback.c, one can check if
it is called somewhere.
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
