W5500 SPI DMA using STM32 HAL

I want to implement SPI with DMA for the W5500 chip using HAL in my existing project (which is written based on HAL). I found an example given in SPL. Likewise, I wasted lots of energy finding examples in HAL but failed. At last, I try to migrate SPL into HAL. But it is not working anymore.
Please help me to migrate SPL to HAL.

NB: without DMA it is working very fine.

MCU: STM32F401RC
Code:
My Implementation-

// this function is using for bothe read & write
void W5500_readBurstDma(uint8_t buff, uint16_t len)
{
/
SPI1 DMA Init /
/
SPI1_RX Init /
hdma_spi1_rx.Instance = DMA2_Stream0;
hdma_spi1_rx.Init.Channel = DMA_CHANNEL_3;
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi1_rx.Init.Mode = DMA_NORMAL;
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_HIGH;
hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
/
SPI1_TX Init */
hdma_spi1_tx.Instance = DMA2_Stream3;
hdma_spi1_tx.Init.Channel = DMA_CHANNEL_3;
hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi1_tx.Init.Mode = DMA_NORMAL;
hdma_spi1_tx.Init.Priority = DMA_PRIORITY_HIGH;
hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx);
W5500_select();
HAL_SPI_DMAResume(&hspi1);
__HAL_SPI_ENABLE(&hspi1);
HAL_DMA_Start(&hdma_spi1_tx, (uint32_t )buff, ( uint32_t )&hspi1.Instance->DR, len);
HAL_DMA_Start(&hdma_spi1_rx, ( uint32_t )&hspi1.Instance->DR,(uint32_t )buff, len);
W5500_deselect();
HAL_DMA_Abort(&hdma_spi1_tx);
HAL_DMA_Abort(&hdma_spi1_rx);
HAL_SPI_DMAPause(&hspi1);
__HAL_SPI_DISABLE(&hspi1);
}

SPL Example:
Visit the link:

  1. Implementing full duplex communication via SPI DMA on STM32F2xx or STM32F4xx
  2. w5100s_an_dma_v100e.pdf

SPI & DMA Configuration:


Pin Connection:
SRM32 - W5500
PA5 - SCK
PA6 - MISO
PA7 - MOSI
PC4 - CS
PB10 - IRQ

Thanks in advance

Hello, Team WIZnet.

Please refer to this repository for an example of the HAL configuration for the Nucleo board and SPI DMA.

Although this board uses the ST32F103 MCU, there shouldn’t be significant differences in the SPI DMA configuration. If you encounter any difficulties during the process, please let us know again.

1 Like

Hi scarlet,

Thanks for your reply.

I have implemented SPI DMA according to the example you have provided. It is working, but not completely. I am able to configure the net information for the TCP server by using SPI DMA. Now the server is in listening mode and ready to accept the connection request. When I send a connection request from the computer TCP client application, the client application shows it is connected. In the meantime, the MCU is reading the status of the w5500 chip, the status value is 22 which is expected. As you know, it means the connection is successfully established. But immediately the MCU is getting hanged.

Now I am requesting you, please help me to overcome this problem.

Note: One thing I want to mention again. It is working fine without DMA.

Thanks in advance

Hi scarlet,

Thanks for your help.

The problem is resolved. Now it is working fine.

I apologize for the delayed confirmation. It’s fortunate that the problem has been resolved. If you have any other difficulties, please visit the forum anytime.