system_stm32wbxx.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "stm32wbxx.h"
  2. /*!< Uncomment the following line if you need to relocate your vector Table in
  3. Internal SRAM. */
  4. /* #define VECT_TAB_SRAM */
  5. #define VECT_TAB_OFFSET \
  6. OS_OFFSET /*!< Vector Table base offset field.
  7. This value must be a multiple of 0x200. */
  8. #define VECT_TAB_BASE_ADDRESS \
  9. SRAM1_BASE /*!< Vector Table base offset field.
  10. This value must be a multiple of 0x200. */
  11. /* The SystemCoreClock variable is updated in three ways:
  12. 1) by calling CMSIS function SystemCoreClockUpdate()
  13. 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
  14. 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
  15. Note: If you use this function to configure the system clock; then there
  16. is no need to call the 2 first functions listed above, since SystemCoreClock
  17. variable is updated automatically.
  18. */
  19. uint32_t SystemCoreClock = 4000000UL; /*CPU1: M4 on MSI clock after startup (4MHz)*/
  20. const uint32_t AHBPrescTable[16UL] =
  21. {1UL, 3UL, 5UL, 1UL, 1UL, 6UL, 10UL, 32UL, 2UL, 4UL, 8UL, 16UL, 64UL, 128UL, 256UL, 512UL};
  22. const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
  23. const uint32_t MSIRangeTable[16UL] = {
  24. 100000UL,
  25. 200000UL,
  26. 400000UL,
  27. 800000UL,
  28. 1000000UL,
  29. 2000000UL,
  30. 4000000UL,
  31. 8000000UL,
  32. 16000000UL,
  33. 24000000UL,
  34. 32000000UL,
  35. 48000000UL,
  36. 0UL,
  37. 0UL,
  38. 0UL,
  39. 0UL}; /* 0UL values are incorrect cases */
  40. /**
  41. * @brief Setup the microcontroller system.
  42. * @param None
  43. * @retval None
  44. */
  45. void SystemInit(void) {
  46. /* Configure the Vector Table location add offset address ------------------*/
  47. #if defined(VECT_TAB_SRAM) && defined(VECT_TAB_BASE_ADDRESS)
  48. /* program in SRAMx */
  49. SCB->VTOR = VECT_TAB_BASE_ADDRESS |
  50. VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAMx for CPU1 */
  51. #else /* program in FLASH */
  52. SCB->VTOR = VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
  53. #endif
  54. /* FPU settings ------------------------------------------------------------*/
  55. #if(__FPU_PRESENT == 1) && (__FPU_USED == 1)
  56. SCB->CPACR |=
  57. ((3UL << (10UL * 2UL)) | (3UL << (11UL * 2UL))); /* set CP10 and CP11 Full Access */
  58. #endif
  59. /* Reset the RCC clock configuration to the default reset state ------------*/
  60. /* Set MSION bit */
  61. RCC->CR |= RCC_CR_MSION;
  62. /* Reset CFGR register */
  63. RCC->CFGR = 0x00070000U;
  64. /* Reset PLLSAI1ON, PLLON, HSECSSON, HSEON, HSION, and MSIPLLON bits */
  65. RCC->CR &= (uint32_t)0xFAF6FEFBU;
  66. /*!< Reset LSI1 and LSI2 bits */
  67. RCC->CSR &= (uint32_t)0xFFFFFFFAU;
  68. /*!< Reset HSI48ON bit */
  69. RCC->CRRCR &= (uint32_t)0xFFFFFFFEU;
  70. /* Reset PLLCFGR register */
  71. RCC->PLLCFGR = 0x22041000U;
  72. #if defined(STM32WB55xx) || defined(STM32WB5Mxx)
  73. /* Reset PLLSAI1CFGR register */
  74. RCC->PLLSAI1CFGR = 0x22041000U;
  75. #endif
  76. /* Reset HSEBYP bit */
  77. RCC->CR &= 0xFFFBFFFFU;
  78. /* Disable all interrupts */
  79. RCC->CIER = 0x00000000;
  80. }