I started with another F0 example (the USB-CDC example), which works great. Then I added the DAC code from the F3 example, which was pretty straight-forward, except I think I had to add the DAC Driver system settings in mcuconf.h. Unfortunately it's not working. The DAC appears to work, but it's not streaming.
You can find all the code here.
The relevant configuration bits are:
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 FALSE
#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, 3)
/*
* GPT driver system settings.
*/
#define STM32_GPT_USE_TIM1 TRUE
#define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM14 FALSE
#define STM32_GPT_TIM1_IRQ_PRIORITY 2
#define STM32_GPT_TIM2_IRQ_PRIORITY 2
#define STM32_GPT_TIM3_IRQ_PRIORITY 2
#define STM32_GPT_TIM14_IRQ_PRIORITY 2
...
static const DACConfig dac1cfg1 = {
.init = 2047U,
.datamode = DAC_DHRM_12BIT_RIGHT
};
static const DACConversionGroup dacgrpcfg1 = {
.num_channels = 1U,
.end_cb = end_cb1,
.error_cb = error_cb1,
.trigger = DAC_TRG(0)
};
/*
* GPT1 configuration.
*/
static const GPTConfig gpt1cfg1 = {
.frequency = 1000000U,
.callback = NULL,
.cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
.dier = 0U
};
...
/*
* Starting DAC1 driver, setting up the output pin as analog as suggested
* by the Reference Manual.
*/
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
dacStart(&DACD1, &dac1cfg1);
/*
* Starting GPT1 driver, it is used for triggering the DAC.
*/
gptStart(&GPTD1, &gpt1cfg1);
/*
* Starting a continuous conversion.
*/
dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE);
gptStartContinuous(&GPTD1, 2U);
I believe the DAC is working because I can change the init value and see a different output on the DAC, so I suspect it the GPT configuration. I also added a GPIO toggle in the end callback and I don't see that happening.