From f7361859b0a8dc39b2f33d897cf4ceb2fa6ee1dd Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 3 May 2015 09:04:25 +0000 Subject: [PATCH] Improved DAC initialization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7942 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/DACv1/dac_lld.c | 5 +++-- os/hal/ports/STM32/LLD/DACv1/dac_lld.h | 4 ++++ testhal/STM32/STM32F4xx/DAC/Makefile | 2 +- .../DAC/debug/STM32F4xx-DAC (OpenOCD, Flash and Run).launch | 2 +- testhal/STM32/STM32F4xx/DAC/main.c | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/os/hal/ports/STM32/LLD/DACv1/dac_lld.c b/os/hal/ports/STM32/LLD/DACv1/dac_lld.c index 6aabd7f34..8fc51ae88 100644 --- a/os/hal/ports/STM32/LLD/DACv1/dac_lld.c +++ b/os/hal/ports/STM32/LLD/DACv1/dac_lld.c @@ -251,10 +251,11 @@ void dac_lld_start(DACDriver *dacp) { #if STM32_DAC_DUAL_MODE == FALSE dacp->params->dac->CR &= dacp->params->regmask; dacp->params->dac->CR |= DAC_CR_EN1 << dacp->params->regshift; - *(&dacp->params->dac->DHR12R1 + dacp->params->dataoffset) = 0U; + dac_lld_put_channel(dacp, 0U, dacp->config->init); #else dacp->params->dac->CR = DAC_CR_EN2 | DAC_CR_EN1; - dacp->params->dac->DHR12RD = 0U; + dac_lld_put_channel(dacp, 0U, dacp->config->init); + dac_lld_put_channel(dacp, 1U, dacp->config->init); #endif } } diff --git a/os/hal/ports/STM32/LLD/DACv1/dac_lld.h b/os/hal/ports/STM32/LLD/DACv1/dac_lld.h index ddfafc256..a62852c51 100644 --- a/os/hal/ports/STM32/LLD/DACv1/dac_lld.h +++ b/os/hal/ports/STM32/LLD/DACv1/dac_lld.h @@ -364,6 +364,10 @@ typedef struct { */ typedef struct { /* End of the mandatory fields.*/ + /** + * @brief Initial output on DAC channels. + */ + dacsample_t init; /** * @brief DAC data holding register mode. */ diff --git a/testhal/STM32/STM32F4xx/DAC/Makefile b/testhal/STM32/STM32F4xx/DAC/Makefile index 3fec9da36..2a762abc4 100644 --- a/testhal/STM32/STM32F4xx/DAC/Makefile +++ b/testhal/STM32/STM32F4xx/DAC/Makefile @@ -5,7 +5,7 @@ # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 + USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16 endif # C specific options here (added to USE_OPT). diff --git a/testhal/STM32/STM32F4xx/DAC/debug/STM32F4xx-DAC (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F4xx/DAC/debug/STM32F4xx-DAC (OpenOCD, Flash and Run).launch index bb8c1ea60..8a1fa9311 100644 --- a/testhal/STM32/STM32F4xx/DAC/debug/STM32F4xx-DAC (OpenOCD, Flash and Run).launch +++ b/testhal/STM32/STM32F4xx/DAC/debug/STM32F4xx-DAC (OpenOCD, Flash and Run).launch @@ -33,7 +33,7 @@ - + diff --git a/testhal/STM32/STM32F4xx/DAC/main.c b/testhal/STM32/STM32F4xx/DAC/main.c index 469132559..e57d8a3f2 100644 --- a/testhal/STM32/STM32F4xx/DAC/main.c +++ b/testhal/STM32/STM32F4xx/DAC/main.c @@ -88,6 +88,7 @@ static void error_cb1(DACDriver *dacp, dacerror_t err) { } static const DACConfig dac1cfg1 = { + init: 2047U, datamode: DAC_DHRM_12BIT_RIGHT };