diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-04-10 14:05:10 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-04-10 14:05:10 +0000 |
commit | 2f99ed97a977f64fd7a11cb6cce569c879be4420 (patch) | |
tree | 3f4576e1c7f792e85c9f12959a6be0706174bc75 /demos/ARMCM3-STM32F103-GCC | |
parent | b01aa7935cff4a5afe0505836b2b774a50f3c141 (diff) | |
download | ChibiOS-2f99ed97a977f64fd7a11cb6cce569c879be4420.tar.gz ChibiOS-2f99ed97a977f64fd7a11cb6cce569c879be4420.tar.bz2 ChibiOS-2f99ed97a977f64fd7a11cb6cce569c879be4420.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@258 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARMCM3-STM32F103-GCC')
-rw-r--r-- | demos/ARMCM3-STM32F103-GCC/Makefile | 2 | ||||
-rw-r--r-- | demos/ARMCM3-STM32F103-GCC/board.c | 35 | ||||
-rw-r--r-- | demos/ARMCM3-STM32F103-GCC/board.h | 65 | ||||
-rw-r--r-- | demos/ARMCM3-STM32F103-GCC/stm32lib/stm32f10x_conf.h | 4 |
4 files changed, 81 insertions, 25 deletions
diff --git a/demos/ARMCM3-STM32F103-GCC/Makefile b/demos/ARMCM3-STM32F103-GCC/Makefile index 5b0e8f23e..7fc33886a 100644 --- a/demos/ARMCM3-STM32F103-GCC/Makefile +++ b/demos/ARMCM3-STM32F103-GCC/Makefile @@ -62,7 +62,7 @@ UDEFS = UADEFS =
# List ARM-mode C source files here
-SRC = ../../ports/ARMCM3/chcore.c \
+SRC = ../../ports/ARMCM3/chcore.c ../../ports/ARMCM3/nvic.c \
../../src/chinit.c ../../src/chdebug.c ../../src/chlists.c ../../src/chdelta.c \
../../src/chschd.c ../../src/chthreads.c ../../src/chsem.c ../../src/chmtx.c \
../../src/chevents.c ../../src/chmsg.c ../../src/chsleep.c ../../src/chqueues.c \
diff --git a/demos/ARMCM3-STM32F103-GCC/board.c b/demos/ARMCM3-STM32F103-GCC/board.c index 09636cb9d..631a13e0c 100644 --- a/demos/ARMCM3-STM32F103-GCC/board.c +++ b/demos/ARMCM3-STM32F103-GCC/board.c @@ -18,6 +18,7 @@ */
#include <ch.h>
+#include <nvic.h>
#include "board.h"
@@ -45,27 +46,29 @@ void hwinit(void) { * Clocks and PLL initialization.
*/
// HSI setup.
- RCC->CR = 0x00000083; // Enforces a known state (HSI ON).
- while (!(RCC->CR & (1 << 1)))
+ RCC->CR = HSITRIM_RESET_BITS | CR_HSION_MASK;
+ while (!(RCC->CR & CR_HSIRDY_MASK))
; // Waits until HSI stable, it should already be.
// HSE setup.
- RCC->CR |= (1 << 16); // HSE ON.
- while (!(RCC->CR & (1 << 17)))
+ RCC->CR |= CR_HSEON_MASK;
+ while (!(RCC->CR & CR_HSERDY_MASK))
; // Waits until HSE stable.
// PLL setup.
- RCC->CFGR |= PLLPREBITS | PLLMULBITS | PLLSRCBITS;
- RCC->CR |= (1 << 24); // PLL ON.
- while (!(RCC->CR & (1 << 25)))
+ RCC->CFGR = PLLSRC_HSE_BITS | PLLPREBITS | PLLMULBITS;
+ RCC->CR |= CR_PLLON_MASK;
+ while (!(RCC->CR & CR_PLLRDY_MASK))
; // Waits until PLL stable.
// Clock sources.
- RCC->CFGR |= AHBBITS | PPRE1BITS | PPRE2BITS | ADCPREBITS |
- USBPREBITS | MCOSRCBITS;
+ RCC->CFGR |= HPRE_DIV1_BITS | PPRE1_DIV2_BITS | PPRE2_DIV2_BITS |
+ ADCPRE_DIV8_BITS | USBPREBITS | MCO_DISABLED_BITS;
/*
* Flash setup and final clock selection.
*/
FLASH->ACR = FLASHBITS; // Flash wait states depending on clock.
- RCC->CFGR |= SYSSRCBITS; // Switches on the PLL clock.
+ RCC->CFGR |= SW_PLL_BITS; // Switches on the PLL clock.
+ while ((RCC->CFGR & CFGR_SWS_MASK) != SWS_PLL_BITS)
+ ;
/*
* I/O ports initialization as specified in board.h.
@@ -88,7 +91,15 @@ void hwinit(void) { GPIOD->ODR = VAL_GPIODODR;
/*
- * NVIC/SCB setup.
+ * NVIC/SCB initialization.
*/
- SCB->AIRCR = (0x5FA << 16) | (0x5 << 8); // PRIGROUP = 5 (2:6).
+ SCB_AIRCR = AIRCR_VECTKEY | AIRCR_PRIGROUP(0x3); // PRIGROUP 4:0 (4:4).
+
+ /*
+ * SysTick initialization.
+ */
+ SCB_SHPR(2) = 0x10 << 24; // SysTick at priority 1:0 (highest - 1).
+ ST_RVR = SYSCLK / (8000000 / CH_FREQUENCY) - 1;
+ ST_CVR = 0;
+ ST_CSR = ENABLE_ON_BITS | TICKINT_ENABLED_BITS | CLKSOURCE_EXT_BITS;
}
diff --git a/demos/ARMCM3-STM32F103-GCC/board.h b/demos/ARMCM3-STM32F103-GCC/board.h index b06745010..fa47168ed 100644 --- a/demos/ARMCM3-STM32F103-GCC/board.h +++ b/demos/ARMCM3-STM32F103-GCC/board.h @@ -52,24 +52,69 @@ #define AHB1CLK (SYSCLK / 1)
/*
- * Various clock settings.
+ * Values derived from clock settings.
*/
-#define SYSSRCBITS (0x2 << 0) // PLLCLK is SYSCLK (do not change)
-#define AHBBITS (0x0 << 4) // Divided by 1
-#define PPRE1BITS (0x4 << 8) // Divided by 2 (must be <= 36MHz)
-#define PPRE2BITS (0x4 << 11) // Divided by 2
-#define ADCPREBITS (0x3 << 14) // Divided by 8
-#define PLLSRCBITS (0x1 << 16) // PLL source is HSE/1
#define PLLPREBITS ((PLLPRE - 1) << 17)
#define PLLMULBITS ((PLLMUL - 2) << 18)
#ifdef SYSCLK_48
-#define USBPREBITS (0x1 << 22) // Divided by 1
+#define USBPREBITS USBPRE_DIV1_BITS
#else
-#define USBPREBITS (0x0 << 22) // Divided by 1.5
+#define USBPREBITS USBPRE_DIV1P5_BITS
#endif
-#define MCOSRCBITS (0x0 << 24) // No MCO output.
+/*
+ * Definitions for RCC_CR register.
+ */
+#define CR_HSION_MASK (0x1 << 0)
+#define CR_HSIRDY_MASK (0x1 << 1)
+#define CR_HSITRIM_MASK (0x1F << 3)
+#define HSITRIM_RESET_BITS (1 << 3)
+#define CR_HSICAL_MASK (0xFF << 8)
+#define CR_HSEON_MASK (0x1 << 16)
+#define CR_HSERDY_MASK (0x1 << 17)
+#define CR_HSEBYP_MASK (0x1 << 18)
+#define CR_CSSON_MASK (0x1 << 19)
+#define CR_PLLON_MASK (0x1 << 24)
+#define CR_PLLRDY_MASK (0x1 << 25)
+/*
+ * Definitions for RCC_CFGR register.
+ */
+#define CFGR_SW_MASK (0x3 << 0)
+#define SW_HSI_BITS (0 << 2)
+#define SW_HSE_BITS (1 << 2)
+#define SW_PLL_BITS (2 << 2)
+#define CFGR_SWS_MASK (0x3 << 2)
+#define SWS_HSI_BITS (0 << 2)
+#define SWS_HSE_BITS (1 << 2)
+#define SWS_PLL_BITS (2 << 2)
+#define CFGR_HPRE_MASK (0xF << 4)
+#define HPRE_DIV1_BITS (0 << 4)
+#define CFGR_PPRE1_MASK (0x7 << 8)
+#define PPRE1_DIV1_BITS (0 << 8)
+#define PPRE1_DIV2_BITS (4 << 8)
+#define CFGR_PPRE2_MASK (0x7 << 11)
+#define PPRE2_DIV1_BITS (0 << 11)
+#define PPRE2_DIV2_BITS (4 << 11)
+#define CFGR_ADCPRE_MASK (0x3 << 14)
+#define ADCPRE_DIV2_BITS (0 << 14)
+#define ADCPRE_DIV4_BITS (1 << 14)
+#define ADCPRE_DIV6_BITS (2 << 14)
+#define ADCPRE_DIV8_BITS (3 << 14)
+#define CFGR_PLLSRC_MASK (0x1 << 16)
+#define PLLSRC_HSI_BITS (0 << 16)
+#define PLLSRC_HSE_BITS (1 << 16)
+#define CFGR_PLLXTPRE_MASK (0x1 << 17)
+#define CFGR_PLLMUL_MASK (0xF << 18)
+#define CFGR_USBPRE_MASK (0x1 << 22)
+#define USBPRE_DIV1P5_BITS (0 << 22)
+#define USBPRE_DIV1_BITS (1 << 22)
+#define CFGR_MCO_MASK (0x7 << 24)
+#define MCO_DISABLED_BITS (0 << 24)
+
+/*
+ * IO pins assignments.
+ */
#define GPIOA_BUTTON (1 << 0)
#define GPIOC_MMCWP (1 << 6)
diff --git a/demos/ARMCM3-STM32F103-GCC/stm32lib/stm32f10x_conf.h b/demos/ARMCM3-STM32F103-GCC/stm32lib/stm32f10x_conf.h index 8e51a48fd..7df30d90d 100644 --- a/demos/ARMCM3-STM32F103-GCC/stm32lib/stm32f10x_conf.h +++ b/demos/ARMCM3-STM32F103-GCC/stm32lib/stm32f10x_conf.h @@ -77,7 +77,7 @@ //#define _IWDG
/************************************* NVIC ***********************************/
-#define _NVIC
+//#define _NVIC
/************************************* PWR ************************************/
//#define _PWR
@@ -94,7 +94,7 @@ //#define _SPI2
/************************************* SysTick ********************************/
-#define _SysTick
+//#define _SysTick
/************************************* TIM1 ***********************************/
//#define _TIM1
|