missing part mcuconf.h stm072 discovery

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

Moderator: RoccoMarco

enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

Hi,
I had to use DAC but there is a loss in the mcuconf.h that comes with ChibiOs 4 (I don't know for previous release)
in order to compile with DAC enabled I had to add the following rows

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(1, 3)
#define STM32_DAC_DAC1_CH2_DMA_STREAM       STM32_DMA_STREAM_ID(1, 4)

Hope nothing was wrong with them
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: missing part mcuconf.h stm072 discovery

Post by Giovanni »

I will look into this.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

I have a question, I look inside the example of DAC but every one generates a waveform on output.
If I need to give a constant value, (constant is intened as I need to change the value very few times in a time of 10 minutes driven by external events) to 2 DAC output with different values.
Can I do something like

Code: Select all

dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, 1);// dac_buffer is a 1 element long
//....
while(true){
   if(condition){
     dacStopConversion(&DACD1);
     //load new value
    dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, 1);
  }
}


with a configuration like this (for 1 output)

Code: Select all

static const DACConversionGroup dacgrpcfg1 = {
  .num_channels = 1U,
  .end_cb       = NULL,
  .error_cb     = NULL,
  .trigger      = DAC_TRG_SW
};



how to manage two output?


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: missing part mcuconf.h stm072 discovery

Post by Giovanni »

Try dacPutChannelX().

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

If I want also to enable the buffer to feed the output directly to other devices, is there any configuration or instruction inside the chibios's driver to do that (I'm talking about BOFF1 field inside DAC_CR register)
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

Thanks Giovanni!

/**
* @brief Outputs a value directly on a DAC channel.
*
* @param[in] dacp pointer to the @p DACDriver object
* @param[in] channel DAC channel number
* @param[in] sample value to be output
*
* @xclass
*/
void dacPutChannelX(DACDriver *dacp, dacchannel_t channel, dacsample_t sample)

it is what I need!!!!
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

I have a problem,
I can increase and decrease only channel 0 on PA4, if I call

Code: Select all

dacPutChannelX(&DACD1,1,dac_ref);


the output of PA5 does not change (even if both PA4 and PA5 are set as analog)

inside mcuconf.h I have

Code: Select all

#define STM32_DAC_DUAL_MODE                 FALSE
#define STM32_DAC_USE_DAC1_CH1              TRUE
#define STM32_DAC_USE_DAC1_CH2              TRUE


Any suggestions?

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: missing part mcuconf.h stm072 discovery

Post by Giovanni »

Mcuconf.h files have been fixed.

Not sure about the issue, that function just writes into the data registers.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: missing part mcuconf.h stm072 discovery

Post by enrico.dallavia »

Found the problem!
I had to initialize DADC2 and use channel 1 when I have to use it.

As a very simple example to drive the 2 independent DAC (using stm072 discovery)

Code: Select all

static const DACConfig dac1cfg1 = {
  .init         = 0U,
  .datamode     = DAC_DHRM_12BIT_RIGHT
};

/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

   palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
   palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);

  dacStart(&DACD1, &dac1cfg1);
  dacStart(&DACD2, &dac1cfg1);
  dacsample_t dac_ref = 0;

  dacPutChannelX(&DACD1,0,dac_ref);
  dacPutChannelX(&DACD2,1,dac_ref);

  while (true) {
    if (palReadPad(GPIOA, GPIOA_BUTTON)){
        dac_ref+=100;
        dacPutChannelX(&DACD1,0,dac_ref);
        dacPutChannelX(&DACD2,1,dac_ref);
    }
    chThdSleepMilliseconds(250);
  }
}



My mistakes were:
1) try to pilot 2nd channel with dacPutChannelX(&DACD1,1,dac_ref);
2) try to pilot 2nd channel with dacPutChannelX(&DACD2,0,dac_ref);

Now I can see at oscilloscope both channel working fine!
Thanks!

If I have to use buffer (set BOFF1 in DAC_CR register) to pilot something without any op amp in the middle, do I have to manage the register manually or is there any hal chibios for that?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: missing part mcuconf.h stm072 discovery

Post by Giovanni »

Hi,

Currently it is not possible to set BOFF, it will require a change. You can change the CR register after calling dacStart().

Giovanni
Post Reply