/** * @brief DAC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hdac: DAC handle pointer * @retval None */ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock */ DACx_CHANNEL_GPIO_CLK_ENABLE(); /* DAC Periph clock enable */ DACx_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* DAC Channel1 GPIO pin configuration */ GPIO_InitStruct.Pin = DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_HIGH_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_HIGH_GPIO_PORT, &GPIO_InitStruct); /* DAC Channel2 GPIO pin configuration */ GPIO_InitStruct.Pin = DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_LOW_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_LOW_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the NVIC #################################################*/ /* NVIC configuration for DAC interrupt */ /* Priority: mid-priority */ HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 3, 0); HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); }
/** * @brief DAC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hdac: DAC handle pointer * @retval None */ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) { GPIO_InitTypeDef GPIO_InitStruct; static DMA_HandleTypeDef hdma_dac1; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock ****************************************/ DACx_CHANNEL_GPIO_CLK_ENABLE(); /* DAC Periph clock enable */ DACx_CLK_ENABLE(); /* DMA1 clock enable */ DMAx_CLK_ENABLE(); /* SYSCFG clock enable for DMA remapping */ __SYSCFG_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* DAC Channel1 GPIO pin configuration */ GPIO_InitStruct.Pin = DACx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(DACx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the DMA ##########################################*/ /* Set the parameters to be configured for DACx_DMA1_CHANNEL3 */ hdma_dac1.Instance = DACx_DMA_INSTANCE; hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_dac1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_dac1.Init.MemInc = DMA_MINC_ENABLE; hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_dac1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_dac1.Init.Mode = DMA_CIRCULAR; hdma_dac1.Init.Priority = DMA_PRIORITY_HIGH; HAL_DMA_Init(&hdma_dac1); /* Associate the initialized DMA handle to the the DAC handle */ __HAL_LINKDMA(hdac, DMA_Handle1, hdma_dac1); /*##-4- Configure the NVIC for DMA #########################################*/ /* Enable the DMA1_Channel3 IRQ Channel */ HAL_NVIC_SetPriority(DACx_DMA_IRQn, 2, 0); HAL_NVIC_EnableIRQ(DACx_DMA_IRQn); /*##-5- Configure the SYSCFG for DMA remapping #############################*/ __HAL_REMAPDMA_CHANNEL_ENABLE(HAL_REMAPDMA_TIM6_DAC1_CH1_DMA1_CH3); }
/** * @brief DAC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hdac: DAC handle pointer * @retval None */ void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock ****************************************/ DACx_CHANNEL_GPIO_CLK_ENABLE(); /* DAC Periph clock enable */ DACx_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* DAC Channel1 GPIO pin configuration */ GPIO_InitStruct.Pin = DACx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(DACx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); }