Hi,
@jachen @Trumany @kevinFFF @DaneLLL @WayneWWW
Who can help me answer my questions? Thank you in advance.
I update my AGX Xavier devkit from r32.7.3 to r35.3.1. Then I meet two bugs for SPI communication of SPE-FW in r35.3.1.
Bug 1: The SPI clock frequency cannot be set correctly.
#define SPI_TEST_CLOCK_RATE 12000000 //12MHz
Based on the above setting, the SPI clock frequency should be 12MHz. But I check the SCK line by my scope. I find that the SPI clock frequency is about 1.2MHz. That is to say, the true value is one tenth of the set value. Other settings also follow this pattern , such as 30M—>3M, 5M—> 0.5M.
Bug 2: The SPI DMA mode do not work correctly.
When I test the SPI of SPE-FW with DMA mode, I meet the similar bug which I meet in r32.7.3. It should be mentioned that the PIO mode of SPI works fine in r35.3.1.
My test code in spi_app.c file is
#define SPI_TEST_CONTROLLER spi_ctlr_spi2
#define SPI_TEST_CLOCK_RATE 12000000
#define SPI_TEST_DMA_TX_CHANNEL 2
#define SPI_TEST_DMA_RX_CHANNEL 3
#define SPI_TEST_RETRIES 50000000
#define SPI_TEST_DELAY 2000
#define SPI_buffer 512
char data_to_send[SPI_buffer];
char data_to_read[SPI_buffer];
extern int en_spi_flag;
static void spi_test_task(void *pvParameters)
{
int ret, count;
(void)pvParameters; /* unused */
// const uint8_t data_to_send[] = {0xab, 0xcd};
// uint8_t data_to_read[] = {0x0, 0x0};
for(int k=0; k < 10; k++)
{
data_to_send[k]=k;
}
struct spi_client_setting spi_test_device[] = {
{
.chip_select = 0,
.set_rx_tap_delay = false,
.spi_max_clk_rate = SPI_TEST_CLOCK_RATE,
.spi_no_dma = false,
}
};
struct spi_master_init master_test_conf[] = {
{
.dma_id = &gpcdma_id_aon,
.dma_chans.tx = SPI_TEST_DMA_TX_CHANNEL,
.dma_chans.rx = SPI_TEST_DMA_RX_CHANNEL,
.spi_max_clk_rate = SPI_TEST_CLOCK_RATE,
.dma_slave_req = GPCDMA_AO_CHANNEL_CH0_CSR_0_REQ_SEL_SPI,
}
};
ret = spi_init(&SPI_TEST_CONTROLLER, master_test_conf);
if (ret) {
printf("spi_test: master init failed\r\n");
return;
}
ret = spi_client_setup(&SPI_TEST_CONTROLLER, spi_test_device);
if (ret) {
printf("spi_test: couldn't setup SPI device\r\n");
return;
}
struct spi_xfer xfer = {
.flags = BIT(TEGRA_SPI_XFER_FIRST_MSG) |
BIT(TEGRA_SPI_XFER_LAST_MSG),
.tx_buf = data_to_send,
.rx_buf = data_to_read,
.len = ARRAY_SIZE(data_to_read),
.chip_select = 0,
.tx_nbits = TEGRA_SPI_NBITS_SINGLE,
.rx_nbits = TEGRA_SPI_NBITS_SINGLE,
.bits_per_word = 8,
.mode = TEGRA_SPI_MODE_0 | TEGRA_SPI_LSBYTE_FIRST,
};
while (1)
{
if (en_spi_flag == 1)
{
for(int k=0; k < 10; k++)
{
data_to_send[k]=k;
}
for (count = 0; count < SPI_TEST_RETRIES; count++) {
ret = spi_transfer(&SPI_TEST_CONTROLLER, &xfer);
if (ret)
printf("SPI TX/RX failed\r\n");
else {
if (!memcmp(data_to_read, data_to_send,
ARRAY_SIZE(data_to_read)))
printf("SPI test successful~\r\n");
else
printf("Received incorrect data\r\n");
}
rtosTaskDelay(SPI_TEST_DELAY);
}
break;
}
}
rtosTaskDelete(NULL);
}
Where extern int en_spi_flag;
is a flag in the IVC task to enable the SPI task after successful the Linux kernel initialization. After the SPI task works, I get the following error from the debug UART:
SPI TX/RX failed