AnsweredAssumed Answered

STM32F2 Change Clock while running: Problems with USB

Question asked by Chris_31543 on Sep 21, 2015
Latest reply on Sep 22, 2015 by Chris_31543
Hello,

I have a STM32F215 running as USB Device. With a specific command I implemented a function to change the core clock speed to 30/60/120 MHz. This is already working, but the USB Port has a strange behavior. After changing the clock speed the Controller doesn't send any data back to the PC, but the data which is sent to the controller is still correct.

The clock changing is done like this:

01.RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
02.RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
03.RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
04.RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
05.RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
06.ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
07.if(ret == 0)
08.{
09.    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
10.    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
11.    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
12.    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
13.    RCC_OscInitStruct.PLL.PLLM = 8;
14.    RCC_OscInitStruct.PLL.PLLN = 240;
15.    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
16.    RCC_OscInitStruct.PLL.PLLQ = 5;
17.    ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
18.    if(ret == HAL_OK)
19.    {
20.        RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
21.        RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
22.        RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
23.        RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
24.        RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
25.        ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
26.        if(ret == HAL_OK)
27.        {
28.            HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/8000);
29.            ret = HAL_OK;
30.            SysFreq = 60;
31.        }
32.    }
33.}

The USB is clocked with the PLL and for changing I have to switch off the PLL and switch on after reconfig it. I guess this is the reason why the USB connection has this strange behavior afterwards.

Does any one know how to solve this problem?

Regards,
Chris

Outcomes