lpcware

Systick missing ticks when printf() is used

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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()?



Outcomes