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;
RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
RCC_PREDIV2Config(RCC_PREDIV2_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 */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE | RCC_APB2Periph_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