Skip to content

Commit c5cc9ec

Browse files
committed
NUCLEO_F207ZG: Fix issue with tests-api-analogout and GCC_ARM
Without this fix the tests-api-analogout test is fail with GCC_ARM.
1 parent df88a9d commit c5cc9ec

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

targets/TARGET_STM/TARGET_STM32F2/analogout_device.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2016, STMicroelectronics
2+
* Copyright (c) 2017, STMicroelectronics
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -25,26 +25,27 @@
2525
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
28+
#include "mbed_assert.h"
2829
#include "analogout_api.h"
2930

3031
#if DEVICE_ANALOGOUT
3132

3233
#include "cmsis.h"
3334
#include "pinmap.h"
3435
#include "mbed_error.h"
35-
#include "stm32f2xx_hal.h"
3636
#include "PeripheralPins.h"
3737

38-
void analogout_init(dac_t *obj, PinName pin)
39-
{
40-
DAC_ChannelConfTypeDef sConfig;
38+
void analogout_init(dac_t *obj, PinName pin) {
39+
DAC_ChannelConfTypeDef sConfig = {0};
4140

42-
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
41+
// Get the peripheral name from the pin and assign it to the object
4342
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
44-
// Get the functions (dac channel) from the pin and assign it to the object
43+
MBED_ASSERT(obj->dac != (DACName)NC);
44+
45+
// Get the pin function and assign the used channel to the object
4546
uint32_t function = pinmap_function(pin, PinMap_DAC);
4647
MBED_ASSERT(function != (uint32_t)NC);
47-
// Save the channel for the write and read functions
48+
4849
switch (STM_PIN_CHANNEL(function)) {
4950
case 1:
5051
obj->channel = DAC_CHANNEL_1;
@@ -59,18 +60,17 @@ void analogout_init(dac_t *obj, PinName pin)
5960
break;
6061
}
6162

62-
if (obj->dac == (DACName)NC) {
63-
error("DAC pin mapping failed");
64-
}
65-
6663
// Configure GPIO
6764
pinmap_pinout(pin, PinMap_DAC);
6865

69-
__GPIOA_CLK_ENABLE();
66+
// Save the pin for future use
67+
obj->pin = pin;
7068

71-
__DAC_CLK_ENABLE();
69+
// Enable DAC clock
70+
__HAL_RCC_DAC_CLK_ENABLE();
7271

73-
obj->handle.Instance = DAC;
72+
// Configure DAC
73+
obj->handle.Instance = (DAC_TypeDef *)(obj->dac);
7474
if (HAL_DAC_Init(&obj->handle) != HAL_OK ) {
7575
error("HAL_DAC_Init failed");
7676
}
@@ -85,10 +85,14 @@ void analogout_init(dac_t *obj, PinName pin)
8585
analogout_write_u16(obj, 0);
8686
}
8787

88-
void analogout_free(dac_t *obj)
89-
{
90-
}
91-
88+
void analogout_free(dac_t *obj) {
89+
// Reset DAC and disable clock
90+
__HAL_RCC_DAC_FORCE_RESET();
91+
__HAL_RCC_DAC_RELEASE_RESET();
92+
__HAL_RCC_DAC_CLK_DISABLE();
9293

94+
// Configure GPIO
95+
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
96+
}
9397

9498
#endif // DEVICE_ANALOGOUT

targets/TARGET_STM/TARGET_STM32F2/objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct analogin_s {
6262

6363
struct dac_s {
6464
DACName dac;
65-
uint8_t channel;
65+
PinName pin;
66+
uint32_t channel;
6667
DAC_HandleTypeDef handle;
6768
};
6869

0 commit comments

Comments
 (0)