Thanks to visit codestin.com
Credit goes to github.com

Skip to content

micros() code bug #4

@maxgerhardt

Description

@maxgerhardt

You write

uint32_t micros(void)
{
/* Ensure COUNTFLAG is reset by reading SysTick control and status register */
LL_SYSTICK_IsActiveCounterFlag();
uint32_t m = tls_os_get_time();
uint32_t u = SysTick->LOAD - SysTick->VAL;
if(LL_SYSTICK_IsActiveCounterFlag) {
m = tls_os_get_time();
u = SysTick->LOAD - SysTick->VAL;
}
return (uint32_t)( m * 2000 + (u * 2000) / SysTick->LOAD);
}

and you write

static inline uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
{
return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
}

By which you can see that in line 45, you are not calling the function and checking its return value, you are doing if(function name), and since function name is also the address of the function, the if statement will always have a true statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions