Page 1 of 1

STM32L1 DAC conversion problem

Posted: Sun Nov 10, 2013 9:45 pm
by beaming
Hi,

I am trying to work on Mobyfab previously published code for DAC http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=1196&hilit=dac&start=10#p12217 and adapt it for STM32L1. But I have strange problem which seems to be DMA related. Namely: I initiate DAC2 and it seems to work. Since once I write manually into the DAC data holding register, I see the appropriate voltage at the PIN (PA5 in the case of the STM32l-discovery board),
however if I execute

Code: Select all

dacStartConversion(&DACD2, &dacconvgrp, dac_buffer, DAC_BUFFER_SIZE);

nothing happens. The pin reads 0, and none of callbacks are ever executed. This is why I think that this is DMA related, since conversion code uses DMA.

Can someone look at what is possibly wrong with this code? It is available at
https://github.com/evgmik/ChibiOS/tree/dac-new-testhal-dac-stm32lxx/testhal/STM32L1xx/DAC

Also it seems that stm32l DMA driver is not full, the manual said that there are 12 channels 7+5 in DMA1 and DMA2, but os/hal/platforms/STM32L1xx/stm32_dma.h defines only 7:

Code: Select all

#define STM32_DMA_STREAMS           7

Is it by design?

Re: STM32L1 DAC conversion problem

Posted: Sun Nov 10, 2013 10:43 pm
by Giovanni
Hi,

The second DMA is only present on devices with 384kB of flash which are recent not yet supported. If you take the DMA files from the F1 family it *should* work.

Giovanni

Re: STM32L1 DAC conversion problem

Posted: Mon Nov 11, 2013 1:35 am
by beaming
Quick diff shows that they are identical in functionality. F1 part has a few extra related to DMA2 but otherwise they are the same.

Is there a condition to be met for DMA exchange to be started?

Re: STM32L1 DAC conversion problem

Posted: Mon Nov 11, 2013 10:35 am
by Giovanni
Hi,

I will add support for DMA2 ASAP however I will be unable to test it first hand.

beaming wrote:Is there a condition to be met for DMA exchange to be started?


Not sure about what you mean, the DMA exchanges are usually triggered by peripherals.

Giovanni

Re: STM32L1 DAC conversion problem

Posted: Tue Nov 12, 2013 3:15 am
by beaming
Not sure about what you mean, the DMA exchanges are usually triggered by peripherals.

This is where I am puzzled. I would expect that the DMA starts transfer to the DAC as soon as ask for conversion in the code,
but you are implying that I probably need to toggle/trigger one of the external pins. Do I understand you correctly?

From other hand all ADC examples do not require to toggle anything externally, yet they use DMA. So I now very confused.

Also, if you do DMA2 just because I asked, it is not a pressing issue. I just noticed that there were contradiction between manual and what is already implemented. I would rather swing you to do the DAC part :)

As for the testing I am willing to do it for ever is needed with stm32l1 since I have the evaluation board, and access to scopes and function generators.
But I need some instructions to what should be treated as good or bad behavior.

Re: STM32L1 DAC conversion problem

Posted: Tue Nov 12, 2013 9:21 am
by Giovanni
Hi,

I think that it is not the DAC triggering the DMA, you need to use TIM6/TIM7 as time base. Note that there is already a contributed DAC driver in the forum, you may use/adapt that one: viewtopic.php?f=16&t=1196

Giovanni

Re: STM32L1 DAC conversion problem

Posted: Sat Nov 16, 2013 5:36 am
by beaming
For those who might search through this thread.I find a problem: wrong DMA streams were set. Now it works.

Mobyfab merged my patches into his tree, see for more details
http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=1196&p=13183#p13179