aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/STM32/pwm_lld.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-12-11 15:55:45 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-12-11 15:55:45 +0000
commit59cd37eacb17e1ccb9b640fdbe172fd91a45f331 (patch)
tree07225624c34a975902a3d0f7865b0366752666eb /os/hal/platforms/STM32/pwm_lld.c
parentf2c5dc67eab392655278f2d34b31190dbf94bac1 (diff)
downloadChibiOS-59cd37eacb17e1ccb9b640fdbe172fd91a45f331.tar.gz
ChibiOS-59cd37eacb17e1ccb9b640fdbe172fd91a45f331.tar.bz2
ChibiOS-59cd37eacb17e1ccb9b640fdbe172fd91a45f331.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1415 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/STM32/pwm_lld.c')
-rw-r--r--os/hal/platforms/STM32/pwm_lld.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/os/hal/platforms/STM32/pwm_lld.c b/os/hal/platforms/STM32/pwm_lld.c
index 8188eefb1..2d49eb6be 100644
--- a/os/hal/platforms/STM32/pwm_lld.c
+++ b/os/hal/platforms/STM32/pwm_lld.c
@@ -29,6 +29,11 @@
#if CH_HAL_USE_PWM || defined(__DOXYGEN__)
+/** @brief PWM1 driver identifier.*/
+#if defined(USE_STM32_PWM1) || defined(__DOXYGEN__)
+PWMDriver PWMD1;
+#endif
+
/*===========================================================================*/
/* Low Level Driver exported variables. */
/*===========================================================================*/
@@ -54,6 +59,15 @@
*/
void pwm_lld_init(void) {
+#if USE_STM32_PWM1
+ /* TIM1 reset, ensures reset state in order to avoid trouble with JTAGs.*/
+ RCC->APB2RSTR = RCC_APB2RSTR_TIM1RST;
+ RCC->APB2RSTR = 0;
+
+ /* Driver initialization.*/
+ pwmObjectInit(&PWMD1);
+#endif
+
}
/**
@@ -65,6 +79,12 @@ void pwm_lld_start(PWMDriver *pwmp) {
if (pwmp->pd_state == PWM_STOP) {
/* Clock activation.*/
+#if USE_STM32_PWM1
+ if (&PWMD1 == pwmp) {
+ NVICEnableVector(TIM1_CC_IRQn, STM32_PWM1_IRQ_PRIORITY);
+ RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
+ }
+#endif
}
/* Configuration.*/
}
@@ -76,6 +96,15 @@ void pwm_lld_start(PWMDriver *pwmp) {
*/
void pwm_lld_stop(PWMDriver *pwmp) {
+ /* If in ready state then disables the PWM clock.*/
+ if (pwmp->pd_state == PWM_READY) {
+#if USE_STM32_PWM1
+ if (&PWMD1 == pwmp) {
+ NVICDisableVector(TIM1_CC_IRQn);
+ RCC->APB2ENR &= ~RCC_APB2ENR_TIM1EN;
+ }
+#endif
+ }
}
/**
@@ -105,6 +134,14 @@ bool_t pwm_lld_is_enabled(PWMDriver *pwmp, pwmchannel_t channel) {
void pwm_lld_set_callback(PWMDriver *pwmp, pwmchannel_t channel,
pwmedge_t edge, pwmcallback_t callback) {
+ if (edge == PWM_NONE) {
+ /* Callback disable.*/
+ pwmp->pd_callbacks[channel] = NULL;
+ }
+ else {
+ /* Callback enable.*/
+ pwmp->pd_callbacks[channel] = callback;
+ }
}
/**