summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-13 15:53:39 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-13 15:53:39 +1100
commit8aad22fdca757fd7135fb2f68ff8023a1f5bebc3 (patch)
treeb88ee2833642c5ccf234cce540c944ba0cde9b8b
parent6e91ab58063a29fc754ac42ede5612076b2a0199 (diff)
stm32/timer: Support MCUs that don't have TIM4 and/or TIM5.
-rw-r--r--ports/stm32/timer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c
index 0744c2f59..bac63ae92 100644
--- a/ports/stm32/timer.c
+++ b/ports/stm32/timer.c
@@ -162,6 +162,7 @@ void timer_deinit(void) {
}
}
+#if defined(TIM5)
// TIM5 is set-up for the servo controller
// This function inits but does not start the timer
void timer_tim5_init(void) {
@@ -181,6 +182,7 @@ void timer_tim5_init(void) {
HAL_TIM_PWM_Init(&TIM5_Handle);
}
+#endif
#if defined(TIM6)
// Init TIM6 with a counter-overflow at the given frequency (given in Hz)
@@ -557,8 +559,12 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons
case 1: __HAL_RCC_TIM1_CLK_ENABLE(); break;
case 2: __HAL_RCC_TIM2_CLK_ENABLE(); break;
case 3: __HAL_RCC_TIM3_CLK_ENABLE(); break;
+ #if defined(TIM4)
case 4: __HAL_RCC_TIM4_CLK_ENABLE(); break;
+ #endif
+ #if defined(TIM5)
case 5: __HAL_RCC_TIM5_CLK_ENABLE(); break;
+ #endif
#if defined(TIM6)
case 6: __HAL_RCC_TIM6_CLK_ENABLE(); break;
#endif
@@ -646,8 +652,12 @@ STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = {
#endif
TIM_ENTRY(2, TIM2_IRQn),
TIM_ENTRY(3, TIM3_IRQn),
+ #if defined(TIM4)
TIM_ENTRY(4, TIM4_IRQn),
+ #endif
+ #if defined(TIM5)
TIM_ENTRY(5, TIM5_IRQn),
+ #endif
#if defined(TIM6)
TIM_ENTRY(6, TIM6_DAC_IRQn),
#endif
@@ -1049,8 +1059,12 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (self->tim.Instance != TIM1
&& self->tim.Instance != TIM2
&& self->tim.Instance != TIM3
+ #if defined(TIM4)
&& self->tim.Instance != TIM4
+ #endif
+ #if defined(TIM5)
&& self->tim.Instance != TIM5
+ #endif
#if defined(TIM8)
&& self->tim.Instance != TIM8
#endif