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

DelaySysTick jitter #237

Open
romain145 opened this issue Sep 12, 2023 · 1 comment
Open

DelaySysTick jitter #237

romain145 opened this issue Sep 12, 2023 · 1 comment

Comments

@romain145
Copy link
Contributor

DelaySysTick has jitter for specific values of 1, 2, 6, 8, 10 (tested up to 10).
DelaySysTick(0) is always 292ns.
DelaySysTick(1) is 292ns or 459ns.
DelaySysTick(2) is 459ns or 626ns.
DelaySysTick(3) is always 793ns.

I'm suspecting compiler optimization at play here. I tried forcing it to be inlined with little success.

Adding volatile changed the behaviour (2 doesn't have jitter anymore) but it still shows jitter for other values. It's also much slower, obviously...

void DelaySysTick( uint32_t n )
{
	volatile uint32_t targend = SysTick->CNT + n;
	while( ((int32_t)( SysTick->CNT - targend )) < 0 );
}
@cnlohr
Copy link
Owner

cnlohr commented Sep 24, 2023

I believe this has to do with instruction alignment. Can you see what happens if you surround your code with option norvc?

https://github.com/cnlohr/ch32v003fun/blob/master/ch32v003fun/ch32v003fun.c#L738C20-L741C21

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

2 participants