64 #include "stm32f4xx.h"
66 #if !defined (HSE_VALUE)
67 #define HSE_VALUE ((uint32_t)25000000)
70 #if !defined (HSI_VALUE)
71 #define HSI_VALUE ((uint32_t)16000000)
92 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\
93 || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
94 || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx)
99 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
100 || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
108 #define VECT_TAB_OFFSET 0x00
136 const uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
146 #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
147 static void SystemInit_ExtMemCtl(
void);
168 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
169 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));
172 #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
173 SystemInit_ExtMemCtl();
222 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
268 #if defined (DATA_IN_ExtSRAM) && defined (DATA_IN_ExtSDRAM)
269 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
270 || defined(STM32F469xx) || defined(STM32F479xx)
279 void SystemInit_ExtMemCtl(
void)
281 __IO uint32_t tmp = 0x00;
283 register uint32_t tmpreg = 0, timeout = 0xFFFF;
284 register __IO uint32_t index;
287 RCC->AHB1ENR |= 0x000001F8;
293 GPIOD->AFR[0] = 0x00CCC0CC;
294 GPIOD->AFR[1] = 0xCCCCCCCC;
296 GPIOD->MODER = 0xAAAA0A8A;
298 GPIOD->OSPEEDR = 0xFFFF0FCF;
300 GPIOD->OTYPER = 0x00000000;
302 GPIOD->PUPDR = 0x00000000;
305 GPIOE->AFR[0] = 0xC00CC0CC;
306 GPIOE->AFR[1] = 0xCCCCCCCC;
308 GPIOE->MODER = 0xAAAA828A;
310 GPIOE->OSPEEDR = 0xFFFFC3CF;
312 GPIOE->OTYPER = 0x00000000;
314 GPIOE->PUPDR = 0x00000000;
317 GPIOF->AFR[0] = 0xCCCCCCCC;
318 GPIOF->AFR[1] = 0xCCCCCCCC;
320 GPIOF->MODER = 0xAA800AAA;
322 GPIOF->OSPEEDR = 0xAA800AAA;
324 GPIOF->OTYPER = 0x00000000;
326 GPIOF->PUPDR = 0x00000000;
329 GPIOG->AFR[0] = 0xCCCCCCCC;
330 GPIOG->AFR[1] = 0xCCCCCCCC;
332 GPIOG->MODER = 0xAAAAAAAA;
334 GPIOG->OSPEEDR = 0xAAAAAAAA;
336 GPIOG->OTYPER = 0x00000000;
338 GPIOG->PUPDR = 0x00000000;
341 GPIOH->AFR[0] = 0x00C0CC00;
342 GPIOH->AFR[1] = 0xCCCCCCCC;
344 GPIOH->MODER = 0xAAAA08A0;
346 GPIOH->OSPEEDR = 0xAAAA08A0;
348 GPIOH->OTYPER = 0x00000000;
350 GPIOH->PUPDR = 0x00000000;
353 GPIOI->AFR[0] = 0xCCCCCCCC;
354 GPIOI->AFR[1] = 0x00000CC0;
356 GPIOI->MODER = 0x0028AAAA;
358 GPIOI->OSPEEDR = 0x0028AAAA;
360 GPIOI->OTYPER = 0x00000000;
362 GPIOI->PUPDR = 0x00000000;
366 RCC->AHB3ENR |= 0x00000001;
377 while((tmpreg != 0) && (timeout-- > 0))
383 for (index = 0; index<1000; index++);
388 while((tmpreg != 0) && (timeout-- > 0))
396 while((tmpreg != 0) && (timeout-- > 0))
404 while((tmpreg != 0) && (timeout-- > 0))
417 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
423 #if defined(STM32F469xx) || defined(STM32F479xx)
433 #elif defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
442 void SystemInit_ExtMemCtl(
void)
444 __IO uint32_t tmp = 0x00;
445 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
446 || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
447 #if defined (DATA_IN_ExtSDRAM)
448 register uint32_t tmpreg = 0, timeout = 0xFFFF;
449 register __IO uint32_t index;
451 #if defined(STM32F446xx)
454 RCC->AHB1ENR |= 0x0000007D;
458 RCC->AHB1ENR |= 0x000001F8;
463 #if defined(STM32F446xx)
465 GPIOA->AFR[0] |= 0xC0000000;
466 GPIOA->AFR[1] |= 0x00000000;
468 GPIOA->MODER |= 0x00008000;
470 GPIOA->OSPEEDR |= 0x00008000;
472 GPIOA->OTYPER |= 0x00000000;
474 GPIOA->PUPDR |= 0x00000000;
477 GPIOC->AFR[0] |= 0x00CC0000;
478 GPIOC->AFR[1] |= 0x00000000;
480 GPIOC->MODER |= 0x00000A00;
482 GPIOC->OSPEEDR |= 0x00000A00;
484 GPIOC->OTYPER |= 0x00000000;
486 GPIOC->PUPDR |= 0x00000000;
490 GPIOD->AFR[0] = 0x000000CC;
491 GPIOD->AFR[1] = 0xCC000CCC;
493 GPIOD->MODER = 0xA02A000A;
495 GPIOD->OSPEEDR = 0xA02A000A;
497 GPIOD->OTYPER = 0x00000000;
499 GPIOD->PUPDR = 0x00000000;
502 GPIOE->AFR[0] = 0xC00000CC;
503 GPIOE->AFR[1] = 0xCCCCCCCC;
505 GPIOE->MODER = 0xAAAA800A;
507 GPIOE->OSPEEDR = 0xAAAA800A;
509 GPIOE->OTYPER = 0x00000000;
511 GPIOE->PUPDR = 0x00000000;
514 GPIOF->AFR[0] = 0xCCCCCCCC;
515 GPIOF->AFR[1] = 0xCCCCCCCC;
517 GPIOF->MODER = 0xAA800AAA;
519 GPIOF->OSPEEDR = 0xAA800AAA;
521 GPIOF->OTYPER = 0x00000000;
523 GPIOF->PUPDR = 0x00000000;
526 GPIOG->AFR[0] = 0xCCCCCCCC;
527 GPIOG->AFR[1] = 0xCCCCCCCC;
529 GPIOG->MODER = 0xAAAAAAAA;
531 GPIOG->OSPEEDR = 0xAAAAAAAA;
533 GPIOG->OTYPER = 0x00000000;
535 GPIOG->PUPDR = 0x00000000;
537 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
538 || defined(STM32F469xx) || defined(STM32F479xx)
540 GPIOH->AFR[0] = 0x00C0CC00;
541 GPIOH->AFR[1] = 0xCCCCCCCC;
543 GPIOH->MODER = 0xAAAA08A0;
545 GPIOH->OSPEEDR = 0xAAAA08A0;
547 GPIOH->OTYPER = 0x00000000;
549 GPIOH->PUPDR = 0x00000000;
552 GPIOI->AFR[0] = 0xCCCCCCCC;
553 GPIOI->AFR[1] = 0x00000CC0;
555 GPIOI->MODER = 0x0028AAAA;
557 GPIOI->OSPEEDR = 0x0028AAAA;
559 GPIOI->OTYPER = 0x00000000;
561 GPIOI->PUPDR = 0x00000000;
566 RCC->AHB3ENR |= 0x00000001;
571 #if defined(STM32F446xx)
582 while((tmpreg != 0) && (timeout-- > 0))
588 for (index = 0; index<1000; index++);
593 while((tmpreg != 0) && (timeout-- > 0))
599 #if defined(STM32F446xx)
605 while((tmpreg != 0) && (timeout-- > 0))
611 #if defined(STM32F446xx)
617 while((tmpreg != 0) && (timeout-- > 0))
624 #if defined(STM32F446xx)
636 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\
637 || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\
638 || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx)
640 #if defined(DATA_IN_ExtSRAM)
643 RCC->AHB1ENR |= 0x00000078;
648 GPIOD->AFR[0] = 0x00CCC0CC;
649 GPIOD->AFR[1] = 0xCCCCCCCC;
651 GPIOD->MODER = 0xAAAA0A8A;
653 GPIOD->OSPEEDR = 0xFFFF0FCF;
655 GPIOD->OTYPER = 0x00000000;
657 GPIOD->PUPDR = 0x00000000;
660 GPIOE->AFR[0] = 0xC00CC0CC;
661 GPIOE->AFR[1] = 0xCCCCCCCC;
663 GPIOE->MODER = 0xAAAA828A;
665 GPIOE->OSPEEDR = 0xFFFFC3CF;
667 GPIOE->OTYPER = 0x00000000;
669 GPIOE->PUPDR = 0x00000000;
672 GPIOF->AFR[0] = 0x00CCCCCC;
673 GPIOF->AFR[1] = 0xCCCC0000;
675 GPIOF->MODER = 0xAA000AAA;
677 GPIOF->OSPEEDR = 0xFF000FFF;
679 GPIOF->OTYPER = 0x00000000;
681 GPIOF->PUPDR = 0x00000000;
684 GPIOG->AFR[0] = 0x00CCCCCC;
685 GPIOG->AFR[1] = 0x000000C0;
687 GPIOG->MODER = 0x00085AAA;
689 GPIOG->OSPEEDR = 0x000CAFFF;
691 GPIOG->OTYPER = 0x00000000;
693 GPIOG->PUPDR = 0x00000000;
697 RCC->AHB3ENR |= 0x00000001;
699 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
707 #if defined(STM32F469xx) || defined(STM32F479xx)
715 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx)\
716 || defined(STM32F412Zx) || defined(STM32F412Vx)