DAC driver for the STM32

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

DAC driver for the STM32

Post 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/dac
You can see the differences with the current trunk here: https://github.com/mobyfab/ChibiOS/compare/dac

The 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.
Last edited by mobyfab on Wed May 29, 2013 1:26 pm, edited 1 time in total.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: DAC driver for the STM32

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: DAC driver for the STM32

Post 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
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for the STM32

Post 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.
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for the STM32

Post 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.
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for the STM32

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: DAC driver for the STM32

Post 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
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for the STM32

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: DAC driver for the STM32

Post 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
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for the STM32

Post 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.
Post Reply