This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5718: DSP核使用SPI通信失败

Part Number: AM5718
Other Parts Discussed in Thread: SYSBIOS

使用Linux端操作SPI1回环通信测试没问题,而通过DSP端配置SPI1调用SPI_transfer一直卡住在这里。

看了论坛上很多帖子,没有找到如何配置SPI这方面的内容。

以下是部分配置程序:

#ifndef BARE_METAL
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Diags.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/Assert.h>
#include <xdc/runtime/Registry.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <ti/ipc/MultiProc.h>
#endif

#include <stdio.h>
#include <ti/csl/example/utils/common/inc/app_utils.h>
#include <ti/csl/soc.h>
#include <ti/csl/hw_types.h>

/* TI-RTOS Header files */
#include <ti/drv/gpio/GPIO.h>
#include <ti/drv/gpio/soc/GPIO_soc.h>

#include <ti/drv/gpio/test/led_blink/src/GPIO_log.h>
#include <ti/drv/gpio/test/led_blink/src/GPIO_board.h>

#include <ti/board/board.h>

#include <ti/osal/osal.h>
/* SPI Header files */
#include <ti/drv/spi/SPI.h>
#include <ti/csl/csl_mcspi.h>
#include <ti/drv/spi/soc/SPI_soc.h>
#include <ti/drv/spi/src/SPI_osal.h>

/* ========================================================================== */
/* Macros */
/* ========================================================================== */

#define McSPI_DATA_COUNT 50U // Data Count Transaction
#define MCSPI_INSTANCE 0

/* clock callback function */
void clockFxn(UArg);

/**********************************************************************
************************** Global Variables **************************
**********************************************************************/
volatile uint32_t gpio_intr_triggered = 0;
uint32_t gpioBaseAddr;
uint32_t gpioPin;
uint8_t gRxBuffer[McSPI_DATA_COUNT];
uint8_t gTxBuffer[McSPI_DATA_COUNT];

SPI_Handle gSpiHandle;

void SPI_callback(SPI_Handle handle, SPI_Transaction *transaction);
/* SPI parameters structure Master mode*/
SPI_Params gSpiParams = {
SPI_MODE_BLOCKING , /* transferMode */
SemaphoreP_WAIT_FOREVER,/* transferTimeout */
NULL, /* transferCallbackFxn */
SPI_MASTER, /* mode */
1000000, /* bitRate */
8, /* dataSize */
SPI_POL0_PHA0, /* frameFormat */
NULL /* custom */
};


static void McSPIInitializeBuffers(void)
{
uint32_t index = 0;

for (index = 0; index < McSPI_DATA_COUNT; index++)
{
/* Initialize the gTxBuffer McSPI1 with a known pattern of data */
gTxBuffer[index] = index;
/* Initialize the gRxBuffer McSPI1 with 0 */
gRxBuffer[index] = (uint32_t) 0;
}
}

static int32_t McSPIVerifyData(void)
{
uint32_t index = 0;
int32_t retVal = 0;

for (index = 0; index < McSPI_DATA_COUNT; index++)
{
if(gRxBuffer[index] != gTxBuffer[index])
{
retVal = -1;
break;
}
}

return retVal;
}

void SPI_callback(SPI_Handle handle, SPI_Transaction *transaction)
{
System_printf("call back...\r\n");
}

/*
* ======== test function ========
*/
void spi_test(UArg arg0, UArg arg1)
{
/* GPIO initialization */

int32_t retVal;
uint32_t index = 0;
SPI_Transaction transaction;
System_printf("spi task...\r\n");
System_printf("SPI_open...");
gSpiHandle = SPI_open(MCSPI_INSTANCE, &gSpiParams);
if(gSpiHandle == NULL)
{
System_printf("\nError opening MCSPI driver\n");
}
System_printf("OK\r\n");
McSPIInitializeBuffers();
System_printf("gTxBuffer:",gTxBuffer[index]);
for(index = 0; index < McSPI_DATA_COUNT; index++)
{
System_printf("%d ",gTxBuffer[index]);
}
System_printf("\r\n",gTxBuffer[index]);

transaction.count = McSPI_DATA_COUNT;
transaction.txBuf = gTxBuffer;
transaction.rxBuf = gRxBuffer;
System_printf("SPI_transfer...");
retVal = SPI_transfer(gSpiHandle, &transaction);
if(retVal == 0)//false
{
System_printf("ERROR\r\n");
}
else
{
System_printf("OK\r\n");
}

retVal = McSPIVerifyData();
if(retVal != 0)
{
System_printf("retVal = %d\r\n",retVal);
}
else
{
System_printf("retVal = %d\r\n",retVal);
}
System_printf("gRxBuffer:%s\r\n",gRxBuffer);
System_printf("SPI_transfer...");
SPI_close(gSpiHandle);
System_printf("OK\r\n");
while (1) {
System_printf("spi %d...\r\n",Clock_getTicks());
Task_sleep(1000);
}

}

void led_test(UArg arg0, UArg arg1)
{
/* GPIO initialization */
System_printf("led task...\r\n");
GPIO_write(0, GPIO_PIN_VAL_HIGH);//熄灭

while (1) {
GPIO_toggle(0);
//System_printf("led %d...\r\n",Clock_getTicks());
Task_sleep(1000);
}

}

extern void TimerFxn(UArg arg);
#ifndef BARE_METAL
/*
* ======== main ========
*/
int main(void)
{
Task_Handle task ;
Task_Params task_led_param;
Error_Block eb;
Error_init(&eb);

PinmuxMCSPIConfig();
PinmuxGpioLedConfig(0);

SPI_init();
GPIO_init();

task = Task_create(spi_test, NULL, &eb);
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}

task = Task_create(led_test, NULL, &eb);
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}

System_printf("task create\n");
/* Start BIOS */

BIOS_start();
return (0);
}
#endif

void clockFxn(UArg arg)
{
//Clock_tick();
}

void TimerFxn(UArg arg)
{
Clock_tick();
// GPIO_toggle(0);
//asm(" NOP");
}

驱动配置如下:

void PinmuxMCSPIConfig()
{


/* SPI1_SCLK */
HW_WR_REG32((CSL_MPU_CORE_PAD_IO_REGISTERS_REGS + CTRL_CORE_PAD_SPI1_SCLK),
0x00050000);

/* SPI1_D0 */
HW_WR_REG32((CSL_MPU_CORE_PAD_IO_REGISTERS_REGS + CTRL_CORE_PAD_SPI1_D0),
0x00050000);

/* SPI1_D1 */
HW_WR_REG32((CSL_MPU_CORE_PAD_IO_REGISTERS_REGS + CTRL_CORE_PAD_SPI1_D1),
0x00060000);

/* SPI1_CS0 */
HW_WR_REG32((CSL_MPU_CORE_PAD_IO_REGISTERS_REGS + CTRL_CORE_PAD_SPI1_CS0),
0x00060000);

}

能帮我看看是哪里出了问题吗?

提前谢谢了!