aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-03-30 22:50:18 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-03-30 22:51:28 -0400
commit869ed39e4c28ebb9813a8b28192d4ca92f72bf22 (patch)
tree6293c34e1dc96ae3f7c0bfdd926a714c03062ae2
parent2c33d55bae8f9e0e009634072ab05302fc734a65 (diff)
downloadlibrambutan-869ed39e4c28ebb9813a8b28192d4ca92f72bf22.tar.gz
librambutan-869ed39e4c28ebb9813a8b28192d4ca92f72bf22.zip
Removed STM32 flash code, replaced with barebones hacks for now.
At this point, there shouldn't be any STM code being compiled and linked against. There are still a bunch of STM header includes, though.
-rw-r--r--Makefile49
-rw-r--r--core/wiring.c16
-rw-r--r--libmaple/flash.c29
-rw-r--r--libmaple/flash.h16
-rw-r--r--libmaple/nvic.c4
-rw-r--r--libmaple/nvic.h2
-rw-r--r--libmaple/rcc.c6
-rw-r--r--libmaple/usb.h1
8 files changed, 80 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index bdc2bf1..5d462dc 100644
--- a/Makefile
+++ b/Makefile
@@ -34,8 +34,8 @@ OUTDIRS = $(BUILD_PATH)/$(STM_SRC) \
$(BUILD_PATH)/core/comm
-INCLUDES = -Istm32lib/inc \
- -I$(LIB_PATH) \
+INCLUDES = -I$(LIB_PATH) \
+ -Istm32lib/inc \
-I./ \
-Icore \
-Icore/comm
@@ -61,30 +61,27 @@ ODFLAGS = -S
# main source file
MAIN=main.c
-STM32SRCS = $(STM_SRC)/stm32f10x_flash.c \
- $(STM_SRC)/stm32f10x_nvic.c
-
-CSRC = libmaple/systick.c \
- libmaple/timers.c \
- libmaple/adc.c \
- libmaple/syscalls.c \
- libmaple/stm32f10x_it.c \
- libmaple/exti.c \
- libmaple/gpio.c \
- libmaple/nvic.c \
- libmaple/usart.c \
- libmaple/util.c \
- libmaple/usb.c \
- libmaple/rcc.c \
- core/wiring.c \
- core/wiring_shift.c \
- core/wiring_analog.c \
- core/time.c \
- core/pwm.c \
- core/ext_interrupts.c \
- core/wiring_digital.c
-
-CSRC += $(STM32SRCS)
+CSRC = libmaple/systick.c \
+ libmaple/timers.c \
+ libmaple/adc.c \
+ libmaple/syscalls.c \
+ libmaple/stm32f10x_it.c \
+ libmaple/exti.c \
+ libmaple/gpio.c \
+ libmaple/nvic.c \
+ libmaple/usart.c \
+ libmaple/util.c \
+ libmaple/usb.c \
+ libmaple/rcc.c \
+ libmaple/flash.c \
+ core/wiring.c \
+ core/wiring_shift.c \
+ core/wiring_analog.c \
+ core/time.c \
+ core/pwm.c \
+ core/ext_interrupts.c \
+ core/wiring_digital.c
+
CPPSRC = core/wiring_math.cpp \
core/Print.cpp \
diff --git a/core/wiring.c b/core/wiring.c
index 488d15c..e125259 100644
--- a/core/wiring.c
+++ b/core/wiring.c
@@ -24,18 +24,15 @@
*/
#include "wiring.h"
-#include "stm32f10x_flash.h"
-#include "stm32f10x_map.h"
-#include "stm32f10x_nvic.h"
#include "rcc.h"
#include "systick.h"
#include "gpio.h"
-void NVIC_Configuration(void);
+void nvic_init(void);
void init(void) {
rcc_init();
- NVIC_Configuration();
+ nvic_init();
systick_init();
gpio_init();
adc_init();
@@ -45,16 +42,15 @@ void init(void) {
timer_init(4, 1);
}
-void NVIC_Configuration(void) {
+void nvic_init(void) {
#ifdef VECT_TAB_ROM
- NVIC_SetVectorTable(USER_ADDR_ROM, 0x0);
+ nvic_set_vector_table(USER_ADDR_ROM, 0x0);
#warning writing to ROM
#elif defined VECT_TAB_RAM
- NVIC_SetVectorTable(USER_ADDR_RAM, 0x0);
+ nvic_set_vector_table(USER_ADDR_RAM, 0x0);
#warning writing to RAM
#else // VECT_TAB_BASE
/* Set the Vector Table base location at 0x08000000 */
- NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
+ nvic_set_vector_table(((uint32)0x08000000), 0x0);
#endif
}
-
diff --git a/libmaple/flash.c b/libmaple/flash.c
new file mode 100644
index 0000000..a3ee26b
--- /dev/null
+++ b/libmaple/flash.c
@@ -0,0 +1,29 @@
+#include "libmaple.h"
+#include "flash.h"
+
+#define ACR_PRFTBE ((uint32)0xFFFFFFEF)
+#define ACR_PRFTBE_ENABLE ((uint32)0x00000010) /* FLASH Prefetch Buffer Enable */
+#define ACR_PRFTBE_DISABLE ((uint32)0x00000000) /* FLASH Prefetch Buffer Disable */
+
+#define ACR_LATENCY ((uint32)0x00000038)
+#define ACR_LATENCY_0 ((uint32)0x00000000) /* FLASH Zero Latency cycle */
+#define ACR_LATENCY_1 ((uint32)0x00000001) /* FLASH One Latency cycle */
+#define ACR_LATENCY_2 ((uint32)0x00000002) /* FLASH Two Latency cycles */
+
+void flash_enable_prefetch(void) {
+ uint32 acr = __read(FLASH_ACR);
+
+ acr &= ACR_PRFTBE;
+ acr |= ACR_PRFTBE_ENABLE;
+
+ __write(FLASH_ACR, acr);
+}
+
+void flash_set_latency(void) {
+ uint32 acr = __read(FLASH_ACR);
+
+ acr &= ACR_LATENCY;
+ acr |= ACR_LATENCY_2;
+
+ __write(FLASH_ACR, acr);
+}
diff --git a/libmaple/flash.h b/libmaple/flash.h
new file mode 100644
index 0000000..741a444
--- /dev/null
+++ b/libmaple/flash.h
@@ -0,0 +1,16 @@
+/**
+ * @brief
+ */
+
+#ifndef _FLASH_H_
+#define _FLASH_H_
+
+#define FLASH_BASE 0x40022000
+#define FLASH_ACR FLASH_BASE
+
+void flash_enable_prefetch(void);
+void flash_set_latency(void);
+
+#endif
+
+
diff --git a/libmaple/nvic.c b/libmaple/nvic.c
index 9b8c84f..45c1902 100644
--- a/libmaple/nvic.c
+++ b/libmaple/nvic.c
@@ -38,7 +38,7 @@ void nvic_disable_interrupts(void) {
void nvic_set_vector_table(uint32_t *addr, uint32_t offset) {
-// SCB->VTOR = NVIC_VectTab | (Offset & (u32)0x1FFFFF80);
+ __write(SCB_VTOR, (uint32_t)addr | (offset & 0x1FFFFF80));
}
@@ -57,3 +57,5 @@ void nvic_enable_interrupt(uint32 n) {
REG_SET_BIT(NVIC_ISER1, n - 32);
}
}
+
+
diff --git a/libmaple/nvic.h b/libmaple/nvic.h
index 5908e9c..89b66fc 100644
--- a/libmaple/nvic.h
+++ b/libmaple/nvic.h
@@ -18,8 +18,6 @@
* ****************************************************************************/
/**
- * @file nvic.h
- *
* @brief Nested interrupt controller defines and prototypes
*/
diff --git a/libmaple/rcc.c b/libmaple/rcc.c
index bf76eb0..98b115a 100644
--- a/libmaple/rcc.c
+++ b/libmaple/rcc.c
@@ -6,8 +6,8 @@
*/
#include "libmaple.h"
+#include "flash.h"
#include "rcc.h"
-#include "stm32f10x_flash.h"
static void set_ahb_prescaler(uint32_t divider) {
uint32_t cfgr = __read(RCC_CFGR);
@@ -95,10 +95,10 @@ void rcc_init(void) {
/* Leave this here for now... */
/* Enable Prefetch Buffer */
- FLASH_PrefetchBufferCmd( (u32)FLASH_PrefetchBuffer_Enable);
+ flash_enable_prefetch();
/* Flash 2 wait state */
- FLASH_SetLatency(FLASH_Latency_2);
+ flash_set_latency();
set_ahb_prescaler(SYSCLK_DIV_1);
set_apb1_prescaler(HCLK_DIV_2);
diff --git a/libmaple/usb.h b/libmaple/usb.h
index 3b7a971..960e1f4 100644
--- a/libmaple/usb.h
+++ b/libmaple/usb.h
@@ -3,7 +3,6 @@
#include <inttypes.h>
#include "util.h"
-#include "cortexm3_macro.h"
#include "usb_regs.h"
#include "bootVect.h"