diff options
-rw-r--r-- | stmhal/stm32_it.c | 9 | ||||
-rw-r--r-- | stmhal/storage.h | 3 | ||||
-rw-r--r-- | stmhal/timer.c | 11 |
3 files changed, 10 insertions, 13 deletions
diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c index aaa1aaca7f..90826a5702 100644 --- a/stmhal/stm32_it.c +++ b/stmhal/stm32_it.c @@ -269,10 +269,15 @@ void SysTick_Handler(void) { // work properly. SysTick->CTRL; - // Right now we just have the DMA controllers to process during this - // interrupt and we use a custom dispatch handler. If this needs to + // Right now we have the storage and DMA controllers to process during + // this interrupt and we use custom dispatch handlers. If this needs to // be generalised in the future then a dispatch table can be used as // follows: ((void(*)(void))(systick_dispatch[uwTick & 0xf]))(); + + if (STORAGE_IDLE_TICK(uwTick)) { + NVIC->STIR = FLASH_IRQn; + } + if (DMA_IDLE_ENABLED() && DMA_IDLE_TICK(uwTick)) { dma_idle_handler(uwTick); } diff --git a/stmhal/storage.h b/stmhal/storage.h index 0d96d80661..a2c56b7654 100644 --- a/stmhal/storage.h +++ b/stmhal/storage.h @@ -26,6 +26,9 @@ #define FLASH_BLOCK_SIZE (512) +#define STORAGE_SYSTICK_MASK (0x1ff) // 512ms +#define STORAGE_IDLE_TICK(tick) (((tick) & STORAGE_SYSTICK_MASK) == 0) + void storage_init(void); uint32_t storage_get_block_size(void); uint32_t storage_get_block_count(void); diff --git a/stmhal/timer.c b/stmhal/timer.c index 39643385b5..cf93a01d7c 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -148,9 +148,6 @@ TIM_HandleTypeDef TIM3_Handle; TIM_HandleTypeDef TIM5_Handle; TIM_HandleTypeDef TIM6_Handle; -// Used to divide down TIM3 and periodically call the flash storage IRQ -STATIC uint32_t tim3_counter = 0; - #define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all)) STATIC uint32_t timer_get_source_freq(uint32_t tim_id); @@ -159,7 +156,6 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback); void timer_init0(void) { - tim3_counter = 0; for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) { MP_STATE_PORT(pyb_timer_obj_all)[i] = NULL; } @@ -256,13 +252,6 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) { void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim == &TIM3_Handle) { USBD_CDC_HAL_TIM_PeriodElapsedCallback(); - - // Periodically raise a flash IRQ for the flash storage controller - if (tim3_counter++ >= 500 / USBD_CDC_POLLING_INTERVAL) { - tim3_counter = 0; - NVIC->STIR = FLASH_IRQn; - } - } else if (htim == &TIM5_Handle) { servo_timer_irq_callback(); } |