Issue with xtimer_usleep

Hello,

i’m facing an issue regarding xtimer_usleep. This issue is not the same as before which was preventing my task from waking up. Here, my task stays awake but is stuck in a while loop that triggers my watchdog. Indeed, i found in this function : xtimer_spin_until(uint32_t target), that i can stay permanently blocked in the first “while” :

xtimer_core.c :

static inline void xtimer_spin_until(uint32_t target) { #if XTIMER_MASK target = _xtimer_lltimer_mask(target); #endif while (_xtimer_lltimer_now() > target); while (_xtimer_lltimer_now() < target); }

By using GDB, i found that target was equal to 6 (or very small), so the probability of the condition being false in order to get out of the loop is very small and i stay blocked because each time the CPU evaluates the timer counter, it has already overshoot the target value. I can easily reproduce this issue by calling xtimer_usleep with very small values but i suppose it is also likely it can occur with any kind of values.

Am i doing something wrong ? Is my analysis correct ? If yes, i don’t know how to solve this issue.

Here is my configuration :

periph_conf.h :

#define CLOCK_HSI (16000000U) /* internal oscillator / #define CLOCK_CORECLOCK (16000000U) / desired core clock frequency */

/* configuration of PLL prescaler and multiply values / / CORECLOCK := HSI / CLOCK_PLL_DIV * CLOCK_PLL_MUL / #define CLOCK_PLL_DIV RCC_CFGR_PLLDIV4 #define CLOCK_PLL_MUL RCC_CFGR_PLLMUL4 / configuration of peripheral bus clock prescalers / #define CLOCK_AHB_DIV RCC_CFGR_HPRE_DIV8 / AHB clock -> 2MHz / #define CLOCK_APB2_DIV RCC_CFGR_PPRE2_DIV1 / APB2 clock -> 2MHz / #define CLOCK_APB1_DIV RCC_CFGR_PPRE1_DIV1 / APB1 clock -> 2MHz / / configuration of flash access cycles */ #define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY

/* bus clocks for simplified peripheral initialization, UPDATE MANUALLY! */ #define CLOCK_AHB (CLOCK_CORECLOCK / 8) #define CLOCK_APB2 (CLOCK_CORECLOCK / 8) #define CLOCK_APB1 (CLOCK_CORECLOCK / 8)

board.h :

#define XTIMER_DEV TIMER_DEV(0) #define XTIMER_CHAN (0) #define XTIMER_WIDTH (16)

#define XTIMER_BACKOFF (100) #define XTIMER_ISR_BACKOFF (100) #define XTIMER_OVERHEAD (100)

Thank you in advance for your help :wink:

Regards,

Hi Aurélien,