diff options
Diffstat (limited to 'stmhal/dac.c')
-rw-r--r-- | stmhal/dac.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/stmhal/dac.c b/stmhal/dac.c index acfcf4e91a..45e709c01d 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include <stdio.h> #include <stdint.h> #include <string.h> @@ -73,6 +74,7 @@ STATIC DAC_HandleTypeDef DAC_Handle; void dac_init(void) { + memset(&DAC_Handle, 0, sizeof DAC_Handle); DAC_Handle.Instance = DAC; DAC_Handle.State = HAL_DAC_STATE_RESET; HAL_DAC_Init(&DAC_Handle); @@ -142,7 +144,10 @@ STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const // stop anything already going on HAL_DAC_Stop(&DAC_Handle, dac->dac_channel); - HAL_DAC_Stop_DMA(&DAC_Handle, dac->dac_channel); + if ((dac->dac_channel == DAC_CHANNEL_1 && DAC_Handle.DMA_Handle1 != NULL) + || (dac->dac_channel == DAC_CHANNEL_2 && DAC_Handle.DMA_Handle2 != NULL)) { + HAL_DAC_Stop_DMA(&DAC_Handle, dac->dac_channel); + } dac->state = 0; |