Description
While trying to port the Mozzi (Sound Synthesis) library to the Arduino Giga, I notice that DMA driven DAC seems to be quite fragile to set up, in some cases the DAC will simply fail to start.
Testcase: I can trip up the DAC_Sine_wave example by as little as uncommenting the Serial.begin()
line. Now the very same sketch will work some but not all of the time (try resetting a couple of times).
After lots of trial and error, I think I have pinned this down to the double buffered dma setup around here:
Arduino_AdvancedAnalog/src/AdvancedDAC.cpp
Line 129 in 80eeb61
Quite obviously, first starting the DAC, then pausing it to enable double buffering, then restarting it seems like a hack (if justified) in the first place.
I managed to arrive at a robust sketch, by essentially copying the HAL_DAC_Start_DMA implementation from the HAL, but modifying it to set up double buffering right away (settings the correct flags, addresses, and starting DMA with HAL_DMAEx_MultiBufferStart_IT). Of course that makes for a very verbose solution. License-wise, I think it should be ok, as the HAL library appears to be BSD'ed.
Would the above make for an acceptable PR, do you have another idea on attacking the problem, or am I the only one to experience it?