STM32L1 DAC conversion problem

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

Moderator: RoccoMarco

Post Reply
beaming
Posts: 11
Joined: Sun Nov 10, 2013 9:27 pm

STM32L1 DAC conversion problem

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

Re: STM32L1 DAC conversion problem

Post 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
beaming
Posts: 11
Joined: Sun Nov 10, 2013 9:27 pm

Re: STM32L1 DAC conversion problem

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

Re: STM32L1 DAC conversion problem

Post 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
beaming
Posts: 11
Joined: Sun Nov 10, 2013 9:27 pm

Re: STM32L1 DAC conversion problem

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

Re: STM32L1 DAC conversion problem

Post 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
beaming
Posts: 11
Joined: Sun Nov 10, 2013 9:27 pm

Re: STM32L1 DAC conversion problem

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