Is it possible to have a patch that I can apply to my svn checkout? currently I don't have bandwidth to download the whole repository.
Giovanni
DAC driver for the STM32
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: DAC driver for the STM32
Hey Giovanni,
It seems like the repository (at least mabl's git mirror) already has some DAC code.
I will have to make some changes to make it works, I'll post the patch when it's done.
Thanks.
It seems like the repository (at least mabl's git mirror) already has some DAC code.
I will have to make some changes to make it works, I'll post the patch when it's done.
Thanks.
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: DAC driver for the STM32
Hi,
Thanks, I made some last minute changes to the API, I wanted to make the driver as similar to the ADC one as possible. I need this because a "streaming" idea I am considering for analog I/O.
Note that there are two possible ways to implement this DAC in the STM32:
- The first one is to make each channel of each unit be a separate driver but in this case how to use a single DMA in linked mode?
- Make channels be like ADC channels in the DACConversionGroup structure. You may define all combination of modes: channel1, channel2 or channel1 and channel2 (with a single or double DMA depending if linked or not).
So far I have been unable to decide the best way this is why I stopped porting the code. We may discuss it on IRC if you want, I am lurking there more often.
Giovanni
Thanks, I made some last minute changes to the API, I wanted to make the driver as similar to the ADC one as possible. I need this because a "streaming" idea I am considering for analog I/O.
Note that there are two possible ways to implement this DAC in the STM32:
- The first one is to make each channel of each unit be a separate driver but in this case how to use a single DMA in linked mode?
- Make channels be like ADC channels in the DACConversionGroup structure. You may define all combination of modes: channel1, channel2 or channel1 and channel2 (with a single or double DMA depending if linked or not).
So far I have been unable to decide the best way this is why I stopped porting the code. We may discuss it on IRC if you want, I am lurking there more often.
Giovanni
Re: DAC driver for the STM32
Hi.
I think the DAC driver for STM32 must impement all capabilities of peripheral and have compiler options or one driver for double channel mode or separate driver for each channel. It is unlikely that someone will need to switch mode in real time. For example, if I need stereo sound output I will use double channel mode, If I want analog ouput I will use one channel mode - it is easier.
I think the DAC driver for STM32 must impement all capabilities of peripheral and have compiler options or one driver for double channel mode or separate driver for each channel. It is unlikely that someone will need to switch mode in real time. For example, if I need stereo sound output I will use double channel mode, If I want analog ouput I will use one channel mode - it is easier.
Re: DAC driver for the STM32
The current driver is very close to the I2S driver as per your request.
If you need something similar to the ADC then I need to redo everything...
Each DAC use its own DMA stream so I don't think we need linked mode right?
If you need something similar to the ADC then I need to redo everything...
Each DAC use its own DMA stream so I don't think we need linked mode right?
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: DAC driver for the STM32
Hi Mobyfab,
I know... I had a change of mind because I decided to remove the I2S driver, I am thinking to merge that functionality into the SPI driver, sorry for not making requests more carefully.
The new API is not very different anyway, your code is almost OK as-is, I was going to make the changes myself during vacations. The only real difference is the DACConversionGroup structure which describes the conversion process, just like the ADC driver. If there is the circular buffer mode then there is no need for the dual buffers so I removed that, it is too-STM32F4-specific, scatter-gather DMA is not something you can assume to be present, in fact it was a special case in the code.
About the linked mode, I think it will be the most used because stereo audio streams. It allows two streams using a single DMA.
Giovanni
I know... I had a change of mind because I decided to remove the I2S driver, I am thinking to merge that functionality into the SPI driver, sorry for not making requests more carefully.
The new API is not very different anyway, your code is almost OK as-is, I was going to make the changes myself during vacations. The only real difference is the DACConversionGroup structure which describes the conversion process, just like the ADC driver. If there is the circular buffer mode then there is no need for the dual buffers so I removed that, it is too-STM32F4-specific, scatter-gather DMA is not something you can assume to be present, in fact it was a special case in the code.
About the linked mode, I think it will be the most used because stereo audio streams. It allows two streams using a single DMA.
Giovanni
Re: DAC driver for the STM32
Bumping the thread
I have started updating the code and it compiles, for F0 at least.
I will redo the examples for all devices that are supported.
For the conversion group I don't really see the point since the DAC is not multiplexed nor has sampling time settings like ADC.
The branch is "dac-new"
https://github.com/mobyfab/ChibiOS/tree/dac-new/
I have started updating the code and it compiles, for F0 at least.
I will redo the examples for all devices that are supported.
For the conversion group I don't really see the point since the DAC is not multiplexed nor has sampling time settings like ADC.
The branch is "dac-new"
https://github.com/mobyfab/ChibiOS/tree/dac-new/
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: DAC driver for the STM32
Hi,
The DAC conversion group is supposed to work like for the ADC, for example the list of DAC channels that are part of the conversion process.
I think the STM32 DAC has 2 channels so the possible modes are CH1, CH2, CH1+CH2 linked (assuming a single DMA is used). Also details about alignment and other should go there.
The idea is to make it symmetrical to the ADC, hope this makes sense.
Giovanni
The DAC conversion group is supposed to work like for the ADC, for example the list of DAC channels that are part of the conversion process.
I think the STM32 DAC has 2 channels so the possible modes are CH1, CH2, CH1+CH2 linked (assuming a single DMA is used). Also details about alignment and other should go there.
The idea is to make it symmetrical to the ADC, hope this makes sense.
Giovanni
Re: DAC driver for the STM32
Each channel is independant and uses its own timer to trigger conversion.
Not sure you can use a single DMA channel for multiple DAC channels without DMA remap.
I see what you mean
Not sure you can use a single DMA channel for multiple DAC channels without DMA remap.
I see what you mean
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: DAC driver for the STM32
You can write a single 32 bits data register accessing both channels with a single store, this requires a 32bits wide DMA operation, a single DMA and a single timer (12.3.7). I think this is the most common mode because it is perfect for stereo streams where left and right must be perfectly in sync.
If you use the two channels as two separate DAC instances then this synchronized mode is no more possible and you have to use two DMAs and two timers without perfect synchronization.
Giovanni
If you use the two channels as two separate DAC instances then this synchronized mode is no more possible and you have to use two DMAs and two timers without perfect synchronization.
Giovanni