|
- /*
- * More info here:
- * https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html
- *
- * And resistor fix:
- * https://amitesh-singh.github.io/stm32/2017/05/27/Overcoming-wrong-pullup-in-blue-pill.html
- *
- * Note: I didn't have to do this fix, and things seem to work fine.
- */
-
- #include <stm32f1xx_hal_flash.h>
- #include <stm32f1xx_hal_rcc.h>
-
- #include <sysinit.h>
-
- /*
- * Referenced from:
- * Projects/STM32F103RB-Nucleo/Applications/USB_Device/HID_Standalone/Src/main.c
- */
- static void
- oscconfig(const void *none)
- {
- RCC_ClkInitTypeDef clkinitstruct;
- RCC_OscInitTypeDef oscinitstruct;
- RCC_PeriphCLKInitTypeDef rccperiphclkinit;
-
- __HAL_RCC_PWR_CLK_ENABLE();
-
- oscinitstruct = (RCC_OscInitTypeDef){
- .OscillatorType = RCC_OSCILLATORTYPE_HSE,
- .HSEState = RCC_HSE_ON,
- .HSEPredivValue = RCC_HSE_PREDIV_DIV1,
- .PLL.PLLMUL = RCC_PLL_MUL9,
-
- .PLL.PLLState = RCC_PLL_ON,
- .PLL.PLLSource = RCC_PLLSOURCE_HSE,
- };
-
- HAL_RCC_OscConfig(&oscinitstruct);
-
- /* USB clock selection */
- rccperiphclkinit = (RCC_PeriphCLKInitTypeDef){
- .PeriphClockSelection = RCC_PERIPHCLK_USB,
- .UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5,
- };
- HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
-
- /*
- * Select PLL as system clock source and configure the HCLK,
- * PCLK1 and PCLK2 clocks dividers
- */
- clkinitstruct = (RCC_ClkInitTypeDef){
- .ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
- RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2),
- .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK,
- .AHBCLKDivider = RCC_SYSCLK_DIV1,
- .APB1CLKDivider = RCC_HCLK_DIV2,
- .APB2CLKDivider = RCC_HCLK_DIV1,
- };
- HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
- }
- SYSINIT(oscconfig, SI_SUB_HAL, SI_ORDER_THIRD, oscconfig, NULL);
|