2022-09-20 10:35 PM
Dear Reader,
In this project we’re required to output a DAC signal (to begin with a sine-wave would suffice in terms of proving the code) on PA4 of our STM32H743 micro using DMA.
I’ve done some evaluation and testing based on STM’s sample project NUCLEO-H743ZI\Examples\DAC\DAC_SignalsGeneration (which I think is basically the same as their STM32H743I-EVAL\Examples\DAC\DAC_SignalsGeneration).
Each example project refers to a Triangle Wave generator, through DAC_Ch1_TriangleConfig(), and an Escalator Wave generator through DAC_Ch1_EscalatorConfig(). The setup/initialisation code seems to be exactly the same with the only difference being which of these two functions is then called.
I seem to be having some good success with the triangle generation, but not with the escalator. The escalator waveform is output on PA4, when DAC_Ch1_EscalatorConfig() is called, but the code then immediately hits a hardfault (although the waveform continues on the pin).
The triangle wave code calls HAL_DACEx_TriangleWaveGenerate(), HAL_DAC_Start(), and HAL_DAC_SetValue(). The escalator code (which is more important for our application) instead calls HAL_DAC_Start_DMA() and I think the problem involves this function as all other parts of the code seem to be the same.
The initialisation code calls MPU_Config(), CPU_CACHE_Enable(), HAL_Init(), and SystemClock_Config(). In this project I’ve excluded SystemClock_Config() as I notice the code will reset if this is executed. The Triangle Wave generator works even without SystemClock_Config(), but the Escalator code does not function properly regardless.
Do you know why the Escalator code is not working here, please ? The code is copied from the example provided except for the exclusions mentioned. Your assistance would be greatly appreciated.
And just in relation to the Triangle code can you please advise how to change the frequency of this signal ? I can alter the amplitude by changing from DAC_TRIANGLEAMPLITUDE_1023 (in function HAL_DACEx_TriangleWaveGenerate) to another of the options, but the frequency seems not to be so easy. I tried changing the fourth parameter in function call HAL_DAC_SetValue(), currently 0x100, but that had very little effect and changing the parameters associated with the initialisation of Timer6 had zero effect (things like Period, Prescaler, ClockDivision, and RepetitionCounter). Basically we need something in the audible frequency range, and the existing settings have the triangle at around 4 hertz (~250ms peak to peak).
2022-09-21 11:14 PM
I've now seen a post titled "DMA is not working on STM32H7 devices" in the Knowledge Database, and was wondering if this is the reason for the issues I'm observing ? Is it a related problem explaining my experience with DMA/DAC performance ? If so what is the workaround ? The Knowledge Database details a large amount of information which is difficult to understand, so can you explain it more simply assuming it is a related issue ?