cancel
Showing results for 
Search instead for 
Did you mean: 

External DAC with SPI + DMA

decalvus
Associate II

Hi

I am trying to make an analog synthesizer, and for this is using a STM32G431 with some 8-channel DAC’s (connected via SPI) for generating control-voltages for the VCA’s and other circuits.

I would like to use the SPI with DMA, and have looked at the RM chapters, understood some of it, but feel I need some working code example to lean against to move forward.
When looking I only have found examples using either the internal DAC + DMA (without SPI), or SPI DAC but without DMA.
The F4 Discovery boards (e.g STM32F407G-DISC1) does have an audio playback & recorder example using a CS32L22 stereo codec with I2S and DMA, but uses I2C instead of SPI for sending initialization settings to the codec.

F4 or F3 examples could also be useful. I mostly chose G4 since it’s newer than F4, and hopefully some DMA and SPI quirks have been corrected in the new silicon (I may be naive though). At least it seems the errata mentions fewer ‘specialties’.

Anything using an external DAC (no matter which) with SPI+DMA or I2S+DMA will be very helpful. If some has a link to an example, or would share a piece of such code, it will be much appreciated.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Happy that you find it interesting.

You can try to understand how this project works. And then you can use the same configuration on the stm32G4. When you find an answer to your question, close the topic by choosing it as best answer.

Best regards.

II

View solution in original post

13 REPLIES 13
Issamos
Lead II

Hello @decalvus 

I've find this exemple in GitHub and you can find her a video to help you understand this exemple (the video and the description are in Russian but you can use the translate page and subtitle option to understand it. Is not going to be so hard.). Also the ressources kan be downloaded from a drive that you can find his link in the video description.

Best regards.

II

Hi @Issamos

Thanks a lot for helping.

It looks like a good simple example (with all relevant code in main.c, compared to 50+ files in the Discovery board example previously mentioned). Also like it uses LL library, which can easily be converted to direct register access which I prefer.
Though it uses an F4, which has a different double-port DMA than the G4 single-port DMA I plan to use. Likely there’s less examples around for the newer G4, although it would be nice to compare to if some knows of one.

Thanks,
Pete

Happy that you find it interesting.

You can try to understand how this project works. And then you can use the same configuration on the stm32G4. When you find an answer to your question, close the topic by choosing it as best answer.

Best regards.

II

AScha.3
Chief II

i think, here is some misunderstanding... or lack of information .

1. did you build already some analog synthesizers ? how ?

2. signal generation : you want only analog, not digital - right ? or both ?

3. which 8ch dac you wanna use ?

4. why this cpu - G431 ?

If you feel a post has answered your question, please click "Accept as Solution".

Hi @AScha.3

No misunderstanding at all, I think:)
I’m in the process of building it, but far from finished. Analog circuitry is done, but have only recently begun the digital part.
It’s only analog. The DAC channels are connected to voltage-controlled amplifiers (VCA’s), e.g. LM13700 or SSI2164, which controls the pitch/note of the analog oscillators and cutoff-frequency of the analog filters (same way it has been done in most analog synths the past 50 years)
Will probably use PCM1681 since it’s low $ per channel
I mostly chose G4 series since it’s newer than F4, and hopefully? some of the SPI and DMA quirks in the F4 errata have been fixed in the G4 silicon. At least the G4 errata sheet seems a bit shorter than for the F4
And also since I’ve read the F4 series ADC’s produce rather unstable values which may need post-filtering in software, while the G4 ADC’s should have better accuracy and doesn’t need filtering (haven’t tested it myself though)

Best regards,
Pete

ok, funny...

but wtf you build analog synth ? just for fun ? (hobby, this i could understand )

can have analog synth for 500$...

AScha3_0-1694903074352.png

https://www.thomann.de/de/ik_multimedia_uno_synth_pro_x.htm

how many hours you need, to build something like this ? 500 ?  

i made my first (and only) digital sampling synth 35 y ago, but Yamaha and Korg been faster... no surprise, they have not only one guy building this.

so tell me, why and for what use ?

PCM1681 seem good bang...but can use any cpu, you need no real fast core, so (think about, what you can get on market now really) "old" F103 should be fast enough, but for 8ch I2S you need a chip with SAI interface, G431 has it, but i would recommend a new series, i have H563 disco here, 2x SAI , 144 pins... 30$ for ready board, to make experiments. 

If you feel a post has answered your question, please click "Accept as Solution".

PCM1681 ?, forget, non of the ST uCPU even highest performance H7 could handle Octal I2S (or Quad-I2S ?). Get for starting something easy to interface, like MCP4922 or LTC1665

...thats why i wrote: > need SAI interface. this can send 16 x 32 bit frames , on 4 channels ! (H563)

so driving 8 x 24 bit DAC is no problem.  or 2x 8x24 on G431 , 4x 8x24 on H563 .

and set -> data coming from a circular DMA , you get zero cpu load, to keep dacs running.

cpu just writes a value to the dma buffer, to set a dac channel to a new level. thats it.

here not 8 music streams with full audio speed needed - that would be another game. 

If you feel a post has answered your question, please click "Accept as Solution".

https://www.st.com/resource/en/reference_manual/rm0481-stm32h563h573-and-stm32h562-armbased-32bit-mcus-stmicroelectronics.pdf 

Page 2450:

"The SAI is mainly composed of two audio subblocks with their own clock generator. Each
audio block integrates a 32-bit shift register controlled by their own functional state machine."

There is only 1 shift register and 2 blocks, so Bi - I2S at the best, no way you can get Quad.