system_init.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stm32f0xx.h>
  2. static void __init_default_clocks(void)
  3. {
  4. /* Reset the RCC clock configuration to the default reset state ------------*/
  5. /* Set HSION bit */
  6. RCC->CR |= (uint32_t)0x00000001;
  7. #if defined (STM32F051x8) || defined (STM32F058x8)
  8. /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */
  9. RCC->CFGR &= (uint32_t)0xF8FFB80C;
  10. #else
  11. /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE, MCOSEL[2:0], MCOPRE[2:0] and PLLNODIV bits */
  12. RCC->CFGR &= (uint32_t)0x08FFB80C;
  13. #endif /* STM32F051x8 or STM32F058x8 */
  14. /* Reset HSEON, CSSON and PLLON bits */
  15. RCC->CR &= (uint32_t)0xFEF6FFFF;
  16. /* Reset HSEBYP bit */
  17. RCC->CR &= (uint32_t)0xFFFBFFFF;
  18. /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
  19. RCC->CFGR &= (uint32_t)0xFFC0FFFF;
  20. /* Reset PREDIV[3:0] bits */
  21. RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
  22. #if defined (STM32F072xB) || defined (STM32F078xx)
  23. /* Reset USART2SW[1:0], USART1SW[1:0], I2C1SW, CECSW, USBSW and ADCSW bits */
  24. RCC->CFGR3 &= (uint32_t)0xFFFCFE2C;
  25. #elif defined (STM32F071xB)
  26. /* Reset USART2SW[1:0], USART1SW[1:0], I2C1SW, CECSW and ADCSW bits */
  27. RCC->CFGR3 &= (uint32_t)0xFFFFCEAC;
  28. #elif defined (STM32F091xC) || defined (STM32F098xx)
  29. /* Reset USART3SW[1:0], USART2SW[1:0], USART1SW[1:0], I2C1SW, CECSW and ADCSW bits */
  30. RCC->CFGR3 &= (uint32_t)0xFFF0FEAC;
  31. #elif defined (STM32F030x6) || defined (STM32F030x8) || defined (STM32F031x6) || defined (STM32F038xx) || defined (STM32F030xC)
  32. /* Reset USART1SW[1:0], I2C1SW and ADCSW bits */
  33. RCC->CFGR3 &= (uint32_t)0xFFFFFEEC;
  34. #elif defined (STM32F051x8) || defined (STM32F058xx)
  35. /* Reset USART1SW[1:0], I2C1SW, CECSW and ADCSW bits */
  36. RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
  37. #elif defined (STM32F042x6) || defined (STM32F048xx)
  38. /* Reset USART1SW[1:0], I2C1SW, CECSW, USBSW and ADCSW bits */
  39. RCC->CFGR3 &= (uint32_t)0xFFFFFE2C;
  40. #elif defined (STM32F070x6) || defined (STM32F070xB)
  41. /* Reset USART1SW[1:0], I2C1SW, USBSW and ADCSW bits */
  42. RCC->CFGR3 &= (uint32_t)0xFFFFFE6C;
  43. /* Set default USB clock to PLLCLK, since there is no HSI48 */
  44. RCC->CFGR3 |= (uint32_t)0x00000080;
  45. #else
  46. #warning "No target selected"
  47. #endif
  48. /* Reset HSI14 bit */
  49. RCC->CR2 &= (uint32_t)0xFFFFFFFE;
  50. /* Disable all interrupts */
  51. RCC->CIR = 0x00000000;
  52. }
  53. void __system_init(void)
  54. {
  55. __init_default_clocks();
  56. }