File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,21 +58,24 @@ void tick_init() {
5858
5959void tick_delay (uint32_t us ) {
6060 uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency () / 1000 / 1000 ;
61- uint32_t us_between_ticks = SysTick -> VAL / ticks_per_us ;
61+ uint32_t us_until_next_tick = SysTick -> VAL / ticks_per_us ;
6262 uint32_t start_tick ;
6363 while (us > 1000 ) {
64+ // check if interrupts are disabled
65+ if (__get_PRIMASK ())
66+ return ; // if not just return
6467 start_tick = SysTick -> VAL ; // wait for SysTick->VAL to RESET
6568 while (SysTick -> VAL < start_tick ) {}
66- us -= us_between_ticks ;
67- us_between_ticks = 1000 ;
69+ us -= us_until_next_tick ;
70+ us_until_next_tick = 1000 ;
6871 }
69- if (us && (us < us_between_ticks )){
70- while (SysTick -> VAL > ((us_between_ticks - us ) * ticks_per_us )) {}
72+ if (us && (us < us_until_next_tick )){
73+ while (SysTick -> VAL > ((us_until_next_tick - us ) * ticks_per_us )) {}
7174 }
7275 else {
7376 start_tick = SysTick -> VAL ; // wait for SysTick->VAL to RESET
7477 while (SysTick -> VAL < start_tick ) {}
75- us -= us_between_ticks ;
78+ us -= us_until_next_tick ;
7679 if (us ){
7780 while (SysTick -> VAL > ((1000 - us ) * ticks_per_us )) {}
7881 }
You can’t perform that action at this time.
0 commit comments