EFM32 AnalogOut HAL doesn't enable the DAC

05 Aug 2016

I'm using the EFM32GG-STK3700 and I've found that the AnalogOut does not work. I've traced it down to the API not calling analogout_enable(dac_t *obj, uint8_t enable) after initializing the DAC. It looks like the void analogout_init(dac_t *obj, PinName pin) is missing the analogout_enable at the end. Here's the relevant code with the enable added:

void analogout_init(dac_t *obj, PinName pin)
{
    static uint8_t dac_initialized = 0;
 
    /* init in-memory structure */
    analogout_preinit(obj, pin);
 
    if (!dac_initialized) {
        /* Initialize the DAC. Will disable both DAC channels, so should only be done once */
        /* Use default settings */
        CMU_ClockEnable(cmuClock_DAC0, true);
 
        DAC_Init_TypeDef init = DAC_INIT_DEFAULT;
 
        /* Calculate the DAC clock prescaler value that will result in a DAC clock
         * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK
         * frequency instead of setting a new one. */
        init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY);
 
        /* Set reference voltage to VDD */
        init.reference = dacRefVDD;
 
        DAC_Init(obj->dac, &init);
        dac_initialized = 1;
    }
    /* Use default channel settings */
    DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT;
    DAC_InitChannel(obj->dac, &initChannel, obj->channel);
 
    analogout_enable(obj->dac, 1); // <- This should be here perhaps?
}

Is this the most appropriate place for the enable?