Those chip close-ups are always so cute...
How to start with the STM32F4?
Of course, the first document to find for any chip is the datasheet , and the reference manual . To write the start-up code, the manual of the CPU core  will be necessary as well. Then the header files with all peripherals register as macro symbol  would come to mind. Yes, you have to download the full 150+MB archive to get the (not even 1MB) header files, which are in:
Later it will also be interesting to know what is connected with what  outside of the chip, on the board.
Clocks and initial settings
On start-up, the CPU core runs with the high speed internal clock (HSI) at 16MHz. Before increasing the clock frequency, flash settings must be updated: the CPU will run significantly faster than the flash.
Settings for a CPU at maximum clock (168MHz) and normal power supply:
/* Flash settings (see RM0090 rev9, p80) */ FLASH->ACR = FLASH_ACR_LATENCY_5WS /* 6 CPU cycle wait */ | FLASH_ACR_PRFTEN /* enable prefetch */ | FLASH_ACR_ICEN /* instruction cache enable */ | FLASH_ACR_DCEN; /* data cache enable */
/* Configure clocks * Max SYSCLK: 168MHz * Max AHB: SYSCLK * Max APB1: SYSCLK/4 = 48MHz * Max APB2: SYSCLK/2 = 86MHz * + enable sys clock output 2 with clock divider = 4 */ RCC->CFGR = 0x0 /* Clock output 2 is SYSCLK (RCC_CFGR_MCO2) */ | ( 0x6 << 27) /* Clock output divider */ | RCC_CFGR_PPRE2_DIV2 /* APB2 prescaler */ | RCC_CFGR_PPRE1_DIV4; /* APB2 prescaler */
My board has an 8MHz external crystal oscillator. In order to generate a 168MHz system clock, the PLL must be used:
/* Clock control register */ RCC->CR = RCC_CR_HSEON; /* Enable external oscillator */ /* Wait for locked external oscillator */ while((RCC->CR & RCC_CR_HSERDY) != RCC_CR_HSERDY); /* PLL config */ RCC->PLLCFGR = RCC_PLLCFGR_PLLSRC_HSE /* PLL source */ | (4 << 0) /* PLL input division */ | (168 << 6) /* PLL multiplication */ | (0 << 16) /* PLL sys clock division */ | (7 << 24); /* PLL usb clock division =48MHz */ /* crystal: 8MHz * PLL in: 2MHz (div 4) * PLL loop: 336MHz (mul 168) * PLL out: 168MHz (div 2) * PLL usb: 48MHz (div 7) */ /* Enable PLL */ RCC->CR |= RCC_CR_PLLON; /* Wait for locked PLL */ while((RCC->CR & RCC_CR_PLLRDY) != RCC_CR_PLLRDY); /* select system clock */ RCC->CFGR &= ~RCC_CFGR_SW; /* clear */ RCC->CFGR |= RCC_CFGR_SW_PLL; /* SYSCLK is PLL */ /* Wait for SYSCLK to be PPL */ while((RCC->CFGR & RCC_CFGR_SW_PLL) != RCC_CFGR_SW_PLL);
A quick test of the clock settings can be done using the Microcontroller Clock Output pins (MCO1 and MCO2). According to the clock tree diagram, SYSCLK is connected to MCO2. This pin as to be set as alternate function.
/* PC9 = MCO2 = alternate func */ GPIOC->MODER = 0x00090000; /* output */ GPIOC->OTYPER = 0x00000000; /* push-pull */ GPIOC->OSPEEDR = 0x000D0000; /* medium speed */
The system clock divided by 4 is on the pin 40. Since my vjCanUsb board makes it easy to reach any pi...
42MHz * 4 = 168MHz (Success!)
|||STM32F427xx and STM32F429xx datasheet http://www.st.com/web/en/resource/technical/document/datasheet/DM00071990.pdf|
|||STM32F42xxx (and others) reference manual http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf|
|||ARM Cortex-M4 Processor, Technical Reference Manual http://infocenter.arm.com/help/topic/com.arm.doc.ddi0439c/DDI0439C_cortex_m4_r0p1_trm.pdf|
|||STM32CubeF4 download page http://www.st.com/web/en/catalog/tools/PF259243|
|||UM1670 User manual (for the discovery board) http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00093903.pdf|