DAC driver for STM32 *almost* done

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

Moderator: RoccoMarco

rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: DAC driver for STM32 *almost* done

Post by rew »

I wanted to have DAC and USB working on the '072, so I was trying to figure out what was going wrong. Nothing helped.

Then suddenly my computer dies. Won't turn on either. Turns out my STM'072 board was lying on the bare shield of an USB cable... Computer broken? PCB broken? Nope. Removing the short, computer boots, board works, USB-serial works!
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: DAC driver for STM32 *almost* done

Post by mobyfab »

Awesome, I did not have much time to take care of it.

Thanks!
User avatar
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 STM32 *almost* done

Post by Giovanni »

mobyfab wrote:Awesome, I did not have much time to take care of it.

Thanks!


Don't mention it, thanks for the implementation.
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: DAC driver for STM32 *almost* done

Post by rew »

Let me say that I find the "convert this value now" function very useful.

Many people will not require the advanced features with DMA etc. When updating say less than 1000x per second, that way of doing it will be good enough. And with a bit of luck this frees up a DMA channel that could be used for something else.

Similarly, I think the ADCs should have a "convert and give me the value now" function. I'll implement it when I have the time and contribute the code, but In the mean time I would like you to know about this "request", so that if it's easy and you happen to be "messing" in that area of code.... maybe.... :-)
(If it's already there, I couldn't find it last time I looked)
User avatar
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 STM32 *almost* done

Post by Giovanni »

Hi,

I considered such a function for the ADC but it is not so simple, the ADC requires parameters: channel, sample time, resolution etc. If you pass all of those then you have a special case of adcConvert.

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: DAC driver for STM32 *almost* done

Post by rew »

I would like to call:

Code: Select all

value = adc_convert_once (ADCD1, ADC_CHAN1, 0);

The "0" is the "options" parameter where I can pass defines that make it deviate from the defaults. The shortest sample-time is probably too short in a significant number of cases, but a few notches up should be fine in many cases.

I sell a product that offers ADC conversion of an input. I've defined the device report the raw value, 10 bits, in the public interface.

Switching to STM32 inside gives me a problem: Either I throw away two valid bits, or I have to redefine the interface.

This would mean that a platform independent interface is a good idea. "The returned value is in the range 0-65535. Depending on the hardware currently the bottom 4-6 bits do not contain valid information. Future hardware might be equipped with a better AD converter." (on the other hand, ADC_O_OVERSAMPLE_256 would give you statistical valid results in the bottom 4 bits).

So, what you're saying is that what I'm proposing is a thin layer above adcConvert.

Code: Select all

adc_sample_t adcConvertOnce (ADCDriver *adcp, int chno, int options)
{
ADCConversionGroup cgrp;
adcsample_t samples[1];

cgrp.circular = 0;
cgrp.num_channels = 1;
cgrp.end_cb = NULL;
cgrp.error_cb = NULL;
// The channel number comes back in one of these registers,
// The options (in the future?) too.
cgrp.cr1 = ...
cgrp.cr2 = ...
cgrp.smpr1 = ...
cgrp.smpr2 = ...
cgrp.sqr1 = ...
cgrp.sqr2 = ...
cgrp.sqr3 = ...
adcConvert (adcp, &cgrp, samples, 1);
return samples[0];
}
(this is based on the documentation for "adcConvert" that I found using google. )
What I'm after is that porting a simple: "get the voltage at a pin" from one member of the STM32 family to another, or from STM32 to AVR or LPC becomes simple.
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: DAC driver for STM32 *almost* done

Post by DeusExMachina »

I know that there is a demo for STM32F072-Disco in Chibios v.3.0
But stable branch is 2.6.x.
How about back-porting this demo and 72 support to 2.6.x branch?
User avatar
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 STM32 *almost* done

Post by Giovanni »

DeusExMachina wrote:I know that there is a demo for STM32F072-Disco in Chibios v.3.0
But stable branch is 2.6.x.
How about back-porting this demo and 72 support to 2.6.x branch?


The 2.6.x branch uses old CMSIS headers from ST, 072 is not supported by those headers. Porting the new headers to 2.6.x would mean re-doing some of the work already done in the 3.0 HAL, possibly introducing issues in doing so.

Are there problems switching to 3.0? it will be released as stable very soon now.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: DAC driver for STM32 *almost* done

Post by DeusExMachina »

Legacy code, is the most obvious reason :D
BTW, it seems that RTOS F051 demo is working correct on stm32F072, and UART/i2c drivers are also functional.
iman
Posts: 9
Joined: Mon Sep 15, 2014 9:16 pm

Re: DAC driver for STM32 *almost* done

Post by iman »

Hi

I want to know that what is the highest frequency for GPT in order to use it for DAC driver on STM32F3?
Post Reply