@@ -56,6 +56,17 @@ const struct rcc_clock_scale benchmarkclock = {
56
56
#include <libopencm3/stm32/usart.h>
57
57
#include <libopencm3/stm32/flash.h>
58
58
59
+ #define SERIAL_GPIO GPIOA
60
+ #define SERIAL_USART USART1
61
+ #define SERIAL_PINS (GPIO9 | GPIO10)
62
+ #define STM32
63
+ #define CW_BOARD
64
+ #elif defined(STM32F415RGT6 )
65
+ #include <libopencm3/stm32/rcc.h>
66
+ #include <libopencm3/stm32/gpio.h>
67
+ #include <libopencm3/stm32/usart.h>
68
+ #include <libopencm3/stm32/flash.h>
69
+
59
70
#define SERIAL_GPIO GPIOA
60
71
#define SERIAL_USART USART1
61
72
#define SERIAL_PINS (GPIO9 | GPIO10)
@@ -119,6 +130,7 @@ static void clock_setup(enum clock_mode clock)
119
130
120
131
flash_prefetch_enable ();
121
132
#elif defined(CW_BOARD )
133
+ (void ) clock ;
122
134
/* Some STM32 Platform */
123
135
rcc_periph_clock_enable (RCC_GPIOH );
124
136
rcc_osc_off (RCC_HSE );
@@ -131,8 +143,13 @@ static void clock_setup(enum clock_mode clock)
131
143
rcc_apb2_frequency = 7372800 ;
132
144
_clock_freq = 7372800 ;
133
145
rcc_set_hpre (RCC_CFGR_HPRE_DIV_NONE );
146
+ #if defined(STM32F3 )
134
147
rcc_set_ppre1 (RCC_CFGR_PPRE1_DIV_NONE );
135
148
rcc_set_ppre2 (RCC_CFGR_PPRE2_DIV_NONE );
149
+ #elif defined(STM32F4 )
150
+ rcc_set_ppre1 (RCC_CFGR_PPRE_DIV_NONE );
151
+ rcc_set_ppre2 (RCC_CFGR_PPRE_DIV_NONE );
152
+ #endif
136
153
rcc_set_sysclk_source (RCC_CFGR_SW_HSE );
137
154
rcc_wait_for_sysclk_status (RCC_HSE );
138
155
#elif defined(NUCLEO_BOARD )
@@ -147,8 +164,8 @@ static void clock_setup(enum clock_mode clock)
147
164
rcc_apb2_frequency = 16000000 ;
148
165
_clock_freq = 16000000 ;
149
166
rcc_set_hpre (RCC_CFGR_HPRE_NODIV );
150
- rcc_set_ppre1 (RCC_CFGR_PPRE1_NODIV );
151
- rcc_set_ppre2 (RCC_CFGR_PPRE2_NODIV );
167
+ rcc_set_ppre1 (RCC_CFGR_PPRE_NODIV );
168
+ rcc_set_ppre2 (RCC_CFGR_PPRE_NODIV );
152
169
flash_dcache_enable ();
153
170
flash_icache_enable ();
154
171
flash_set_ws (FLASH_ACR_LATENCY_0WS );
@@ -165,8 +182,8 @@ static void clock_setup(enum clock_mode clock)
165
182
rcc_apb2_frequency = 80000000 ;
166
183
_clock_freq = 80000000 ;
167
184
rcc_set_hpre (RCC_CFGR_HPRE_NODIV );
168
- rcc_set_ppre1 (RCC_CFGR_PPRE1_NODIV );
169
- rcc_set_ppre2 (RCC_CFGR_PPRE2_NODIV );
185
+ rcc_set_ppre1 (RCC_CFGR_PPRE_NODIV );
186
+ rcc_set_ppre2 (RCC_CFGR_PPRE_NODIV );
170
187
rcc_osc_off (RCC_PLL );
171
188
while (rcc_is_osc_ready (RCC_PLL ));
172
189
/* Configure the PLL oscillator (use CUBEMX tool -> scale HSI16 to 80MHz). */
@@ -189,24 +206,33 @@ static void clock_setup(enum clock_mode clock)
189
206
rcc_periph_clock_enable (RCC_PWR );
190
207
rcc_periph_clock_enable (RCC_SYSCFG );
191
208
pwr_set_vos_scale (PWR_SCALE1 );
209
+ /* The L4R5ZI chip also needs the R1MODE bit in PWR_CR5 register set, but
210
+ OpenCM3 doesn't support this yet. But luckily the default value for the bit
211
+ is 1. */
192
212
switch (clock ) {
193
213
case CLOCK_BENCHMARK :
194
214
/* Benchmark straight from the HSI16 without prescaling */
195
215
rcc_osc_on (RCC_HSI16 );
196
216
rcc_wait_for_osc_ready (RCC_HSI16 );
197
- rcc_ahb_frequency = 16000000 ;
198
- rcc_apb1_frequency = 16000000 ;
199
- rcc_apb2_frequency = 16000000 ;
200
- _clock_freq = 16000000 ;
217
+ rcc_ahb_frequency = 20000000 ;
218
+ rcc_apb1_frequency = 20000000 ;
219
+ rcc_apb2_frequency = 20000000 ;
220
+ _clock_freq = 20000000 ;
201
221
rcc_set_hpre (RCC_CFGR_HPRE_NODIV );
202
- rcc_set_ppre1 (RCC_CFGR_PPRE1_NODIV );
203
- rcc_set_ppre2 (RCC_CFGR_PPRE2_NODIV );
222
+ rcc_set_ppre1 (RCC_CFGR_PPRE_NODIV );
223
+ rcc_set_ppre2 (RCC_CFGR_PPRE_NODIV );
224
+ rcc_osc_off (RCC_PLL );
225
+ while (rcc_is_osc_ready (RCC_PLL ));
226
+ /* Configure the PLL oscillator (use CUBEMX tool -> scale HSI16 to 20MHz). */
227
+ _rcc_set_main_pll (RCC_PLLCFGR_PLLSRC_HSI16 , 1 , 10 , 2 , RCC_PLLCFGR_PLLQ_DIV2 , RCC_PLLCFGR_PLLR_DIV8 );
228
+ /* Enable PLL oscillator and wait for it to stabilize. */
229
+ rcc_osc_on (RCC_PLL );
204
230
flash_dcache_enable ();
205
231
flash_icache_enable ();
206
232
flash_set_ws (FLASH_ACR_LATENCY_0WS );
207
233
flash_prefetch_enable ();
208
- rcc_set_sysclk_source (RCC_CFGR_SW_HSI16 );
209
- rcc_wait_for_sysclk_status (RCC_HSI16 );
234
+ rcc_set_sysclk_source (RCC_CFGR_SW_PLL );
235
+ rcc_wait_for_sysclk_status (RCC_PLL );
210
236
break ;
211
237
case CLOCK_FAST :
212
238
default :
@@ -217,12 +243,12 @@ static void clock_setup(enum clock_mode clock)
217
243
rcc_apb2_frequency = 120000000 ;
218
244
_clock_freq = 120000000 ;
219
245
rcc_set_hpre (RCC_CFGR_HPRE_NODIV );
220
- rcc_set_ppre1 (RCC_CFGR_PPRE1_NODIV );
221
- rcc_set_ppre2 (RCC_CFGR_PPRE2_NODIV );
246
+ rcc_set_ppre1 (RCC_CFGR_PPRE_NODIV );
247
+ rcc_set_ppre2 (RCC_CFGR_PPRE_NODIV );
222
248
rcc_osc_off (RCC_PLL );
223
249
while (rcc_is_osc_ready (RCC_PLL ));
224
250
/* Configure the PLL oscillator (use CUBEMX tool -> scale HSI16 to 120MHz). */
225
- _rcc_set_main_pll (RCC_PLLCFGR_PLLSRC_HSI16 , 2 , 30 , 2u , RCC_PLLCFGR_PLLQ_DIV2 , RCC_PLLCFGR_PLLR_DIV2 );
251
+ _rcc_set_main_pll (RCC_PLLCFGR_PLLSRC_HSI16 , 1 , 15 , 2 , RCC_PLLCFGR_PLLQ_DIV2 , RCC_PLLCFGR_PLLR_DIV2 );
226
252
/* Enable PLL oscillator and wait for it to stabilize. */
227
253
rcc_osc_on (RCC_PLL );
228
254
rcc_wait_for_osc_ready (RCC_PLL );
@@ -235,7 +261,9 @@ static void clock_setup(enum clock_mode clock)
235
261
break ;
236
262
}
237
263
rcc_osc_on (RCC_HSI48 ); /* HSI48 must always be on for RNG */
264
+ rcc_wait_for_osc_ready (RCC_HSI48 );
238
265
rcc_periph_clock_enable (RCC_RNG );
266
+ rcc_set_clock48_source (RCC_CCIPR_CLK48SEL_HSI48 );
239
267
rng_enable ();
240
268
#else
241
269
#error Unsupported platform
@@ -358,3 +386,74 @@ size_t hal_get_stack_size(void)
358
386
__asm__ volatile ("mov %0, sp" : "=r" (cur_stack ));
359
387
return cur_stack - heap_end ;
360
388
}
389
+
390
+ /* Implement some system calls to shut up the linker warnings */
391
+
392
+ #include <errno.h>
393
+ #undef errno
394
+ extern int errno ;
395
+
396
+ int __wrap__close (int fd )
397
+ {
398
+ errno = ENOSYS ;
399
+ (void ) fd ;
400
+ return -1 ;
401
+ }
402
+
403
+ #include <sys/stat.h>
404
+
405
+ int __wrap__fstat (int fd , struct stat * buf )
406
+ {
407
+ (void ) fd ;
408
+ (void ) buf ;
409
+ errno = ENOSYS ;
410
+ return -1 ;
411
+ }
412
+
413
+ int __wrap__getpid (void )
414
+ {
415
+ errno = ENOSYS ;
416
+ return -1 ;
417
+ }
418
+
419
+ int __wrap__isatty (int file )
420
+ {
421
+ (void ) file ;
422
+ errno = ENOSYS ;
423
+ return 0 ;
424
+ }
425
+
426
+ int __wrap__kill (int pid , int sig )
427
+ {
428
+ (void ) pid ;
429
+ (void ) sig ;
430
+ errno = ENOSYS ;
431
+ return -1 ;
432
+ }
433
+
434
+ int __wrap__lseek (int fd , int ptr , int dir )
435
+ {
436
+ (void ) fd ;
437
+ (void ) ptr ;
438
+ (void ) dir ;
439
+ errno = ENOSYS ;
440
+ return -1 ;
441
+ }
442
+
443
+ int __wrap__read (int fd , char * ptr , int len )
444
+ {
445
+ (void ) fd ;
446
+ (void ) ptr ;
447
+ (void ) len ;
448
+ errno = ENOSYS ;
449
+ return -1 ;
450
+ }
451
+
452
+ int __wrap__write (int fd , const char * ptr , int len )
453
+ {
454
+ (void ) fd ;
455
+ (void ) ptr ;
456
+ (void ) len ;
457
+ errno = ENOSYS ;
458
+ return -1 ;
459
+ }
0 commit comments