# Regular timer vs systick handler

**URL:** <https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934>\
**Category:** Kernel\
**Tags:** tutorial\
**Created:** [March 13, 2023, 9:52am UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934 "2023-03-13T09:52:02Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 13, 2023, 9:52am UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/1 "2023-03-13T09:52:02Z")

</div>

hello all!  
is it possible to use regular timer instead of systick handler? in my sc000 controller systick function is truncated.  
how will macros look like in this case? (in freertos\_config.h)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 13, 2023, 10:14am UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/2 "2023-03-13T10:14:02Z")

</div>

Which FreeRTOS port are you using? If you are using Cortex-M4, you need to implement [vPortSetupTimerInterrupt](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM4F/port.c#L749) which will override the default implementation as it is weak. And install [this function](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM4F/port.c#L504) as your interrupt handler?

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 13, 2023, 11:40am UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/3 "2023-03-13T11:40:07Z")

</div>

I have follow quick start. copy tasks queue list and port (cortex m0) and heap 1  
my sc000 - cortex m0, it is a simulator for sim card

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 13, 2023, 12:05pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/4 "2023-03-13T12:05:23Z")

</div>

What problem are you facing? Can you describe in detail all the symptoms - is it a build error, linker error or run time error?

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 21, 2023, 11:32am UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/5 "2023-03-21T11:32:58Z")

</div>

I have followed the recommendation for create new project. There are not demo project for my controller. It is a SC000 (ARM CortexM0).  
So I have follow the new project from FreeRTOS(list, queue task port and heap)  
The first trouble is - on my controller SysTick\_Handler is truncated.  
So, I do try to use regular timer and IRQHandler as a source for SysTick  
I have define it in FreeRTOSConfig.h as a  
#define xPortSysTickHandler Timer0\_IRQHandler  
But receive an error Symbol multiple defined (port.o and main.o)  
If define as SysTickHandler as default it is compiled but tasks not switched  
I do check it with digital analyzer on GPIO ports, port with timer shows the impulses but tasks keep silence  
I means that tasks not started  
Where I do mistakes?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 21, 2023, 12:58pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/6 "2023-03-21T12:58:54Z")

</div>

> [@achechet](#):
>
> But receive an error Symbol multiple defined (port.o and main.o)

Please share the complete output.

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 21, 2023, 1:56pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/7 "2023-03-21T13:56:14Z")

</div>

Rebuild target ‘Target 1’  
compiling main.c…  
assembling M25\_Startup.s…  
compiling list.c…  
compiling queue.c…  
compiling tasks.c…  
compiling heap\_1.c…  
compiling port.c…  
compiling function.c…  
linking…  
.\lesson015.axf: Error: L6200E: Symbol Timer0\_IRQHandler multiply defined (by .\port.o and .\main.o).  
Not enough information to list image symbols.  
Not enough information to list the image map.  
Finished: 2 information, 0 warning and 1 error messages.  
“.\lesson015.axf” - 1 Error(s), 0 Warning(s).  
Target not created

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 21, 2023, 2:00pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/8 "2023-03-21T14:00:08Z")

</div>

this is tail of FreeRTOSConfig

```auto
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define xPortPendSVHandler PendSV_Handler
// #define xPortSysTickHandler SysTick_Handler
#define xPortSysTickHandler Timer0_IRQHandler

/* Bump up the priority of recmuCONTROLLING_TASK_PRIORITY to prevent false
positive errors being reported considering the priority of other tasks in the
system. */
#define recmuCONTROLLING_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )

#define traceTASK_SWITCHED_IN() TaskSwitchedIn((int)pxCurrentTCB->pxTaskTag);
#define traceTASK_SWITCHED_OUT() TaskSwitchedOut((int)pxCurrentTCB->pxTaskTag);

#endif /* FREERTOS_CONFIG_H */

```

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 21, 2023, 2:06pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/9 "2023-03-21T14:06:01Z")

</div>

this is tail of main

```auto
BaseType_t xReturned_ONE;
BaseType_t xReturned_TWO;

// #define TASK_DEBUG

void vTaskCode_ONE(void * pvParametrs ) 
	{
		#ifdef TASK_DEBUG
			vTaskSetApplicationTaskTag( NULL, ( TaskHookFunction_t ) 1 );
		__nop();
		#endif
		for( ;; ) 
			{

				__nop();
			GPIODATA = (1 << 1);
				vTaskDelay(10);
			GPIODATA = (0 << 1);
				vTaskDelay(1);
			}
	}	
	
	void vTaskCode_TWO(void * pvParametrs ) 
	{
		#ifdef TASK_DEBUG
			vTaskSetApplicationTaskTag( NULL, ( TaskHookFunction_t ) 2 );
		__nop();
		#endif
		for( ;; ) 
			{

				__nop();
			GPIODATA = (1 << 2);
				vTaskDelay(10);
			GPIODATA = (0 << 2);
				vTaskDelay(1);
			}
	}	

void Timer0_IRQHandler(void)
{
			TIMER0IS = 0;		
			__nop();
			GPIODATA = (1 << 3);
			__nop();
			GPIODATA = (0 << 3);
}

int main(void) 
	{
	Timer0_Init();
		
	xReturned_ONE = xTaskCreate(vTaskCode_ONE, "ONE", 50*4, NULL, tskIDLE_PRIORITY, NULL );
	xReturned_TWO = xTaskCreate(vTaskCode_TWO, "TWO", 50*4, NULL, tskIDLE_PRIORITY, NULL );

  vTaskStartScheduler();

  for( ;; );
	
	}

```

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 21, 2023, 2:29pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/10 "2023-03-21T14:29:07Z")

</div>

Assuming that the line `TIMER0IS = 0;` clears the interrupt, you need to update the definition of `Timer0_IRQHandler` in the main.c to the following -

```c
void Timer0_IRQHandler( void )
{
    uint32_t ulPreviousMask;

    TIMER0IS = 0;

    ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR();
    {
        /* Increment the RTOS tick. */
        if( xTaskIncrementTick() != pdFALSE )
        {
            /* Pend a context switch. */
            portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
        }
    }
    portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask );
}

```

And remove the following line from the FreeRTOSConfig.h:

```auto
#define xPortSysTickHandler Timer0_IRQHandler

```

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 21, 2023, 3:09pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/11 "2023-03-21T15:09:33Z")

</div>

Thank you a lot! I will try

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 22, 2023, 3:10pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/12 "2023-03-22T15:10:25Z")

</div>

It is working! Cool!  
Thank you a lot! Again and again

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 28, 2023, 12:29pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/13 "2023-03-28T12:29:29Z")

</div>

Dear Aggard  
I do continue my questions.  
FreeRTOS in my case switch tasks but its behavior not the same as I expected.  
Task as  
`
void vTaskCode_ONE(void * pvParametrs )
{
#ifdef TASK_DEBUG
vTaskSetApplicationTaskTag( NULL, ( TaskHookFunction_t ) 1 );
#endif`

`
```
	 for( ; ; ) 
		{
			osDelay(1);
		 } 		

}	</code>

```
not ended until switch context`

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 28, 2023, 12:31pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/14 "2023-03-28T12:31:42Z")

</div>

![task](https://d2v6vdsk2p900z.cloudfront.net/original/2X/e/ebd07b3c025e509e3e65e863472dfc460a9d1793.png)

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 28, 2023, 12:32pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/15 "2023-03-28T12:32:32Z")

</div>

0 and 1 tasks next IDLE and TICK from TIMER

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [March 28, 2023, 12:46pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/16 "2023-03-28T12:46:24Z")

</div>

I have found the solution. I have to change osDelay → vTaskDelay and then it began works right

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 28, 2023, 1:19pm UTC](https://forums.freertos.org/t/regular-timer-vs-systick-handler/16934/17 "2023-03-28T13:19:52Z")

</div>

Glad that you figured!
