Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

xPortSysTickHandler only gets called once/No task switching going on

Posted by dibosco on November 18, 2016

I am in the process of transferring a rather old STM32F107 project that ran at 62.5MHz to a new stripped-right-down project that runs at 72MHz so I can also create the correct 48MHz clock to have USB working.

I took the old 62.5M [Rowley] project, stripped everything non-FreeRTOS out, replaced the clock generation code with code from a run-to-complete program that had the CDC/VCP USB code working and have also put the USB code into this stripped-down project.

The USB interrupts work just fine and I can see I am receiving VCP messages.

However, when I went to process the received data in a new thread I found I was not receiving it. A load of Googling as to why no contect switching was happening lead me to look at the sys tick as that not going off would stop context switching.

I have found that the xPortSysTickHandler is getting called just once which is, presumably, why there is no context switching going on.

Here is all the clock initialsation in this new project:

~~~ void InitSystem(void) {

RCC_DeInit();  
RCC_HSEConfig(RCC_HSE_ON);
while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET );
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

/* 2 wait states required on the flash. */ *( ( unsigned long * ) 0x40022000 ) = 0x02; RCCPREDIV1Config(RCCPREDIV1SourcePLL2, RCCPREDIV1Div5); RCCPREDIV2Config(RCCPREDIV2_Div5);

RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
RCC_PLL2Config(RCC_PLL2Mul_8);

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Sysclock source is PLL


RCC_PCLK1Config(RCC_HCLK_Div2); // APB1 Clock = HCLK/2
RCC_PCLK2Config(RCC_HCLK_Div1); // APB2 = HCLK

RCC_PLL2Cmd(ENABLE);

while(RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET);

RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready. */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ RCCAPB2PeriphClockCmd( RCCAPB2PeriphGPIOA | RCCAPB2PeriphGPIOB | RCCAPB2PeriphGPIOC | RCCAPB2PeriphGPIOD | RCCAPB2PeriphGPIOE | RCCAPB2Periph_AFIO, ENABLE );

/* Configure HCLK clock as SysTick clock source. */
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
ifdef USE_USB
Set_USBClock();
USB_Interrupts_Config();
USB_Init();

DisableSOFInterrupt();
endif

} ~~~

Compared to what works in the old project (at 62.5MHz)

~~~ void prvSetupHardware( void ) {

uint8_t BootloaderValue;
    uint8_t i;
uint32_t reg;

/* Start with the clocks in their expected state. */
RCC_DeInit();

/* Enable HSE (high speed external clock). */
RCC_HSEConfig( RCC_HSE_ON );

/* Wait till HSE is ready. */
while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET )
{
}

/* 2 wait states required on the flash. */
*( ( unsigned long * ) 0x40022000 ) = 0x02;

/* HCLK = SYSCLK */
RCC_HCLKConfig( RCC_SYSCLK_Div1 );

/* PCLK2 = HCLK */
RCC_PCLK2Config( RCC_HCLK_Div1 );

/* PCLK1 = HCLK/2 */
RCC_PCLK1Config( RCC_HCLK_Div2 );

/* PLLCLK = (25MHz / 2 ) * 5 = 62.5 MHz. */
RCC_PLLConfig( RCC_PLLSource_HSE_Div2, RCC_PLLMul_5 );

/* Enable PLL. */
RCC_PLLCmd( ENABLE );

/* Wait till PLL is ready. */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}

/* Select PLL as system clock source. */
RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );

/* Wait till PLL is used as system clock source. */
while( RCC_GetSYSCLKSource() != 0x08 )
{
}

/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
						| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );

/* Set the Vector Table base address at 0x08000000 */
//NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );

// NVIC_SetVectorTable( 0x08008000, 0x0 );

NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

/* Configure HCLK clock as SysTick clock source. */
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );

} ~~~

Is anyone able to advise what I might have forgotten/am doing wrong please?

Many thanks,

Rob


xPortSysTickHandler only gets called once/No task switching going on

Posted by dibosco on November 18, 2016

A little bit more information on this, and problably pointing to what is going on - if not why, is that when that first xPortSysTickHandler is called I can see the TICKINT bit in the SYST_CSR register is cleared.

I have singled stepped the code both in a working version of a FreeRTOS STM32F107 and this non-functioning one and I can see that the TICKINT bit is set right up until the moment the system jumps to xPortSysTickHandler, from inside - I think - vPortSVCHandler.

I assume this TICKINT being cleared is why the xPortSysTickHandler ISR never gets called again. The question, I assume, is what could be making the TICKINT get cleared?


xPortSysTickHandler only gets called once/No task switching going on

Posted by dibosco on November 18, 2016

OK, partially talking to myself, but maybe this helps someone in future.

The USB libraries call something called uDELAY & mDELAY which are in turn #defined as USBOTGBSPuDelay(usec) & USBOTGBSPuDelay(1000 * msec). The USBOTGBSP_uDelay messes around with the previously set sys tick timers. :~/

So, I guess I need to either use a different timer for FreeRTOS's tick timer or a different timer/method for USBOTGBSP_uDelay.

Does anyone have any advice on the best way to proceed?


xPortSysTickHandler only gets called once/No task switching going on

Posted by dibosco on November 18, 2016

OK, one more and I'm stopping. I used TIM6 instead of the sys tick timer and it seems to be all working nicely now.


xPortSysTickHandler only gets called once/No task switching going on

Posted by rtel on November 18, 2016

Good news. This is the best kind of support request - one that not only fixes itself, but has the courtesy to report back so everybody else can see too :o)


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists