libopencm3/libopencm3 — pull request #379 by ChuckM (2014-12-07 01:44:20+00:00)
Title: First cut at an HSI configuration API for rcc on the STMF4 series.

This is a first cut at a simplified setup function for the HSI clock on the STM32F series. The function is called simply `rcc_set_hsi_clock(uint32_t speed)` and it takes 32 bit constant which has encoded the PLL values to achieve that speed. It is possible to generalize it to something even more generic, one could have `rcc_set_pll_clock(uint32_t pll_constants, uint32_t base_frequency);` where the `pll constants` would have been set for an HSE or HSI input, and `base_frequency` would be the starting crystal frequency. But that is prone to error is you used HSI PLL flags and an HSE crystal for example.

Two things I do like is that it automatically computes the best APB2 and APB1 clocks. This avoids problems where the constants don't match the setup and things like the UARTs don't get the right baud rate constants. It also automatically sets the FLASH wait states based on the data sheet. I did consider making the FLASH wait state value a parameter so that it is completely general purpose at all voltages for HSI.