0
\$\begingroup\$

I want to set my STM32F446 controller his clockfrequency to 60MHz. I thought I could do it, but without results.

I am using an STM32F446 -nucleo board. I used STM32CubeMX to generate my code. After that didn't work, I searched on the web and found the same code (exept for the values).

If I program my controller with this code. The values of the clockfrequency isn't right, or my controller does nothing.

Can you guys help me?

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;

__PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 60;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
                            |RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLRCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
\$\endgroup\$
11
  • \$\begingroup\$ What didn't work? How did you check? \$\endgroup\$
    – user72833
    Commented Feb 11, 2016 at 12:24
  • \$\begingroup\$ @Tibo I tested it with very many toggles of a GPIO in a while loop. I know the while-loop creates some delay. But is still need to get an output frequency of 30MHz. If I change the values of the PPLs a bit, it doesn't work. GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct1.Pin = GPIO_PIN_1; GPIO_InitStruct1.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct1.Pull = GPIO_PULLDOWN; GPIO_InitStruct1.Speed = GPIO_SPEED_HIGH HAL_GPIO_Init(GPIOA, &GPIO_InitStruct) while() { GPIOA -> ODR = 0x0002 GPIOA -> ODR = 0x0000 .... } \$\endgroup\$
    – StijnB
    Commented Feb 11, 2016 at 12:29
  • \$\begingroup\$ A pure-software loop doesn't sound like a good idea to achieve 30MHz. You should first check that your GPIO are actually clocked at the highest possible rate (peripheral clock != core clock), check that you set the GPIO speed as high as possible (as they call it in CubeMX), and consider using a hardware timer instead of a loop. \$\endgroup\$
    – user72833
    Commented Feb 11, 2016 at 12:35
  • 3
    \$\begingroup\$ You're still trying to bit-bang a USB PHY over ULPI?! You really need to just hook your PHY up to the STM's ULPI pins and use the internal module to communicate with it. Anything else is just a waste of time. \$\endgroup\$
    – brhans
    Commented Feb 11, 2016 at 12:56
  • 1
    \$\begingroup\$ @brhans: thanks for pointing this out. I now understand that OP has a XY[Z...] problem. I'll just stop trying to be helpful on this thread. \$\endgroup\$
    – user72833
    Commented Feb 11, 2016 at 14:09

2 Answers 2

1
\$\begingroup\$

you should try the RCC example in the firmware package for your stm32f4 mcu. And implement error checking:

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
  /* Initialization Error */
  Error_Handler();
}


\\and:

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
  /* Initialization Error */
  Error_Handler();
}

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
  /* Initialization Error */
  Error_Handler();
}

after implementing this you can run in debug mode and insert break points at Error_Handler();

\$\endgroup\$
1
  • \$\begingroup\$ He goes into the error handler two times, at the first if and the thirth. \$\endgroup\$
    – StijnB
    Commented Feb 24, 2016 at 9:58
0
\$\begingroup\$

You do use internal HSI oscilator, check MXCube and select external HSE oscilator if this is a problem you are asking for.

\$\endgroup\$
1
  • \$\begingroup\$ No i want to use the HSI oscilator. \$\endgroup\$
    – StijnB
    Commented Feb 24, 2016 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.