Systick missing ticks when printf() is used

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Systick missing ticks when printf() is used

651 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by riscy00 on Sat Nov 28 22:25:06 MST 2015
I have systick running, generating interrupts every 1mSec and it working fine.

I was reading sensor on I2C and use systick counter as timestamp. I expected to be every 2000mSec for each interrupt generated by sensor data RDY signal.

I found that when I use printf() to send resultant data, the timestamp (systick) was reading 1800mSec instead of 2000mSec. I checked the timing of the RDY signal on scope and confirmed 2000mSec exactly.

When I disable all message on printf() except the timestamp which is much shorter message, the systick improved close to 2000mSec.

Something between printf() and systick cause to miss 1mSec interrupts. I use retarget.h to direct printf()'s putchar to UART2 (see below) 

void UART2_PutChar(char ch)
{
// try unblocking so systick keep going.
//Chip_UART_Send(DEBUG_UART, &ch, 1);
// below will cause systick to suspend until printf task is completed.
Chip_UART_SendBlocking(DEBUG_UART, &ch, 1);
}


I have changed the below to highest priority ie '0' and it does not fix this problem

#define __NVIC_PRIO_BITS          3
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); 


I have tried unblocking but does not work....I'm missing something there.

Is there way to reduce change priority on printf() or stop interfering the systick interrupt.

Maybe I should use RTC instead of Systick, but I'm curious why printf() stop systick working and what the work around before I get to RTC timer, will it fix issue even using printf()?



Labels (1)
0 Kudos
2 Replies

582 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by riscy00 on Mon Nov 30 08:27:39 MST 2015
Thank for quick reply.

I switched to RIT and use it keep track of timing without interrupts which resolve this problem. i just grab counter and divided by 12000 for 12MHz clock which provide mSec readout.

BTW, The UART BAUD is 57600.

Best wishes

R.

0 Kudos

582 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pnhnkvr on Sun Nov 29 09:09:25 MST 2015
Hey,

First of all you do not set the SysTick priority to highest with (1<<__NVIC_PRIO_BITS) - 1, actually you get the lowest priority with that.

Secondly I hope you do not use printf() from ISR (at least if it takes long, i.e. if baud rate is slow or string is long). In any case it will take some time to execute the printf -function because the UART transmission does not use interrupts, i.e. the cpu must wait until the whole string is send.

Without the your code it's difficult to say where you lose the time.
0 Kudos