summaryrefslogtreecommitdiff
path: root/stmhal/timer.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-04 14:07:15 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-04 14:07:15 +0000
commit66b96822fb33863fde5ce13a6bdeb99a404575dc (patch)
tree3bd14e12de97527afd9f362bdd9aaef0a1f2ec2c /stmhal/timer.c
parent9aaf888b420101fd01c9455f20fda7a09ce8d93d (diff)
stmhal: Add option to free up TIM3 from USB VCP polling.
This is a hack to free up TIM3 so that it can be used by the user. Instead we use the PVD irq to call the USB VCP polling function, and trigger it from SysTick (so SysTick itself does not do any processing). The feature is enabled for pyboard lite only, since it lacks timers.
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r--stmhal/timer.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c
index cf93a01d7..bca3f5457 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -250,9 +250,12 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) {
// Interrupt dispatch
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
+ #if !defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC)
if (htim == &TIM3_Handle) {
USBD_CDC_HAL_TIM_PeriodElapsedCallback();
- } else if (htim == &TIM5_Handle) {
+ } else
+ #endif
+ if (htim == &TIM5_Handle) {
servo_timer_irq_callback();
}
}
@@ -653,7 +656,11 @@ STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
switch (tim->tim_id) {
case 1: tim->tim.Instance = TIM1; tim->irqn = TIM1_UP_TIM10_IRQn; break;
case 2: tim->tim.Instance = TIM2; tim->irqn = TIM2_IRQn; tim->is_32bit = true; break;
+ #if defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC)
+ case 3: tim->tim.Instance = TIM3; tim->irqn = TIM3_IRQn; break;
+ #else
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
+ #endif
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)