AnsweredAssumed Answered

Bug in HAL library for DAC2 output 1 for the STM32F334

Question asked by Philippe on Mar 14, 2016
Latest reply on Mar 16, 2016 by Philippe
Hello,

there is a bug in the HAL library file stm32f3xx_hal_dac_ex.c when using STM32F334.
The file version is 1.2 (last version in the firmware package 1.4 for STM32F3).
I want to enable the output switch for the DAC2 output 1.
The bug is in the function HAL_DAC_ConfigChannel().
The DAC2 output 1  doesn't have a buffer output but a switch output.

Lines concerned

  /* Configure for the selected DAC channel: buffer output or switch output, trigger */
  /* Set TSELx and TENx bits according to DAC_Trigger value */
  /* Set BOFFx bit according to DAC_OutputBuffer value OR */   
  /* Set OUTEN bit according to DAC_OutputSwitch value */   
#if defined(STM32F328xx)
  tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);
#elif defined(STM32F334x8)
  if (Channel == DAC_CHANNEL_1) /* DAC1 channel 1 or DAC2 channel 1*/
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);    
  }
  else /* DAC1 channel 2 */
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);    
  }    
#elif defined(STM32F303x8)
  /* DAC1 channel 1 */
  if ((hdac->Instance == DAC1) && (Channel == DAC_CHANNEL_1)) 
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);    
  }
  else /* DAC1 channel 2 & DAC2 channel 1 */
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);    
  }    
#else
  tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
#endif


This should be 

  /* Configure for the selected DAC channel: buffer output or switch output, trigger */
  /* Set TSELx and TENx bits according to DAC_Trigger value */
  /* Set BOFFx bit according to DAC_OutputBuffer value OR */   
  /* Set OUTEN bit according to DAC_OutputSwitch value */   
#if defined(STM32F328xx)
  tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);
#elif defined(STM32F303x8)
  if (Channel == DAC_CHANNEL_1) /* DAC1 channel 1 or DAC2 channel 1*/
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);    
  }
  else /* DAC1 channel 2 */
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);    
  }    
#elif defined(STM32F334x8)
  /* DAC1 channel 1 */
  if ((hdac->Instance == DAC1) && (Channel == DAC_CHANNEL_1)) 
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);    
  }
  else /* DAC1 channel 2 & DAC2 channel 1 */
  {
    tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);    
  }    
#else
  tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
#endif

Philippe

Outcomes