SPI DMA bug on the P4

RogerDavisWork
Posts: 10
Joined: Thu May 02, 2024 4:33 pm

SPI DMA bug on the P4

Postby RogerDavisWork » Fri Jan 10, 2025 2:21 pm

I am using the ESP32-P4-Function-EV-Board and have an application running that uses the SPI in slave mode. I am compiling it using the IDF 5.4 library and tools. It works fine in non-DMA mode with 64-byte packets for large transfers. I have a CRC on it and the CRC is good in this mode.

I am now trying to get the DMA working and it generally works for 512-byte packets for many packets, but once in a while I receive a bad packet. This makes it impossible to send a large transfer without at least one or two packets being bad.

I have followed the directions to ensure that the buffers and size value are on 64-bit boundaries, and as I mentioned, most of the packets arrive correctly.

Code: Select all

// SPI DMA buffers and lengths must be aligned to 64-but boundaries
#define ALIGNMENT_64Bit 64
__attribute__((aligned(ALIGNMENT_64Bit))) SRE_Packet_t workingSendPacket;
__attribute__((aligned(ALIGNMENT_64Bit))) SRE_Packet_t workingRcvPacket;
__attribute__((aligned(ALIGNMENT_64Bit))) const size_t SPIBufferSize = SRE_SPI_PACKET_SIZE;
Map file:

Code: Select all

 .srodata.SPIBufferSize
                0x00000000        0x4 esp-idf/SPI_task/libSPI_task.a(SPI_task.c.obj)
 .bss.workingRcvPacket
                0x4ff510c0       0x40 esp-idf/SPI_task/libSPI_task.a(SPI_task.c.obj)
                0x4ff510c0                workingRcvPacket
 .bss.workingSendPacket
                0x4ff51100       0x40 esp-idf/SPI_task/libSPI_task.a(SPI_task.c.obj)
                0x4ff51100                workingSendPacket
I have attached a screenshot from a comparison tool that shows an example where we receive a bad packet.
As you can see, this is not a noise problem but looks more like a driver problem. I am sending a repeating pattern so that I can see the errors. The slash marks in the picture delineate the beginning of the actual data after my header. The left side is the packet that was sent. The packet on the right is the bad packet that was received on the P4.

The circle on the left shows 3 bytes that are missing from the packet on the right. The circle on the right side shows 3 bytes that were inserted incorrectly into the buffer and repeated from the 3 bytes before it.

I am fairly certain that this is some kind of hardware or library issue. As I mentioned, almost all of the packets arrive correctly and this only happens often enough to disallow large transfers. I am trying to send 200K and this happens about one to three times in that transfer.

I should also mention that in IDF 5.2.2, there is code to disallow SPI DMA transfer with a note about IDF-7503. But this code is changed in IDF 5.4, so I assume that it is now allowed:

Code: Select all

    
    if (use_dma) {
#if CONFIG_IDF_TARGET_ESP32P4
        abort();    //will supported in IDF-7503
#endif
See attachment showing the issue.
Attachments
DMA Failure Annotated.png
DMA Failure Annotated.png (428.31 KiB) Viewed 1018 times

RogerDavisWork
Posts: 10
Joined: Thu May 02, 2024 4:33 pm

Re: SPI DMA bug on the P4

Postby RogerDavisWork » Fri Jan 10, 2025 3:42 pm

I should add that the buffers in the map above are set up for 64 bytes in this map file.
In the version that fails with DMA, they are set for 512 bytes.

Who is online

Users browsing this forum: Amazon [Bot], ChatGPT-User, Qwantbot and 1 guest