Skip to main content
ALE C.1
Associate II
November 19, 2021
Question

How to use HAL_SPI_Receive_DMA with dma1 and SPI6 ?

  • November 19, 2021
  • 9 replies
  • 4628 views

Hi,

I am currently working on the STM32H743 and i'm trying to bring data from SPI6 to a buffer in D2. As I have a lot of data to read i would like to use the DMA in order to transfer data without using the cpu. I don't understand whether I can use the DMA1/2 in order to do this or not.

For instance, with the SPI1, in D2, I can choose the DMA request as the DMA_REQUEST_SPI1_RX/TX. However the only request I can use with SPI6 is BDMA_REQUEST_SPI6_RX/TX. does it mean that I can only use the bdma here ?

However as BDMA is restricted to the D3 domain, it can't write data on a buffer in D2. How can I write it then ?

Do someone have a clear answer to this ? if so could you explain the required step i would need to implement the solution.

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
November 19, 2021

> However the only request I can use with SPI6 is BDMA_REQUEST_SPI6_RX/TX. does it mean that I can only use the bdma here ?

Yes, because SPI6 itself is in D3, too. DMA requests tend not to cross clock domains.

> However as BDMA is restricted to the D3 domain, it can't write data on a buffer in D2. How can I write it then ?

You simply can't, that's the constraint of the hardware.

Use a different SPI if SRAM4 does not fit your needs.

JW

MHana.1
Associate II
December 5, 2021

Hello,

I'm using the same microcontroller migrating from STM32F7 to STM32H743, so we are forced to use same pinout and peripherals. My issue is that when trying to use BDMA to send and receive using SPI6 it is not working although SPI6 alone is working perfectly. I tried to generate STM32CubeMx example and tried to modify it but it is not working. I'm using SPI6 with BDMA channel0 for Tx and channel1 for receiving. Also used DMAMUX2_Channel0 and DMAMUX2_Channel1 to handle DMA_SPI6_TX_REQUEST_ID and DMA_SPI6_RX_REQUEST_ID. I enabled BDMA, SPI6, GPIOG clocks and BDMA, SRAM4 in D3 domain. Is there any thing I missed or any working example on SPI6 and BDMA to use.

Thanks and regards.

waclawek.jan
Super User
December 5, 2021

Be more specific with "not working".

Are the buffers in SRAM4?

Read out and check/post content of relevant SPI, DMA, DMAMUX and GPIO registers.

JW

MHana.1
Associate II
December 6, 2021

Thanks for your response.

I started to modify the example I generated by STM32CubeMX and started to send SPI using DMA but it takes about 30 mSec to send. I'm trying to solve this issue and will check my code. I'm thankful if there any advise from you.

MHana.1
Associate II
December 6, 2021

Yes the buffers are in SRAM4.

waclawek.jan
Super User
December 6, 2021

> it takes about 30 mSec to send

And why is this unexpected? What is the baudrate? Have you observed the SPI signals using oscilloscope/LA?

JW

MHana.1
Associate II
December 9, 2021

Dears,

the delay was due to another waiting in code as it is a legacy code. The BDMA is sending and receiving perfectly. my missed point was the needed actions on SPI when sending with BDMA so I used the generated example after modifications as reference. Thanks for your help.

GCava.2
Visitor II
June 21, 2022

Hello MHana.1,

which is the example code that you considered? I have the same situation, in fact I'm using SPI6 with BDMA channel0 for Tx and channel1 for receiving. I don't understand how set DMAMUX2_Channel0 and DMAMUX2_Channel1 to handle DMA_SPI6_TX_REQUEST_ID and DMA_SPI6_RX_REQUEST_ID.

Have u any problems to share your code, in which I can get ideas?

Thanks and regards.

MHana.1
Associate II
June 21, 2022

Hello GCava.2,

Attached my test code.

GCava.2
Visitor II
June 22, 2022

Hi MHana.1,

I took a look at the code, i don't understand the presence of PG9 as external interrupt. Also, the togglepin PE5 which means?

Do u have also test SPI6 as Slave?

Thanks!!

MHana.1
Associate II
June 22, 2022

Hi GCava.2,

PG9 and toggling PE5 to test something related to my application. What do you mean by "Do u have also test SPI6 as Slave?", do you mean using my board as an SPI slave?. I did not use it as a slave I only used it as master with BDMA to communicate with SLAVE chip. But I think you can modify the example attached above to do so.

Thanks

GCava.2
Visitor II
June 23, 2022

Hi @MHana.1​ ,

thanks for ur answer. Yes, my idea is to use SPI6 as a slave.

However, I'm trying to debug ur sharing code, I noticed a very strange thing. Suppose to not connect anything to SPI6, and it is configurated likes ur code. If I debug HAL_SPI_Transmit(&hspi6,(uint8_t *)"HELLO",10, 500); I have HAL_ERROR with ErrorCode 32d (So timeout problems) but also if I analyze registers, with Live Expressions, I can see that this code line *((__IO uint8_t *)&hspi->Instance->TXDR) = *((uint8_t *)hspi->pTxBuffPtr); doesn't modify the TXDR register, that is every 0.

Have u some suggestion about this situation?

Thanks and regards!!!

GCava.2
Visitor II
June 23, 2022

I also tried using a different SPI, without DMA. and I have the same problem.....

Thanks!!