DAC error for STM32F4 discovery

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

Moderator: RoccoMarco

c2issy
Posts: 5
Joined: Tue Oct 28, 2014 2:32 am

DAC error for STM32F4 discovery

Post by c2issy »

Hi,
I have been working on a DAC driver recently and came across a compile error.
I'm using STM32F4 discovery board which has 2 DAC channels and chibiOS RT from https://github.com/ChibiOS/ChibiOS-RT.
As a newbie to chibiOS, I first tried the DAC example from https://github.com/fpoussin/ChibiOS-Exa ... TM32F4-DAC.

But the DAC doesn't compile.
The error message is like below:
DAC error message
DAC error message
Screenshot from 2014-10-21 22_32_25.png (177.93 KiB) Viewed 8492 times

My main suspicion for the cause of the error is that the variable STM32_HAS_DAC_CHN1 is never defined in any header.

Besides, when I looked at the file os/hal/ports/STM32/STM32F4xx/stm32_registry.h , the variable STM32_HAS_DAC1 is set to FALSE by default even though there're presence of DACs on board.

All of these led me to think that maybe the DAC module is not well-supported in chibiOS currently?
Can anybody provide a working version of DAC module? The links from this thread viewtopic.php?f=16&t=1196 have all expired.

I really need to make the DAC module working for my research. Any help or suggestion is highly appreciated!

Cheers,

CC, helpless phD :(
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 error for STM32F4 discovery

Post by Giovanni »

Hi,

Try adding that variable to the stm32_registry.h file, it is supposed to be there, of course also mark the DAC as present.

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

Re: DAC error for STM32F4 discovery

Post by mobyfab »

Hey,

I moved DAC along with other drivers to this repo:
https://github.com/ChibiOS/ChibiOS-Drivers

The example will need some changes as it doesn't use HAL but DRIVER.
Let me know if you have any problems with it.

You can also do as Giovanni said, it should get it working :)
c2issy
Posts: 5
Joined: Tue Oct 28, 2014 2:32 am

Re: DAC error for STM32F4 discovery

Post by c2issy »

Giovanni wrote:Hi,

Try adding that variable to the stm32_registry.h file, it is supposed to be there, of course also mark the DAC as present.

Giovanni


Thanks for your suggestion. I will modify the corresponding headers and see if I can make it work.
c2issy
Posts: 5
Joined: Tue Oct 28, 2014 2:32 am

Re: DAC error for STM32F4 discovery

Post by c2issy »

mobyfab wrote:Hey,

I moved DAC along with other drivers to this repo:
https://github.com/ChibiOS/ChibiOS-Drivers

The example will need some changes as it doesn't use HAL but DRIVER.
Let me know if you have any problems with it.

You can also do as Giovanni said, it should get it working :)


Hi mobyfab,

Thanks for providing the DAC driver. You made my day ! :)
I will try the module out and let you know my progress. Meanwhile I'm trying to fix the header as Giovanni suggested.
c2issy
Posts: 5
Joined: Tue Oct 28, 2014 2:32 am

Re: DAC error for STM32F4 discovery

Post by c2issy »

Hi Mobyfab,

Many thanks for your DAC driver!

As Giovanni and you sugguested, I have add the driver-path to SRC and INC in makefile and included the header drivers.h in my main.c. Although compilation generates no error, I still could't get my dac on STM32F4 to work. There's one wired thing that the dac_driver.h doesn't seem to be linked to the dac_driver.c.

Usually after compilation, we could access variables and functions declaired in other .c files using F3. But when I tried "open declaration" for the function dacStartConversion in the snapshot below.
Screenshot1.png
Screenshot1.png (90.82 KiB) Viewed 8411 times

Screenshot2.png
Screenshot2.png (81.2 KiB) Viewed 8411 times

It jumps to dac_driver.h instead of dac_driver.c. Trying "open declaration" for the function dacStartConversion in dac_driver.h does nothing. If this function is not linked to the real declaration which has contents in dac_driver.c, then it will a void function and nothing is excecuted.

I was confuced because and I do have the dac_driver.c specified in SRC of my makefile. Do you possibly know what I may have done wrong? I attached my main.c here.
DAC.zip
My DAC project
(4.87 MiB) Downloaded 494 times


PS. Warning messages are attached here. Don't know if they are important.



mobyfab wrote:Hey,

I moved DAC along with other drivers to this repo:
https://github.com/ChibiOS/ChibiOS-Drivers

The example will need some changes as it doesn't use HAL but DRIVER.
Let me know if you have any problems with it.

You can also do as Giovanni said, it should get it working :)
wolf
Posts: 42
Joined: Mon Dec 31, 2012 1:55 pm
Been thanked: 9 times

Re: DAC error for STM32F4 discovery

Post by wolf »

Hy all,

@Mobyfab: ERROR in dac_lld in method void dac_lld_start_conversion(DACDriver *dacp) and probably more

I used your DAC code for CHN1 and CHN2 as independent units.

CHN1 worked immediately, CHN2 ended up in a memory fault.
So I traced into the problem and found the following error:

When assigning the DMA peripheral address in line :
.......
switch (dacp->config->dhrm) {
/* Sets the DAC data register */
case DAC_DHRM_12BIT_RIGHT:
dmaStreamSetPeripheral(dacp->dma, &dacp->dac->DHR12R1 + dataoffset);

where offset equals 12 for CHN2, the calculation of the target address leads to (DHR12R1 + 12x4) and not to (DHR12R1 + 12) as intended! This is probably due to the fact that all DAC registers are defines as 32 bit values. Pointing to nowhere we'll have a hardfault as a result!

So a quick change (a few hours later) of the line in question to:
dmaStreamSetPeripheral(dacp->dma, &dacp->dac->DHR12R1 + dataoffset/4);

solved the problem.

This unexpected behaviour happens most certain throughout the whole section, where this calculation is performed.

The compiler and IDE I use is ChibiStudio_Preview7 everything updated to latest version:

Kernel: 2.6.6
Compiler: GCC 4.7.4 20140401 (release) [ARM/embedded-4_7-branch revision 209195]
Architecture: ARMv7-ME
Core Variant: Cortex-M4F
Port Info: Advanced kernel mode
Platform: STM32F407/F417 High Performance with DSP and FPU
Board: STMicroelectronics STM32F4-Discovery
Build time: Jan 5 2015 - 19:30:12

Can anybody confirm my observation?

@Giovanni: Is the DAC driver intended to be officially included in future versions?

Best regards

Wolf
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 error for STM32F4 discovery

Post by Giovanni »

Hi,

Yes, it is half done but I have to find some time, the ChibiOS 3.0 preparation for release has priority.

Giovanni
deeznutz
Posts: 7
Joined: Tue Jan 20, 2015 6:25 pm

Re: DAC error for STM32F4 discovery

Post by deeznutz »

Hi,

first of all thanks for that great os!

I have some problems to get the DAC thing to work... as a starting point I used the example posted by c2issy. After eliminating a couple of warnings (mainly redeclaration) I got stuck when linking the projekt with the following errors:

    main.c:98:3: warning: initialization from incompatible pointer type [enabled by default]
    main.c:98:3: warning: (near initialization for 'dacconvgrp.end_cb') [enabled by default]
    main.c:99:3: warning: initialization from incompatible pointer type [enabled by default]
    main.c:99:3: warning: (near initialization for 'dacconvgrp.error_cb') [enabled by default]
    main.c: In function 'Thread1':
    main.c:138:1: warning: no return statement in function returning non-void [-Wreturn-type]
    Linking build/ch.elf
    C:\Users\OSSENB~1.FB1\AppData\Local\Temp\ccSMAs0P.ltrans0.ltrans.o: In function `port_init':
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/../../chibios3/os/ext/CMSIS/include/core_cm4.h:1441: undefined reference to `_stm32_dma_streams'
    C:\Users\OSSENB~1.FB1\AppData\Local\Temp\ccSMAs0P.ltrans0.ltrans.o: In function `main':
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/main.c:174: undefined reference to `dmaStreamAllocate'
    C:\Users\OSSENB~1.FB1\AppData\Local\Temp\ccSMAs0P.ltrans0.ltrans.o: In function `chSysHalt':
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/../../chibios3/os/rt/src/chsys.c:165: undefined reference to `_stm32_dma_streams'
    C:\Users\OSSENB~1.FB1\AppData\Local\Temp\ccSMAs0P.ltrans0.ltrans.o: In function `dac_lld_start_conversion':
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/../../chibios3/../ChibiOS-Drivers/stm32/dac_driver_lld.c:380: undefined reference to `dmaStreamAllocate'
    C:\Users\OSSENB~1.FB1\AppData\Local\Temp\ccSMAs0P.ltrans1.ltrans.o: In function `daccb.10078':
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/main.c:76: undefined reference to `_stm32_dma_streams'
    C:\ChibiStudio\workspace30\STM32F4xx-DAC/main.c:76: undefined reference to `_stm32_dma_streams'
    collect2.exe: error: ld returned 1 exit status
    make: *** [build/ch.elf] Error 1
The file stm32_dma.c is being compiled successfully and the object file is present. Any idea what I am missing?

I am using chibistudio pre8 with chibios 3.0

Thanks in advance!

Nils
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 error for STM32F4 discovery

Post by Giovanni »

Hi,

It is unfinished so I can't support.

Please also read here: viewtopic.php?f=16&t=2381
Probably they got the driver working.

Giovanni
Post Reply