From 88b82e312de8a11c0418ee2cfe0fde4ca7bc516d Mon Sep 17 00:00:00 2001 From: bcostm Date: Thu, 5 Oct 2017 16:35:05 +0200 Subject: [PATCH] fix init struct analogout --- targets/TARGET_STM/TARGET_STM32F0/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32F3/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32F4/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32F7/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32L0/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32L1/analogout_device.c | 4 +++- targets/TARGET_STM/TARGET_STM32L4/analogout_device.c | 2 ++ 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F0/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F0/analogout_device.c index c8891f85d8..da73e70b30 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F0/analogout_device.c @@ -36,7 +36,7 @@ #include "PeripheralPins.h" void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -71,6 +71,8 @@ void analogout_init(dac_t *obj, PinName pin) { // Configure DAC obj->handle.Instance = (DAC_TypeDef *)(obj->dac); + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32F3/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F3/analogout_device.c index 6bc7da1e5b..4b17b6e5f2 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F3/analogout_device.c @@ -40,7 +40,7 @@ static int pa4_used = 0; static int pa5_used = 0; void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -83,6 +83,8 @@ void analogout_init(dac_t *obj, PinName pin) { // Configure DAC obj->handle.Instance = (DAC_TypeDef *)(obj->dac); + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c index 802fad6bbb..da07ad678b 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c @@ -36,7 +36,7 @@ #include "PeripheralPins.h" void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -71,6 +71,8 @@ void analogout_init(dac_t *obj, PinName pin) { __HAL_RCC_DAC_CLK_ENABLE(); obj->handle.Instance = DAC; + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32F7/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F7/analogout_device.c index 8003d35a51..d817d3d280 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F7/analogout_device.c @@ -36,7 +36,7 @@ #include "PeripheralPins.h" void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -71,6 +71,8 @@ void analogout_init(dac_t *obj, PinName pin) { __DAC_CLK_ENABLE(); obj->handle.Instance = DAC; + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32L0/analogout_device.c b/targets/TARGET_STM/TARGET_STM32L0/analogout_device.c index dbf8f9cab1..499008b73a 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32L0/analogout_device.c @@ -40,7 +40,7 @@ static int channel1_used = 0; static int channel2_used = 0; void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -74,6 +74,8 @@ void analogout_init(dac_t *obj, PinName pin) { // Configure DAC obj->handle.Instance = DAC; + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32L1/analogout_device.c b/targets/TARGET_STM/TARGET_STM32L1/analogout_device.c index 7dd2cb7eac..2220b7d592 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32L1/analogout_device.c @@ -40,7 +40,7 @@ static int pa4_used = 0; static int pa5_used = 0; void analogout_init(dac_t *obj, PinName pin) { - DAC_ChannelConfTypeDef sConfig; + DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); @@ -68,6 +68,8 @@ void analogout_init(dac_t *obj, PinName pin) { obj->pin = pin; obj->handle.Instance = DAC; + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } diff --git a/targets/TARGET_STM/TARGET_STM32L4/analogout_device.c b/targets/TARGET_STM/TARGET_STM32L4/analogout_device.c index bd5bafbd92..92386ab594 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32L4/analogout_device.c @@ -75,6 +75,8 @@ void analogout_init(dac_t *obj, PinName pin) { // Configure DAC obj->handle.Instance = DAC; + obj->handle.State = HAL_DAC_STATE_RESET; + if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); }