Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micros() code bug #4

Open
maxgerhardt opened this issue Sep 24, 2020 · 0 comments
Open

micros() code bug #4

maxgerhardt opened this issue Sep 24, 2020 · 0 comments

Comments

@maxgerhardt
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant