mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/pwmout_api.c
- Revision:
- 84:f54042cbc282
- Parent:
- 76:aeb1df146756
- Child:
- 129:0182c99221bc
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/pwmout_api.c Fri Jan 31 10:15:06 2014 +0000 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/pwmout_api.c Mon Feb 03 09:30:05 2014 +0000 @@ -34,11 +34,10 @@ #include "error.h" static const PinMap PinMap_PWM[] = { - {PB_3, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH2 - {PB_4, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH1 - //{PB_10, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH3 - //{PC_7, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH2 - {NC, NC, 0} + {PB_3, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH2 + {PB_4, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH1 + {PB_6, PWM_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM4)}, // TIM4_CH1 + {NC, NC, 0} }; void pwmout_init(pwmout_t* obj, PinName pin) { @@ -52,7 +51,8 @@ // Enable TIM clock if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); if (obj->pwm == PWM_3) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); - + if (obj->pwm == PWM_4) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); + // Configure GPIO pinmap_pinout(pin, PinMap_PWM); @@ -77,10 +77,7 @@ } else if (value > 1.0) { value = 1.0; } - - //while(TIM_GetFlagStatus(tim, TIM_FLAG_Update) == RESET); - //TIM_ClearFlag(tim, TIM_FLAG_Update); - + obj->pulse = (uint32_t)((float)obj->period * value); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; @@ -89,7 +86,7 @@ TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; // Configure channel 1 - if (obj->pin == PB_4) { + if ((obj->pin == PB_4) || (obj->pin == PB_6)) { TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); TIM_OC1Init(tim, &TIM_OCInitStructure); }