system_stm32wbxx.c 3.0 KB

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