6868/// tim.callback(lambda t: ...) # set callback for update interrupt (t=tim instance)
6969/// tim.callback(None) # clear callback
7070///
71- /// *Note:* Timer 3 is reserved for internal use . Timer 5 controls
71+ /// *Note:* Timer 3 is used for fading the blue LED . Timer 5 controls
7272/// the servo driver, and Timer 6 is used for timed ADC/DAC reading/writing.
7373/// It is recommended to use the other timers in your programs.
7474
7575// The timers can be used by multiple drivers, and need a common point for
7676// the interrupts to be dispatched, so they are all collected here.
7777//
7878// TIM3:
79- // - flash storage controller, to flush the cache
80- // - USB CDC interface, interval, to check for new data
8179// - LED 4, PWM to set the LED intensity
8280//
8381// TIM5:
@@ -144,7 +142,6 @@ typedef struct _pyb_timer_obj_t {
144142#define TIMER_CNT_MASK (self ) ((self)->is_32bit ? 0xffffffff : 0xffff)
145143#define TIMER_CHANNEL (self ) ((((self)->channel) - 1) << 2)
146144
147- TIM_HandleTypeDef TIM3_Handle ;
148145TIM_HandleTypeDef TIM5_Handle ;
149146TIM_HandleTypeDef TIM6_Handle ;
150147
@@ -171,34 +168,6 @@ void timer_deinit(void) {
171168 }
172169}
173170
174- // TIM3 is set-up for the USB CDC interface
175- void timer_tim3_init (void ) {
176- // set up the timer for USBD CDC
177- __TIM3_CLK_ENABLE ();
178-
179- TIM3_Handle .Instance = TIM3 ;
180- TIM3_Handle .Init .Period = (USBD_CDC_POLLING_INTERVAL * 1000 ) - 1 ; // TIM3 fires every USBD_CDC_POLLING_INTERVAL ms
181- TIM3_Handle .Init .Prescaler = timer_get_source_freq (3 ) / 1000000 - 1 ; // TIM3 runs at 1MHz
182- TIM3_Handle .Init .ClockDivision = TIM_CLOCKDIVISION_DIV1 ;
183- TIM3_Handle .Init .CounterMode = TIM_COUNTERMODE_UP ;
184- HAL_TIM_Base_Init (& TIM3_Handle );
185-
186- HAL_NVIC_SetPriority (TIM3_IRQn , IRQ_PRI_TIM3 , IRQ_SUBPRI_TIM3 );
187- HAL_NVIC_EnableIRQ (TIM3_IRQn );
188-
189- if (HAL_TIM_Base_Start (& TIM3_Handle ) != HAL_OK ) {
190- /* Starting Error */
191- }
192- }
193-
194- /* unused
195- void timer_tim3_deinit(void) {
196- // reset TIM3 timer
197- __TIM3_FORCE_RESET();
198- __TIM3_RELEASE_RESET();
199- }
200- */
201-
202171// TIM5 is set-up for the servo controller
203172// This function inits but does not start the timer
204173void timer_tim5_init (void ) {
@@ -250,10 +219,6 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) {
250219
251220// Interrupt dispatch
252221void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef * htim ) {
253- #if !defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC )
254- if (htim == & TIM3_Handle ) {
255- } else
256- #endif
257222 if (htim == & TIM5_Handle ) {
258223 servo_timer_irq_callback ();
259224 }
@@ -655,11 +620,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args,
655620 switch (tim -> tim_id ) {
656621 case 1 : tim -> tim .Instance = TIM1 ; tim -> irqn = TIM1_UP_TIM10_IRQn ; break ;
657622 case 2 : tim -> tim .Instance = TIM2 ; tim -> irqn = TIM2_IRQn ; tim -> is_32bit = true; break ;
658- #if defined(MICROPY_HW_USE_ALT_IRQ_FOR_CDC )
659623 case 3 : tim -> tim .Instance = TIM3 ; tim -> irqn = TIM3_IRQn ; break ;
660- #else
661- 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
662- #endif
663624 case 4 : tim -> tim .Instance = TIM4 ; tim -> irqn = TIM4_IRQn ; break ;
664625 case 5 : tim -> tim .Instance = TIM5 ; tim -> irqn = TIM5_IRQn ; tim -> is_32bit = true; break ;
665626 #if defined(TIM6 )
0 commit comments