cancel
Showing results for 
Search instead for 
Did you mean: 

H7S SAI DMA - example?

mojolabs
Associate II

Hello,

I'm attempting to work with the SAI using DMA on the H7S using the NUCLEO-H7S3L8, unfortunately there is no SAI example. There is an I2S example using DMA on the STM32H7S78-DK:

https://github.com/STMicroelectronics/STM32CubeH7RS/tree/main/Projects/STM32H7S78-DK/Applications/USB_Device/Audio_Standalone

I've generated a project for the Nucleo using CubeMX, and then brought over the DMA code in the HAL_SAI_MspInit from that I2S example, and modified it for SAI. The result runs, but a user settings error is reported in the DMA interrupt:

dmaSettingsError.png

Here's the complete project:

https://github.com/mojolabsdotnet/saiDmaH7S

What is the right way to setup DMA for the SAI on the H7S?

Thanks!

 

5 REPLIES 5
FBL
ST Employee

Hi @mojolabs 

This example uses SAI configured to send a continuous SPDIF frame, using circular DMA.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL
mojolabs
Associate II

Hi @FBL 

Thank you very much for pointing out that example. I've examined the DMA init in that example and there were a few differences (DMA ch 4 instead of 2, DMA_TCEM_BLOCK_TRANSFER for the transfer mode, see git diff for full changes), but unfortunately those differences did not change the behavior - I still get a DMA_FLAG_USE error. I've updated the github project showing the problem with these updates.

The SAI init was generated by CubeMX, but could there be an issue with that init code? Or is there perhaps still an issue with the DMA init when using the SAI in I2S mode instead of using it with SPDIF?

Hi @mojolabs again,

I suggest you test the example firmware provided as it is and see if the issue persists. Than you can narrow down the issue. It could be an issue in CubeMX generated code.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

Hello @mojolabs,

I worked on a similar project recently, so I can see some things that may be causing a problem.
First was the DMA handIe name, and channel direction. Initially, I tried running it the way it was. Then, by adding a breakpoint at the HAL_SAI_Transmit_DMA call, I found out that it doesn't pass the check for enabling the DMA handle and Linked List mode being enabled, resulting in HAL_ERROR. Changing the GPDMA settings in CubeMX such that the handle is hdmatx and the channel direction is Memory To Peripheral solved it.
The other is something that also came up on my project and I solved with help from another forum member (on a previous account, leaving a post link here in case it's helpful). The DMA_FLAG_USE error comes up because the Linked List attributes never get saved in the registers, because they are not declared non-cacheable, and are as prone to not being loaded correctly as the data buffer that you have correctly declared so. A quick fix is to disable D-Cache, though you do have alternatives ("cleaning" the cache area where they are located pre-loading, etc).
With these two changes, it seems to run correctly, though I didn't check for output.

Hello @DDeimos ,

Thank you very much for the suggestions and tips. I ended up getting it working in a different codebase, the key was updating SystemClock_Config in the boot code, this change is pushed to my example git repo above. The SAI still does not work in this repo, however, there is one primary difference between it and my working codebase - the SAI initialization. My other codebase SAI init is based on working code on an H7, where the repo SAI init is generated by CubeMX. I'm intending to circle back and bring over the SAI init into this repo so there is an example of the SAI on the H7S for I2S once I have some time.

One takeaway I have from this is that the DMA_FLAG_USE error does not necessarily indicate a problem with the DMA setup - I made no change to the DMA setup in getting it working.

And, @FBL, I did try your suggestion of running the SPDIF example on the Nucleo, thank you for the suggestion. Unfortunately, it didn't run cleanly, but had an error at init time. I didn't investigate in detail as my goal wasn't SPDIF operation. Perhaps someone from ST can test this example to see if the issue I saw reproduces.