Skip to content

NUCLEO_F207ZG: Analogout improvement #5188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions targets/TARGET_STM/TARGET_STM32F2/analogout_device.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2016, STMicroelectronics
* Copyright (c) 2017, STMicroelectronics
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -25,26 +25,28 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "mbed_assert.h"
#include "analogout_api.h"

#if DEVICE_ANALOGOUT

#include "cmsis.h"
#include "pinmap.h"
#include "mbed_error.h"
#include "stm32f2xx_hal.h"
#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
// Get the peripheral name from the pin and assign it to the object
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
// Get the functions (dac channel) from the pin and assign it to the object
MBED_ASSERT(obj->dac != (DACName)NC);

// Get the pin function and assign the used channel to the object
uint32_t function = pinmap_function(pin, PinMap_DAC);
MBED_ASSERT(function != (uint32_t)NC);
// Save the channel for the write and read functions

switch (STM_PIN_CHANNEL(function)) {
case 1:
obj->channel = DAC_CHANNEL_1;
Expand All @@ -59,18 +61,19 @@ void analogout_init(dac_t *obj, PinName pin)
break;
}

if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed");
}

// Configure GPIO
pinmap_pinout(pin, PinMap_DAC);

__GPIOA_CLK_ENABLE();
// Save the pin for future use
obj->pin = pin;

// Enable DAC clock
__HAL_RCC_DAC_CLK_ENABLE();

__DAC_CLK_ENABLE();
// Configure DAC
obj->handle.Instance = (DAC_TypeDef *)(obj->dac);
obj->handle.State = HAL_DAC_STATE_RESET;

obj->handle.Instance = DAC;
if (HAL_DAC_Init(&obj->handle) != HAL_OK ) {
error("HAL_DAC_Init failed");
}
Expand All @@ -87,8 +90,13 @@ void analogout_init(dac_t *obj, PinName pin)

void analogout_free(dac_t *obj)
{
}

// Reset DAC and disable clock
__HAL_RCC_DAC_FORCE_RESET();
__HAL_RCC_DAC_RELEASE_RESET();
__HAL_RCC_DAC_CLK_DISABLE();

// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}

#endif // DEVICE_ANALOGOUT
3 changes: 2 additions & 1 deletion targets/TARGET_STM/TARGET_STM32F2/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ struct analogin_s {

struct dac_s {
DACName dac;
uint8_t channel;
PinName pin;
uint32_t channel;
DAC_HandleTypeDef handle;
};

Expand Down