3
3
*
4
4
* Copyright (c) 2010 Perry Hung.
5
5
* Copyright (c) 2011, 2012 LeafLabs, LLC.
6
+ * Copyright 2014 Google, Inc.
6
7
*
7
8
* Permission is hereby granted, free of charge, to any person
8
9
* obtaining a copy of this software and associated documentation
52
53
#include < libmaple/systick.h>
53
54
#include " boards_private.h"
54
55
55
- static void setup_flash (void );
56
- static void setup_clocks (void );
57
56
static void setup_nvic (void );
58
- static void setup_adcs (void );
59
- static void setup_timers (void );
60
-
61
- /*
62
- * Exported functions
63
- */
64
57
65
58
void init (void ) {
66
- setup_flash ();
67
- setup_clocks ();
59
+ wirish::priv::board_setup_flash ();
60
+ wirish::priv::board_setup_clocks ();
68
61
setup_nvic ();
69
62
systick_init (SYSTICK_RELOAD_VAL);
70
63
wirish::priv::board_setup_gpio ();
71
- setup_adcs ();
72
- setup_timers ();
64
+ wirish::priv::board_setup_adcs ();
65
+ wirish::priv::board_setup_timers ();
73
66
wirish::priv::board_setup_usb ();
74
67
wirish::priv::series_init ();
75
68
boardInit ();
@@ -91,20 +84,52 @@ bool boardUsesPin(uint8 pin) {
91
84
}
92
85
93
86
/*
94
- * Auxiliary routines
87
+ * These addresses are where usercode starts when a bootloader is
88
+ * present. If no bootloader is present, the user NVIC usually starts
89
+ * at the Flash base address, 0x08000000.
90
+ */
91
+ #if defined(BOOTLOADER_maple)
92
+ #define USER_ADDR_ROM 0x08005000
93
+ #elif defined(BOOTLOADER_robotis)
94
+ #define USER_ADDR_ROM 0x08003000
95
+ #endif
96
+ #define USER_ADDR_RAM 0x20000C00
97
+ extern char __text_start__;
98
+
99
+ static void setup_nvic (void ) {
100
+ #ifdef VECT_TAB_FLASH
101
+ nvic_init (USER_ADDR_ROM, 0 );
102
+ #elif defined VECT_TAB_RAM
103
+ nvic_init (USER_ADDR_RAM, 0 );
104
+ #elif defined VECT_TAB_BASE
105
+ nvic_init ((uint32)0x08000000 , 0 );
106
+ #elif defined VECT_TAB_ADDR
107
+ // A numerically supplied value
108
+ nvic_init ((uint32)VECT_TAB_ADDR, 0 );
109
+ #else
110
+ // Use the __text_start__ value from the linker script; this
111
+ // should be the start of the vector table.
112
+ nvic_init ((uint32)&__text_start__, 0 );
113
+ #endif
114
+ }
115
+
116
+ /*
117
+ * Default implementations for some board-specific routines.
95
118
*/
96
119
97
- static void setup_flash (void ) {
120
+ namespace wirish {
121
+ namespace priv {
122
+
123
+ __weak void board_setup_flash (void ) {
98
124
// Turn on as many Flash "go faster" features as
99
125
// possible. flash_enable_features() just ignores any flags it
100
126
// can't support.
101
127
flash_enable_features (FLASH_PREFETCH | FLASH_ICACHE | FLASH_DCACHE);
102
- // Configure the wait states, assuming we're operating at "close
103
- // enough" to 3.3V.
128
+ // FLASH_SAFE_WAIT_STATES is a hack that needs to go away.
104
129
flash_set_latency (FLASH_SAFE_WAIT_STATES);
105
130
}
106
131
107
- static void setup_clocks (void ) {
132
+ __weak void board_setup_clocks (void ) {
108
133
// Turn on HSI. We'll switch to and run off of this while we're
109
134
// setting up the main PLL.
110
135
rcc_turn_on_clk (RCC_CLK_HSI);
@@ -139,42 +164,12 @@ static void setup_clocks(void) {
139
164
rcc_switch_sysclk (RCC_CLKSRC_PLL);
140
165
}
141
166
142
- /*
143
- * These addresses are where usercode starts when a bootloader is
144
- * present. If no bootloader is present, the user NVIC usually starts
145
- * at the Flash base address, 0x08000000.
146
- */
147
- #if defined(BOOTLOADER_maple)
148
- #define USER_ADDR_ROM 0x08005000
149
- #elif defined(BOOTLOADER_robotis)
150
- #define USER_ADDR_ROM 0x08003000
151
- #endif
152
- #define USER_ADDR_RAM 0x20000C00
153
- extern char __text_start__;
154
-
155
- static void setup_nvic (void ) {
156
- #ifdef VECT_TAB_FLASH
157
- nvic_init (USER_ADDR_ROM, 0 );
158
- #elif defined VECT_TAB_RAM
159
- nvic_init (USER_ADDR_RAM, 0 );
160
- #elif defined VECT_TAB_BASE
161
- nvic_init ((uint32)0x08000000 , 0 );
162
- #elif defined VECT_TAB_ADDR
163
- // A numerically supplied value
164
- nvic_init ((uint32)VECT_TAB_ADDR, 0 );
165
- #else
166
- // Use the __text_start__ value from the linker script; this
167
- // should be the start of the vector table.
168
- nvic_init ((uint32)&__text_start__, 0 );
169
- #endif
170
- }
171
-
172
167
static void adc_default_config (const adc_dev *dev) {
173
168
adc_enable_single_swstart (dev);
174
169
adc_set_sample_rate (dev, wirish::priv::w_adc_smp);
175
170
}
176
171
177
- static void setup_adcs (void ) {
172
+ __weak void board_setup_adcs (void ) {
178
173
adc_set_prescaler (wirish::priv::w_adc_pre);
179
174
adc_foreach (adc_default_config);
180
175
}
@@ -214,6 +209,9 @@ static void timer_default_config(timer_dev *dev) {
214
209
timer_resume (dev);
215
210
}
216
211
217
- static void setup_timers (void ) {
212
+ __weak void board_setup_timers (void ) {
218
213
timer_foreach (timer_default_config);
219
214
}
215
+
216
+ }
217
+ }
0 commit comments