mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5188 from bcostm/fix_dac_f207zg
NUCLEO_F207ZG: Analogout improvementpull/5180/merge
commit
3354327a9f
|
@ -1,5 +1,5 @@
|
||||||
/* mbed Microcontroller Library
|
/* mbed Microcontroller Library
|
||||||
* Copyright (c) 2016, STMicroelectronics
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* 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.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include "mbed_assert.h"
|
||||||
#include "analogout_api.h"
|
#include "analogout_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
|
@ -32,19 +33,20 @@
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
#include "stm32f2xx_hal.h"
|
|
||||||
#include "PeripheralPins.h"
|
#include "PeripheralPins.h"
|
||||||
|
|
||||||
void analogout_init(dac_t *obj, PinName pin)
|
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);
|
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);
|
uint32_t function = pinmap_function(pin, PinMap_DAC);
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
MBED_ASSERT(function != (uint32_t)NC);
|
||||||
// Save the channel for the write and read functions
|
|
||||||
switch (STM_PIN_CHANNEL(function)) {
|
switch (STM_PIN_CHANNEL(function)) {
|
||||||
case 1:
|
case 1:
|
||||||
obj->channel = DAC_CHANNEL_1;
|
obj->channel = DAC_CHANNEL_1;
|
||||||
|
@ -59,18 +61,19 @@ void analogout_init(dac_t *obj, PinName pin)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj->dac == (DACName)NC) {
|
|
||||||
error("DAC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_DAC);
|
pinmap_pinout(pin, PinMap_DAC);
|
||||||
|
|
||||||
__GPIOA_CLK_ENABLE();
|
// Save the pin for future use
|
||||||
|
obj->pin = pin;
|
||||||
|
|
||||||
__DAC_CLK_ENABLE();
|
// Enable DAC clock
|
||||||
|
__HAL_RCC_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 ) {
|
if (HAL_DAC_Init(&obj->handle) != HAL_OK ) {
|
||||||
error("HAL_DAC_Init failed");
|
error("HAL_DAC_Init failed");
|
||||||
}
|
}
|
||||||
|
@ -87,8 +90,13 @@ void analogout_init(dac_t *obj, PinName pin)
|
||||||
|
|
||||||
void analogout_free(dac_t *obj)
|
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
|
#endif // DEVICE_ANALOGOUT
|
||||||
|
|
|
@ -62,7 +62,8 @@ struct analogin_s {
|
||||||
|
|
||||||
struct dac_s {
|
struct dac_s {
|
||||||
DACName dac;
|
DACName dac;
|
||||||
uint8_t channel;
|
PinName pin;
|
||||||
|
uint32_t channel;
|
||||||
DAC_HandleTypeDef handle;
|
DAC_HandleTypeDef handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue