STM32 DAC problem ChibiOS 20.3.1 Topic is solved
Posted: Fri May 22, 2020 2:41 pm
Code porting from ChibiOS 18.2.1 to ChibiOS 19.1.4 works fine, ChibiOS 20.3.1 has a problem. I have separate builds for each version, with mcuconf.h, halconf.h, chconf.h and Makefile from the relevant ChibiOS versions and files updated as appropriate.
Edit to add: Using STM32F407 DISC1 board
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
I populate a buffer with a sine wave of a given frequency, output via DAC (very similar to testhal/STM32/STM32F4xx/DAC/main.c, but not using the callback) and read back via ADC as a test signal. I use 1024 sample buffers (12 bit), and join two buffers together, so the raw trace shows the same DAC data repeated. The left trace is the incoming signal, the right trace is the spectrum.
From Version 19.1.4 (which works the same as 18.2.1):
With version 20.3.1 the data is garbled in places, and the frequency doubled:
I have tested with an oscilloscope and an external signal which confirms the ADC code is working properly and the DAC is producing bad data.
I suspect it's related to the different CR settings in os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.c and I'll try to examine that in the debugger.
It may be DMA related as it seems similar to the following, although I'm not using DUAL mode
viewtopic.php?t=2988
Thanks
Mike
Edit to add: Using STM32F407 DISC1 board
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
I populate a buffer with a sine wave of a given frequency, output via DAC (very similar to testhal/STM32/STM32F4xx/DAC/main.c, but not using the callback) and read back via ADC as a test signal. I use 1024 sample buffers (12 bit), and join two buffers together, so the raw trace shows the same DAC data repeated. The left trace is the incoming signal, the right trace is the spectrum.
From Version 19.1.4 (which works the same as 18.2.1):
With version 20.3.1 the data is garbled in places, and the frequency doubled:
I have tested with an oscilloscope and an external signal which confirms the ADC code is working properly and the DAC is producing bad data.
I suspect it's related to the different CR settings in os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.c and I'll try to examine that in the debugger.
It may be DMA related as it seems similar to the following, although I'm not using DUAL mode
viewtopic.php?t=2988
Thanks
Mike