Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
Revision 159:3b23f6d9ecb9, committed 2014-04-14
- Comitter:
- mbed_official
- Date:
- Mon Apr 14 10:30:07 2014 +0100
- Parent:
- 158:3121b9889f7b
- Child:
- 160:6870f452afa4
- Commit message:
- Synchronized with git revision 3afbb87c326e6dba456e6421d226611464fab342
Full URL: https://github.com/mbedmicro/mbed/commit/3afbb87c326e6dba456e6421d226611464fab342/
[DISCO_F407VG] Fixed PWM PA_3 (and PC_9) output issue.
Changed in this revision
--- a/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pwmout_api.c Fri Apr 11 17:30:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pwmout_api.c Mon Apr 14 10:30:07 2014 +0100
@@ -43,7 +43,7 @@
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
//{PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
//{PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
- {PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
+ {PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
//{PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
//{PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
{PA_5, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH1
@@ -77,7 +77,7 @@
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
- {PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
+ {PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
{NC, NC, 0}
};
@@ -183,13 +183,13 @@
break;
// Channels 3
case PA_2:
- case PA_3:
+ //case PA_3:
case PA_10:
//case PB_0:
case PB_8:
case PB_10:
case PC_8:
- case PC_9:
+ //case PC_9:
channel = TIM_CHANNEL_3;
break;
// Channels 3N
@@ -199,10 +199,11 @@
complementary_channel = 1;
break;
// Channels 4
- //case PA_3:
+ case PA_3:
case PA_11:
//case PB_1:
case PB_9:
+ case PC_9:
channel = TIM_CHANNEL_4;
break;
default:
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/analogout_api.c Fri Apr 11 17:30:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/analogout_api.c Mon Apr 14 10:30:07 2014 +0100
@@ -33,7 +33,7 @@
#include "pinmap.h"
#include "error.h"
-#define RANGE_12BIT (0xFFF)
+#define DAC_RANGE (0xFFF) // 12 bits
static const PinMap PinMap_DAC[] = {
{PA_4, DAC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // DAC_OUT1
@@ -56,7 +56,7 @@
// Configure GPIO
pinmap_pinout(pin, PinMap_DAC);
- // Save the channel for the write and read functions
+ // Save the channel for future use
obj->channel = pin;
// Enable DAC clock
@@ -71,6 +71,12 @@
}
void analogout_free(dac_t *obj) {
+ DAC_TypeDef *dac = (DAC_TypeDef *)(obj->dac);
+ // Disable DAC
+ DAC_DeInit(dac);
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, DISABLE);
+ // Configure GPIO
+ pin_function(obj->channel, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
}
static inline void dac_write(dac_t *obj, uint16_t value) {
@@ -87,15 +93,15 @@
if (value < 0.0f) {
dac_write(obj, 0); // Min value
} else if (value > 1.0f) {
- dac_write(obj, (uint16_t)RANGE_12BIT); // Max value
+ dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
- dac_write(obj, (uint16_t)(value * (float)RANGE_12BIT));
+ dac_write(obj, (uint16_t)(value * (float)DAC_RANGE));
}
}
void analogout_write_u16(dac_t *obj, uint16_t value) {
- if (value > (uint16_t)RANGE_12BIT) {
- dac_write(obj, (uint16_t)RANGE_12BIT); // Max value
+ if (value > (uint16_t)DAC_RANGE) {
+ dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
dac_write(obj, value);
}
@@ -103,7 +109,7 @@
float analogout_read(dac_t *obj) {
uint32_t value = dac_read(obj);
- return (float)value * (1.0f / (float)RANGE_12BIT);
+ return (float)((float)value * (1.0f / (float)DAC_RANGE));
}
uint16_t analogout_read_u16(dac_t *obj) {
