Page 1 of 5
DAC driver for the STM32
Posted: Wed May 29, 2013 1:23 pm
by mobyfab
Hi,
I am currently working on the DAC driver for the STM32F0/3/4 devices.
It's based on the patch submitted by Braun (many thanks!).
Right now it works on the F4, I will port it to the F3 and F0 in the following days/weeks.
So far I just added circular buffer support.
The code is here:
https://github.com/mobyfab/ChibiOS/tree/dacYou can see the differences with the current trunk here:
https://github.com/mobyfab/ChibiOS/compare/dacThe example for F4 discovery is here:
https://github.com/mobyfab/ChibiOS-Exam ... DSP/main.c (video:
http://www.youtube.com/watch?v=PqdnNBhFhbI)
I will make a simpler example as this one uses my DSP example using and LCD and so on.
Re: DAC driver for the STM32
Posted: Wed May 29, 2013 1:25 pm
by Tectu
Good work! I'd really love to finally see the DAC driver inside the ChibiOS/RT mainline. Maybe the other platform maintainers should be contacted to create a port since they might not read this forum (and yes, I don't know if any other, currently supported, platforms do provide a DAC).
~ Tectu
Re: DAC driver for the STM32
Posted: Wed May 29, 2013 3:58 pm
by Giovanni
Hi,
Thanks for the work, it is really needed.
I need to specify that this will have to go post-2.6.0 or directly in 3.0.x. I need to release 2.6.0 ASAP and I am doing just fixing right now.
Giovanni
Re: DAC driver for the STM32
Posted: Thu May 30, 2013 8:05 pm
by mobyfab
Hi,
I got both channels working with their own DMA stream and timer

(TIM6 & 7)
I will work on the F0/3 implementations in the following days.
The git repo has been updated.
Re: DAC driver for the STM32
Posted: Fri May 31, 2013 10:51 am
by mobyfab
I have updated the code with drivers and testhal demos for F0/30/37.
I had to add some code specific to the basic timers they use.
I will test them this evening on F0/F3 discovery boards, since they compile fine.
if someone has a F37x board and a scope, some testing would be helpful.
Re: DAC driver for the STM32
Posted: Fri May 31, 2013 10:00 pm
by mobyfab
Good news, I have almost finished writing the driver

Tested and works fine on F0 F30 and F4! (after some fixes)
Untested on F37 but very likely to work.
Video:
http://www.youtube.com/watch?v=JZrWxAi_U0s
Re: DAC driver for the STM32
Posted: Sat Jun 01, 2013 6:52 am
by Giovanni
Hi,
Would be possible to keep the API as close as possible to that unfinished I2S driver? basically they do the same thing. Probably there is no need for an explicit double buffered function. It works like the ADC on reverse.
For ChibiOS 3.0 I am thinking to give a "circular" capability to the SPI driver and make it some kind of common infrastructure for SPI/I2S/DAC (not sure about ADC) and similar.
Giovanni
Re: DAC driver for the STM32
Posted: Sat Jun 01, 2013 2:52 pm
by mobyfab
Hi,
What I could do it use the same function names and define the DMA mode and buffers in the config structure like the I2S driver.
Code: Select all
void dacInit(void);
void dacObjectInit(DACDriver *dacp);
void dacStart(DACDriver *dacp, const DACConfig *config);
void dacStop(DACDriver *dacp);
void dacStartSend(DACDriver *dacp);
void dacStopSend(DACDriver *dacp);
void dacSend(DACDriver *dacp);
Does that sound good to you?
I am also moving the dac driver to the STM32 folder as it's pretty much the same for all STM32 devices.
Re: DAC driver for the STM32
Posted: Sat Jun 01, 2013 3:35 pm
by Giovanni
That would be perfect. I would locate the files under ./STM32/DACv1 just in case it will change in some future STM32.
Giovanni
Re: DAC driver for the STM32
Posted: Sat Jun 01, 2013 4:49 pm
by mobyfab
It's done.
I have added support and demos for F1 and L1 devices. (untested)
The coding style is probably not perfect but there should not be too many things to modify.