STM32: initialize the clock for all the peripherals at boot.
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 12 May 2010 12:15:31 +0000 (12:15 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 12 May 2010 12:15:31 +0000 (12:15 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3660 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/cortex-m3/drv/clock_stm32.c
bertos/cpu/cortex-m3/drv/clock_stm32.h

index cd8e0f4286d708a0c377b6a5696b23e62fe589a7..4b8cd89897de9982210badca6b9ccf3d5eefacc3 100644 (file)
@@ -126,8 +126,23 @@ void clock_init(void)
        rcc_pll_config();
        while(!rcc_get_flag_status(RCC_FLAG_PLLRDY));
 
+       /* Configure USB clock (48MHz) */
+       *CFGR_USBPRE_BB = RCC_USBCLK_PLLCLK_1DIV5;
+       /* Configure ADC clock: PCLK2 (9MHz) */
+       RCC->CFGR &= CFGR_ADCPRE_RESET_MASK;
+       RCC->CFGR |= RCC_PCLK2_DIV8;
+       /* Configure system clock dividers: PCLK2 (72MHz) */
+       RCC->CFGR &= CFGR_PPRE2_RESET_MASK;
+       RCC->CFGR |= RCC_HCLK_DIV1 << 3;
+       /* Configure system clock dividers: PCLK1 (36MHz) */
+       RCC->CFGR &= CFGR_PPRE1_RESET_MASK;
+       RCC->CFGR |= RCC_HCLK_DIV2 << 3;
+       /* Configure system clock dividers: HCLK */
+       RCC->CFGR &= CFGR_HPRE_RESET_MASK;
+       RCC->CFGR |= RCC_SYSCLK_DIV1;
+
        /* Set 1 wait state for the flash memory */
-       *(reg32_t *)0x40022000 = 0x12;
+       *(reg32_t *)FLASH_BASE = 0x12;
 
        /* Clock the system from the PLL */
        rcc_set_clock_source(RCC_SYSCLK_PLLCLK);
index c675a5f8dbc72863ae2939677b333da43e21702e..4150a44d1e11c8f6278279e5ce43491b7bd381c8 100644 (file)
 #define RCC_PLLMUL_14              (0x00300000)
 #define RCC_PLLMUL_15              (0x00340000)
 #define RCC_PLLMUL_16              (0x00380000)
+
+/* APB1/APB2 clock source */
+#define RCC_HCLK_DIV1              (0x00000000)
+#define RCC_HCLK_DIV2              (0x00000400)
+#define RCC_HCLK_DIV4              (0x00000500)
+#define RCC_HCLK_DIV8              (0x00000600)
+#define RCC_HCLK_DIV16             (0x00000700)
+
+/* USB clock source */
+#define RCC_USBCLK_PLLCLK_1DIV5    (0x00)
+#define RCC_USBCLK_PLLCLK_DIV1     (0x01)
+
+/* ADC clock source */
+#define RCC_PCLK2_DIV2             (0x00000000)
+#define RCC_PCLK2_DIV4             (0x00004000)
+#define RCC_PCLK2_DIV6             (0x00008000)
+#define RCC_PCLK2_DIV8             (0x0000C000)
+
+/* AHB clock source */
+#define RCC_SYSCLK_DIV1            (0x00000000)
+#define RCC_SYSCLK_DIV2            (0x00000080)
+#define RCC_SYSCLK_DIV4            (0x00000090)
+#define RCC_SYSCLK_DIV8            (0x000000A0)
+#define RCC_SYSCLK_DIV16           (0x000000B0)
+#define RCC_SYSCLK_DIV64           (0x000000C0)
+#define RCC_SYSCLK_DIV128          (0x000000D0)
+#define RCC_SYSCLK_DIV256          (0x000000E0)
+#define RCC_SYSCLK_DIV512          (0x000000F0)
 /*\}*/
 
 /**