How to use DAC1 Ch2 without dual mode Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: How to use DAC1 Ch2 without dual mode

Post by alex31 »

I have created a ticket with a proposed patch attached.

Alexandre
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use DAC1 Ch2 without dual mode

Post by Giovanni »

I will give it a try tomorrow.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use DAC1 Ch2 without dual mode

Post by Giovanni »

Hi,

Fixed in repository, could you confirm everything is OK?

Giovanni
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: How to use DAC1 Ch2 without dual mode

Post by alex31 »

looks fine. I was on the road this two days, I will be able to do a real test tomorrow.

thanks
Alexandre
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: How to use DAC1 Ch2 without dual mode

Post by alex31 »

Tests has been done on F4 and F7 and all is working nicely !

Alexandre
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use DAC1 Ch2 without dual mode

Post by Giovanni »

Thanks :)

Giovanni
sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: How to use DAC1 Ch2 without dual mode

Post by sntnjrg »

Hi,

I have a similar problem. I'm using a STM32L4R5ZI-NUCLEO144 board and the version 19.1.0 of ChibiOS.

My mcuconf.h have the following definitions:

Code: Select all

/*
 * DAC driver system settings.
 */
#define STM32_DAC_DUAL_MODE                 FALSE
#define STM32_DAC_USE_DAC1_CH1              TRUE
#define STM32_DAC_USE_DAC1_CH2              TRUE
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY     10
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY     10
#define STM32_DAC_DAC1_CH1_DMA_PRIORITY     2
#define STM32_DAC_DAC1_CH2_DMA_PRIORITY     2
#define STM32_DAC_DAC1_CH1_DMA_STREAM       STM32_DMA_STREAM_ID_ANY
#define STM32_DAC_DAC1_CH2_DMA_STREAM       STM32_DMA_STREAM_ID_ANY


The DAC configuration is:

Code: Select all

  static DACConfig dac_cfg = {
    // Initial output on DAC channels.
    .init         = 0U,
    // DAC data holding register mode.
    .datamode     = DAC_DHRM_8BIT_RIGHT,
    // DAC control register.
    .cr = 0
  };


When the following code is executed, an assertion fails:

Code: Select all

dacPutChannelX(&DACD2,1,dac_out2);


The dacPutChannelX() function contains:

Code: Select all

void dacPutChannelX(DACDriver *dacp, dacchannel_t channel, dacsample_t sample) {

  osalDbgCheck(channel < (dacchannel_t)DAC_MAX_CHANNELS);
  osalDbgAssert(dacp->state == DAC_READY, "invalid state");

  dac_lld_put_channel(dacp, channel, sample);
}


channel is 1 and DAC_MAX_CHANNELS is 1.

The DAC_MAX_CHANNELS macro is defined in hal_dac_lld.h as:

Code: Select all

/**
 * @brief   Max DAC channels.
 */
#if STM32_DAC_DUAL_MODE == FALSE
#define DAC_MAX_CHANNELS                    1
#else
#define DAC_MAX_CHANNELS                    2
#endif


Is it possible to use that channel with that instance of the driver? Should I use channel 0 in both instances?

Code: Select all

dacPutChannelX(&DACD1,0,dac_out1);
dacPutChannelX(&DACD2,0,dac_out2);


Thanks
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use DAC1 Ch2 without dual mode

Post by Giovanni »

Hi,
It is a bug, I think the problem is here:

Code: Select all

/**
 * @brief   Max DAC channels.
 */
#if STM32_DAC_DUAL_MODE == FALSE
#define DAC_MAX_CHANNELS                    1
#else
#define DAC_MAX_CHANNELS                    2
#endif


Those two definitions are inverted. Moving this topic in bug reports.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to use DAC1 Ch2 without dual mode

Post by Giovanni »

Hi,

Fixed as bug #1065.

Giovanni
Post Reply