summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/timer.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-18 15:54:15 +0100
committerDamien George <damien.p.george@gmail.com>2015-04-18 21:40:58 +0100
commitc92c7a69fd87ad0c2d330271bc67aaf9d4838fc3 (patch)
tree5f31f5de224fb6bfcd18634dec5964d2dd9fa733 /stmhal/timer.c
parent7d6595fd188487670635d3e870b6cb6c67edd022 (diff)
downloadmicropython-c92c7a69fd87ad0c2d330271bc67aaf9d4838fc3.tar.gz
micropython-c92c7a69fd87ad0c2d330271bc67aaf9d4838fc3.zip
stmhal: Exclude code for those timers that don't exist in the hardware.
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r--stmhal/timer.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c
index ed592069cc..b75dd688c0 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -223,6 +223,7 @@ void timer_tim5_init(void) {
HAL_TIM_PWM_Init(&TIM5_Handle);
}
+#if defined(TIM6)
// Init TIM6 with a counter-overflow at the given frequency (given in Hz)
// TIM6 is used by the DAC and ADC for auto sampling at a given frequency
// This function inits but does not start the timer
@@ -247,6 +248,7 @@ void timer_tim6_init(uint freq) {
TIM6_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; // unused for TIM6
HAL_TIM_Base_Init(&TIM6_Handle);
}
+#endif
// Interrupt dispatch
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
@@ -587,15 +589,27 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
case 3: __TIM3_CLK_ENABLE(); break;
case 4: __TIM4_CLK_ENABLE(); break;
case 5: __TIM5_CLK_ENABLE(); break;
+ #if defined(TIM6)
case 6: __TIM6_CLK_ENABLE(); break;
+ #endif
+ #if defined(TIM7)
case 7: __TIM7_CLK_ENABLE(); break;
+ #endif
+ #if defined(TIM8)
case 8: __TIM8_CLK_ENABLE(); break;
+ #endif
case 9: __TIM9_CLK_ENABLE(); break;
case 10: __TIM10_CLK_ENABLE(); break;
case 11: __TIM11_CLK_ENABLE(); break;
+ #if defined(TIM12)
case 12: __TIM12_CLK_ENABLE(); break;
+ #endif
+ #if defined(TIM13)
case 13: __TIM13_CLK_ENABLE(); break;
+ #endif
+ #if defined(TIM14)
case 14: __TIM14_CLK_ENABLE(); break;
+ #endif
}
// set IRQ priority (if not a special timer)
@@ -643,15 +657,27 @@ STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
case 3: nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Timer 3 is for internal use only")); // TIM3 used for low-level stuff; go via regs if necessary
case 4: tim->tim.Instance = TIM4; tim->irqn = TIM4_IRQn; break;
case 5: tim->tim.Instance = TIM5; tim->irqn = TIM5_IRQn; tim->is_32bit = true; break;
+ #if defined(TIM6)
case 6: tim->tim.Instance = TIM6; tim->irqn = TIM6_DAC_IRQn; break;
+ #endif
+ #if defined(TIM7)
case 7: tim->tim.Instance = TIM7; tim->irqn = TIM7_IRQn; break;
+ #endif
+ #if defined(TIM8)
case 8: tim->tim.Instance = TIM8; tim->irqn = TIM8_UP_TIM13_IRQn; break;
+ #endif
case 9: tim->tim.Instance = TIM9; tim->irqn = TIM1_BRK_TIM9_IRQn; break;
case 10: tim->tim.Instance = TIM10; tim->irqn = TIM1_UP_TIM10_IRQn; break;
case 11: tim->tim.Instance = TIM11; tim->irqn = TIM1_TRG_COM_TIM11_IRQn; break;
+ #if defined(TIM12)
case 12: tim->tim.Instance = TIM12; tim->irqn = TIM8_BRK_TIM12_IRQn; break;
+ #endif
+ #if defined(TIM13)
case 13: tim->tim.Instance = TIM13; tim->irqn = TIM8_UP_TIM13_IRQn; break;
+ #endif
+ #if defined(TIM14)
case 14: tim->tim.Instance = TIM14; tim->irqn = TIM8_TRG_COM_TIM14_IRQn; break;
+ #endif
default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id));
}
@@ -986,7 +1012,10 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
&& self->tim.Instance != TIM3
&& self->tim.Instance != TIM4
&& self->tim.Instance != TIM5
- && self->tim.Instance != TIM8 ) {
+ #if defined(TIM8)
+ && self->tim.Instance != TIM8
+ #endif
+ ) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "encoder not supported on timer %d", self->tim_id));
}