Other Parts Discussed in Thread: MMWAVEICBOOST, UNIFLASH
Tool/software: Code Composer Studio
I'm trying to test SPI function on IWR6843. After finished pinmux settings, I modified the mss_main.c code of 3D people counting and added the SPI test code based on sample code in the path: C:\ti\mmwave_sdk_03_03_00_03\packages\ti\drivers\spi\test\xwr68xx
I already done SPI_init(), SPI_Params_init(¶ms);
But there were many errors occurred. Please explain (something like 3D_people_count_68xx_mss.xe4f not built, other errors and help me solve it.
Here's the code I used
void Test_spiSlaveWithPC(void) { SPI_Params params; SPI_Handle handle; spiTestMsg* pTestMsg; uint16_t retry=0; uint16_t msgSeqNo = 0; uint32_t loop; volatile uint32_t cycles; float throughput; uint32_t totalLoop; /* Setup the default SPI Parameters */ SPI_Params_init(¶ms); params.mode = SPI_SLAVE; params.frameFormat = SPI_POL0_PHA1; params.pinMode = SPI_PINMODE_4PIN_CS; params.shiftFormat = SPI_MSB_FIRST; /* When communicating with PC through FTDI, it is difficult to toggle CS for every two bytes, hence set csHold to 1. In this mode, the highest working SPI clock is 2MHz */ params.csHold = 1; /* Enable DMA and set DMA channels */ params.dmaEnable = 1; params.dmaHandle = gDmaHandle; params.u.slaveParams.dmaCfg.txDmaChanNum =1U; params.u.slaveParams.dmaCfg.rxDmaChanNum =0U; handle = SPI_open(0, ¶ms); if (handle == NULL) { System_printf("Error: Unable to open the SPI Instance\n"); MCPI_setFeatureTestResult ("SPI Slave with PC ", MCPI_TestResult_FAIL); return; } memset((void *)txBuf, 0x55, SPI_TEST_MSGLEN); System_printf("Debug: SPI Instance %p has been reopened in SLAVE mode successfully for 4pin FTDI testing\n", handle); gXWR1xxxSlaveReady = true; while(1) { Test_spiRead(handle, SPI_TEST_MSGLEN, (void *)rxBuf, 0U); pTestMsg = (spiTestMsg*)&rxBuf[0]; if(pTestMsg->magicNumber != SWAP_BYTES(MAGIC_NUMBER)) { System_printf("incorrect magic Number: 0x%x 0x%x\n", pTestMsg->magicNumber, SWAP_BYTES(MAGIC_NUMBER)); continue; } if((pTestMsg->dataLen != SWAP_BYTES(SPI_TEST_SYNC_MSGLEN)) || (pTestMsg->seqNo != 0)) { System_printf("incorrect datalen(%d), seqNo= %d\n", pTestMsg->dataLen, pTestMsg->seqNo); continue; } /* Got the correct sync message, send back the message */ msgSeqNo = SWAP_BYTES(pTestMsg->seqNo); pTestMsg->seqNo = SWAP_BYTES(msgSeqNo+1); /* Read two byte , send it back */ Test_spiWrite(handle, SPI_TEST_MSGLEN, (void *)pTestMsg, 0U); break; } /* Save the Sync message for re-sent */ memcpy((void *)txBuf, (void *)pTestMsg, SPI_TEST_MSGLEN); /* Got the Sync message, waiting for next test message */ msgSeqNo += 2; /* Test loop count from first 16 bits of Sync message */ loop = pTestMsg->data[0] * 256 + pTestMsg->data[1] ; System_printf("Test loop=%d, bufferLen=%d\n", loop, SPI_TEST_MSGLEN); totalLoop = loop; while(loop) { /* Read two byte , send it back */ Test_spiRead(handle, SPI_TEST_MSGLEN, (void *)rxBuf, 0U); if(pTestMsg->magicNumber != SWAP_BYTES(MAGIC_NUMBER)) { continue; } if((pTestMsg->seqNo == 0) && (pTestMsg->dataLen == SWAP_BYTES(SPI_TEST_SYNC_MSGLEN))) { /* Re-sent the Sync message */ Test_spiWrite(handle, SPI_TEST_MSGLEN, (void *)txBuf, 0U); continue; } /* Receive Last message */ if(pTestMsg->seqNo == SWAP_BYTES(msgSeqNo - 2)) { Test_spiWrite(handle, SPI_TEST_MSGLEN, (void *)txBuf, 0U); retry++; continue; } /* Incorrect seqNo, drop the message */ if(pTestMsg->seqNo != SWAP_BYTES(msgSeqNo)) { retry++; continue; } if(loop == totalLoop) { // Start the counter after receive the first message Test_benchmarkStart(0); } retry = 0; loop--; /* Receive the message with correct header, increment the seq Number */ pTestMsg->seqNo = SWAP_BYTES(SWAP_BYTES(pTestMsg->seqNo) + 1); Test_spiWrite(handle, SPI_TEST_MSGLEN, (void *)pTestMsg, 0U); msgSeqNo += 2; } // Stop the counter cycles = Test_benchmarkStop(0); // Calculate and print the count throughput = 8.0 * SPI_TEST_MSGLEN * totalLoop * VBUSP_FREQ / cycles; System_printf("Debug: throughput overall = %.2f Mbps\n", throughput); MCPI_setFeatureTestResult ("SPI Slave with PC ", MCPI_TestResult_PASS); } /** * @b Description * @n * System Initialization Task which initializes the various * components in the system. * * @retval * Not Applicable. */ static void Pcount3DDemo_initTask(UArg arg0, UArg arg1) { int32_t errCode; MMWave_InitCfg initCfg; UART_Params uartParams; Task_Params taskParams; Semaphore_Params semParams; DPM_InitCfg dpmInitCfg; DMA_Params dmaParams; DMA_Handle dmaHandle; SPI_Params params; SPI_Handle handle; SOC_Handle socHandle; spiTestMsg* pTestMsg; int32_t retVal = 0; /* Get SOC driver Handle */ socHandle = (SOC_Handle) arg0; DPC_ObjectDetectionRangeHWA_InitParams objDetInitParams; // int32_t i; /* Debug Message: */ System_printf("Debug: Launched the Initialization Task\n"); /* Initialize MCPI logger framework */ MCPI_Initialize (); /***************************************************************************** * Initialize the mmWave SDK components: *****************************************************************************/ /* Initialize the UART */ UART_init(); /* Initialize the DMA for UART */ DMA_init (); /* Open DMA driver instance 0 for SPI test */ gDmaHandle = DMA_open(0, &dmaParams, &retVal); if(gDmaHandle == NULL) { printf("Open DMA driver failed with error=%d\n", retVal); return; } /* Initialize the SPI */ SPI_init(); /* Setup the default SPI Parameters */ SPI_Params_init(¶ms); /************************************************************************** * Test: One instace API test - SPIA **************************************************************************/ Test_spiAPI_oneInstance(0); System_printf("Debug: Finished API Test for SPIA!\n"); /************************************************************************** * Test: One instace API test - SPIB **************************************************************************/ Test_spiAPI_oneInstance(1); System_printf("Debug: Finished API Test for SPIB!\n"); /************************************************************************** * Test: two instaces API test - SPIA & SPIB **************************************************************************/ Test_spiAPI_twoInstance(); System_printf("Debug: Finished API Test for SPIA + SPIB!\n"); if(gXWR1xxxSlaveWithFTDITest) { /* Enable output control for SPIA in 4Pin mode */ if(SOC_SPIOutputCtrl(socHandle, 0U, 0U, &errCode) < 0) { /* Debug Message: */ System_printf ("Debug: SOC_SPIOutputCtrl failed with Error [%d]\n", errCode); return; } Test_spiSlaveWithPC(); } /* Open the DMA Instance */ DMA_Params_init(&dmaParams); dmaHandle = DMA_open(0, &dmaParams, &errCode); if (dmaHandle == NULL) { printf ("Error: Unable to open the DMA Instance [Error code %d]\n", errCode); return; } /* Initialize the GPIO */ GPIO_init(); /* Initialize the Mailbox */ Mailbox_init(MAILBOX_TYPE_MSS); /* Platform specific configuration */ Pcount3DDemo_platformInit(&gMmwMssMCB.cfg.platformCfg); /***************************************************************************** * Open the mmWave SDK components: *****************************************************************************/ /* Setup the default UART Parameters */ UART_Params_init(&uartParams); uartParams.clockFrequency = gMmwMssMCB.cfg.platformCfg.sysClockFrequency; uartParams.baudRate = gMmwMssMCB.cfg.platformCfg.commandBaudRate; uartParams.isPinMuxDone = 1; /* Open the UART Instance */ gMmwMssMCB.commandUartHandle = UART_open(0, &uartParams); if (gMmwMssMCB.commandUartHandle == NULL) { Pcount3DDemo_debugAssert (0); return; } /* Setup the default UART Parameters */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.clockFrequency = gMmwMssMCB.cfg.platformCfg.sysClockFrequency; uartParams.baudRate = gMmwMssMCB.cfg.platformCfg.loggingBaudRate; uartParams.isPinMuxDone = 1U; uartParams.dmaHandle = dmaHandle; uartParams.txDMAChannel = UART_DMA_TX_CHANNEL; uartParams.rxDMAChannel = UART_DMA_RX_CHANNEL; /* Open the Logging UART Instance: */ gMmwMssMCB.loggingUartHandle = UART_open(1, &uartParams); if (gMmwMssMCB.loggingUartHandle == NULL) { System_printf("Error: Unable to open the Logging UART Instance\n"); Pcount3DDemo_debugAssert (0); return; } /* Create binary semaphores which is used to signal DPM_start/DPM_stop/DPM_ioctl is done * to the sensor management task. The signalling (Semaphore_post) will be done * from DPM registered report function (which will execute in the DPM execute task context). */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; gMmwMssMCB.DPMstartSemHandle = Semaphore_create(0, &semParams, NULL); gMmwMssMCB.DPMstopSemHandle = Semaphore_create(0, &semParams, NULL); gMmwMssMCB.DPMioctlSemHandle = Semaphore_create(0, &semParams, NULL); /* Open EDMA driver */ Pcount3DDemo_edmaInit(&gMmwMssMCB.dataPathObj, DPC_OBJDET_R4F_EDMA_INSTANCE); /* Use EDMA instance 0 on MSS */ Pcount3DDemo_edmaOpen(&gMmwMssMCB.dataPathObj, DPC_OBJDET_R4F_EDMA_INSTANCE); Pcount3DDemo_hwaInit(&gMmwMssMCB.dataPathObj); Pcount3DDemo_hwaOpen(&gMmwMssMCB.dataPathObj, gMmwMssMCB.socHandle); /***************************************************************************** * mmWave: Initialization of the high level module *****************************************************************************/ /* Initialize the mmWave control init configuration */ memset ((void*)&initCfg, 0 , sizeof(MMWave_InitCfg)); /* Populate the init configuration: */ initCfg.domain = MMWave_Domain_MSS; initCfg.socHandle = gMmwMssMCB.socHandle; initCfg.eventFxn = Pcount3DDemo_eventCallbackFxn; initCfg.linkCRCCfg.useCRCDriver = 1U; initCfg.linkCRCCfg.crcChannel = CRC_Channel_CH1; initCfg.cfgMode = MMWave_ConfigurationMode_FULL; initCfg.executionMode = MMWave_ExecutionMode_ISOLATION; /* Initialize and setup the mmWave Control module */ gMmwMssMCB.ctrlHandle = MMWave_init (&initCfg, &errCode); if (gMmwMssMCB.ctrlHandle == NULL) { /* Error: Unable to initialize the mmWave control module */ System_printf ("Error: mmWave Control Initialization failed [Error code %d]\n", errCode); Pcount3DDemo_debugAssert (0); return; } System_printf ("Debug: mmWave Control Initialization was successful\n"); /* Synchronization: This will synchronize the execution of the control module * between the domains. This is a prerequiste and always needs to be invoked. */ if (MMWave_sync (gMmwMssMCB.ctrlHandle, &errCode) < 0) { /* Error: Unable to synchronize the mmWave control module */ System_printf ("Error: mmWave Control Synchronization failed [Error code %d]\n", errCode); Pcount3DDemo_debugAssert (0); return; } System_printf ("Debug: mmWave Control Synchronization was successful\n"); // Create a task to do SPI /* Task_Params_init(&taskParams); taskParams.stackSize = 6*1024; taskParams.arg0 = (UArg)socHandle; Task_create(Test_initTask, &taskParams, NULL);*/ /***************************************************************************** * Launch the mmWave control execution task * - This should have a higher priroity than any other task which uses the * mmWave control API *****************************************************************************/ Task_Params_init(&taskParams); taskParams.priority = MMWDEMO_MMWAVE_CTRL_TASK_PRIORITY; taskParams.stackSize = 2800; gMmwMssMCB.taskHandles.mmwaveCtrl = Task_create(Pcount3DDemo_mmWaveCtrlTask, &taskParams, NULL); /***************************************************************************** * Create a task to do DMA based UART data transfer *****************************************************************************/ /* Create a binary semaphore for application task to pend */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; gMmwMssMCB.uartTxSemHandle = Semaphore_create(0, &semParams, NULL); Task_Params_init(&taskParams); taskParams.priority = MMWDEMO_UARTTX_TASK_PRIORITY; taskParams.stackSize = 800; Task_create(MmwDemo_uartTxTask, &taskParams, NULL); /***************************************************************************** * Initialization of the DPM Module: *****************************************************************************/ memset ((void *)&objDetInitParams, 0, sizeof(DPC_ObjectDetectionRangeHWA_InitParams)); /* Note this must be after Pcount3DDemo_dataPathOpen() above which opens the hwa */ objDetInitParams.L3ramCfg.addr = (void *)&gMmwL3[0]; objDetInitParams.L3ramCfg.size = sizeof(gMmwL3); objDetInitParams.CoreLocalRamCfg.addr = &gDPCTCM[0]; objDetInitParams.CoreLocalRamCfg.size = sizeof(gDPCTCM); objDetInitParams.edmaHandle = gMmwMssMCB.dataPathObj.edmaHandle; objDetInitParams.hwaHandle = gMmwMssMCB.dataPathObj.hwaHandle; /* DPC Call-back config */ objDetInitParams.processCallBackFxn.processInterFrameBeginCallBackFxn = Pcount3DDemo_DPC_ObjectDetection_processInterFrameCallBackFxn; objDetInitParams.processCallBackFxn.processFrameBeginCallBackFxn = Pcount3DDemo_DPC_ObjectDetection_processFrameBeginCallBackFxn; /* Setup the configuration: */ memset ((void *)&dpmInitCfg, 0, sizeof(DPM_InitCfg)); dpmInitCfg.socHandle = gMmwMssMCB.socHandle; dpmInitCfg.ptrProcChainCfg = &gDPC_ObjDetRangeHWACfg;; dpmInitCfg.instanceId = DPC_OBJDET_R4F_INSTANCEID; dpmInitCfg.domain = DPM_Domain_DISTRIBUTED; dpmInitCfg.reportFxn = Pcount3DDemo_DPC_ObjectDetection_reportFxn; dpmInitCfg.arg = &objDetInitParams; dpmInitCfg.argSize = sizeof(DPC_ObjectDetectionRangeHWA_InitParams); /* Initialize the DPM Module: */ gMmwMssMCB.objDetDpmHandle = DPM_init (&dpmInitCfg, &errCode); if (gMmwMssMCB.objDetDpmHandle == NULL) { System_printf ("Error: Unable to initialize the DPM Module [Error: %d]\n", errCode); Pcount3DDemo_debugAssert (0); return; } /* Synchronization: This will synchronize the execution of the datapath module * between the domains. This is a prerequiste and always needs to be invoked. */ while (1) { int32_t syncStatus; /* Get the synchronization status: */ syncStatus = DPM_synch (gMmwMssMCB.objDetDpmHandle, &errCode); if (syncStatus < 0) { /* Error: Unable to synchronize the framework */ System_printf ("Error: DPM Synchronization failed [Error code %d]\n", errCode); Pcount3DDemo_debugAssert (0); return; } if (syncStatus == 1) { /* Synchronization acheived: */ break; } /* Sleep and poll again: */ Task_sleep(1); } #ifdef TRACKERPROC_EN /***************************************************************************** * Create a task to run tracker DPU at lower priority than HWA DPC *****************************************************************************/ /* Create a binary semaphore for application task to pend */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; gMmwMssMCB.trackerDPUSemHandle = Semaphore_create(0, &semParams, NULL); Task_Params_init(&taskParams); taskParams.priority = MMWDEMO_TRACKERDPU_TASK_PRIORITY; taskParams.stackSize = 7*1024; Task_create(MmwDemo_trackerDPUTask, &taskParams, NULL); #endif /* Launch the DPM Task */ Task_Params_init(&taskParams); taskParams.priority = MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY; taskParams.stackSize = 7*1024; gMmwMssMCB.taskHandles.objDetDpmTask = Task_create(mmwDemo_mssDPMTask, &taskParams, NULL); /***************************************************************************** * Initialize the Profiler *****************************************************************************/ Cycleprofiler_init(); /***************************************************************************** * Initialize the CLI Module: *****************************************************************************/ Pcount3DDemo_CLIInit(MMWDEMO_CLI_TASK_PRIORITY); return; } int main(void) { /*======================================= * Setup the PINMUX to bring out the MibSpiA *=======================================*/ /* NOTE: Please change the following pin configuration according to EVM used for the test */ /* SPIA_MOSI */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PIND13_PADAD, SOC_XWR68XX_PIND13_PADAD_SPIA_MOSI); /* SPIA_MISO */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE, SOC_XWR68XX_PINE14_PADAE_SPIA_MISO); /* SPIA_CLK */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE13_PADAF, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINE13_PADAF, SOC_XWR68XX_PINE13_PADAF_SPIA_CLK); /* SPIA_CS */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE15_PADAG, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINE15_PADAG, SOC_XWR68XX_PINE15_PADAG_SPIA_CSN); /* SPI_HOST_INTR - not used, reference code */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINP13_PADAA, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINP13_PADAA, SOC_XWR68XX_PINP13_PADAA_SPI_HOST_INTR); /*======================================= * Setup the PINMUX to bring out the MibSpiB *=======================================*/ /* NOTE: Please change the following pin configuration according to EVM used for the test */ /* Setup the PINMUX to bring out the MibSpiB */ Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF13_PADAH, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINF13_PADAH, SOC_XWR68XX_PINF13_PADAH_SPIB_MOSI); Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PING14_PADAI, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PING14_PADAI, SOC_XWR68XX_PING14_PADAI_SPIB_MISO); Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINF14_PADAJ, SOC_XWR68XX_PINF14_PADAJ_SPIB_CLK); Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINH14_PADAK, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINH14_PADAK, SOC_XWR68XX_PINH14_PADAK_SPIB_CSN); /* SPIB signals are connected to PMIC and XDS110 , unless the connection is removed on XWR16 EVM, SPI signals can not be enabled as output. */ #if 0 /* Enable output control for SPIB */ if(SOC_SPIOutputCtrl(socHandle, 1U, 1U, &errCode) < 0) { /* Debug Message: */ System_printf ("Debug: SOC_SPIOutputCtrl failed with Error [%d]\n", errCode); goto Exit; } #endif /* SPIA DMA and interrupt signals are muxed with other IPs in the SOC. * Map them to SPIA. */ if (SOC_selectDMARequestMapping(socHandle, SOC_MODULE_SPIA, &errCode) < 0) { /* Debug Message: */ System_printf ("Debug: SOC_selectDMARequestMapping (SPIA) failed with Error [%d]\n", errCode); goto Exit; } if (SOC_selectInterruptRequestMapping(socHandle, SOC_MODULE_SPIA, &errCode) < 0) { /* Debug Message: */ System_printf ("Debug: SOC_selectInterruptRequestMapping (SPIA) failed with Error [%d]\n", errCode); goto Exit; } /* Debug Message: */ System_printf ("**********************************************\n"); System_printf ("Debug: Launching the MMW Demo on MSS\n"); System_printf ("**********************************************\n"); /* Initialize the Task Parameters. */ Task_Params_init(&taskParams); gMmwMssMCB.taskHandles.initTask = Task_create(Pcount3DDemo_initTask, &taskParams, NULL); /* Start BIOS */ BIOS_start(); Exit: return 0; }