From 66b96822fb33863fde5ce13a6bdeb99a404575dc Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 4 Dec 2015 14:07:15 +0000 Subject: 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. --- stmhal/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'stmhal/timer.c') 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) -- cgit v1.2.3