From 75c85b80ff7b2e4ce68e231c3e49b41dd73f90ef Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 20 Dec 2011 17:31:06 +0000 Subject: PWM driver works git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4205 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/configs/stm3240g-eval/include/board.h | 8 +++-- .../configs/stm3240g-eval/src/stm3240g-internal.h | 8 +++-- nuttx/configs/stm3240g-eval/src/up_pwm.c | 38 +++++++++++++++------- 3 files changed, 38 insertions(+), 16 deletions(-) (limited to 'nuttx/configs') diff --git a/nuttx/configs/stm3240g-eval/include/board.h b/nuttx/configs/stm3240g-eval/include/board.h index 9ae54a4d0..4002f918a 100755 --- a/nuttx/configs/stm3240g-eval/include/board.h +++ b/nuttx/configs/stm3240g-eval/include/board.h @@ -269,9 +269,13 @@ * a pulse train using TIM4 CH2. This pin is used by FSMC is connect to CN5 just for this * purpose: * - * PD13 FSMC_A18 / MC_TIM4_CH2 pin 33 (EnB) + * PD13 FSMC_A18 / MC_TIM4_CH2 pin 33 (EnB) * - * FSMC must be disabled in this case! + * FSMC must be disabled in this case! PD13 is available at: + * + * Daughterboard Extension Connector, CN3, pin 32 - available + * TFT LCD Connector, CN19, pin 17 -- not available without removing the LCD. + * Motor Control Connector CN15, pin 33 -- no available unless to connect SB14. */ #define GPIO_TIM4_CH2 GPIO_TIM4_CH2_2 diff --git a/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h b/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h index 415831191..0ccdaf40a 100644 --- a/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h +++ b/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h @@ -90,9 +90,13 @@ * a pulse train using TIM4 CH2. This pin is used by FSMC is connect to CN5 just for this * purpose: * - * PD13 FSMC_A18 / MC_TIM4_CH2 pin 33 (EnB) + * PD13 FSMC_A18 / MC_TIM4_CH2 pin 33 (EnB) * - * FSMC must be disabled in this case! + * FSMC must be disabled in this case! PD13 is available at: + * + * Daughterboard Extension Connector, CN3, pin 32 - available + * TFT LCD Connector, CN19, pin 17 -- not available without removing the LCD. + * Motor Control Connector CN15, pin 33 -- no available unless to connect SB14. */ #define STM3240G_EVAL_PWMTIMER 4 diff --git a/nuttx/configs/stm3240g-eval/src/up_pwm.c b/nuttx/configs/stm3240g-eval/src/up_pwm.c index 503e26073..d0701b2b2 100644 --- a/nuttx/configs/stm3240g-eval/src/up_pwm.c +++ b/nuttx/configs/stm3240g-eval/src/up_pwm.c @@ -40,6 +40,7 @@ #include +#include #include #include @@ -102,27 +103,40 @@ * ************************************************************************************/ -void pwm_devinit(void) +int pwm_devinit(void) { + static bool initialized = false; struct pwm_lowerhalf_s *pwm; int ret; - /* Call stm32_pwminitialize() to get an instance of the PWM interface */ + /* Have we already initialized? */ - pwm = stm32_pwminitialize(STM3240G_EVAL_PWMTIMER); - if (!pwm) + if (!initialized) { - dbg("Failed to get the STM32 PWM lower half\n"); - return; - } + /* Call stm32_pwminitialize() to get an instance of the PWM interface */ - /* Register the PWM driver at "/dev/pwm0" */ + pwm = stm32_pwminitialize(STM3240G_EVAL_PWMTIMER); + if (!pwm) + { + dbg("Failed to get the STM32 PWM lower half\n"); + return -ENODEV; + } - ret = pwm_register("/dev/pwm0", pwm); - if (ret < 0) - { - adbg("pwm_register failed: %d\n", ret); + /* Register the PWM driver at "/dev/pwm0" */ + + ret = pwm_register("/dev/pwm0", pwm); + if (ret < 0) + { + adbg("pwm_register failed: %d\n", ret); + return ret; + } + + /* Now we are initialized */ + + initialized = true; } + + return OK; } #endif /* HAVE_PWM */ -- cgit v1.2.3