mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Mon Jan 13 10:45:05 2014 +0000
Revision:
72:248c61396e08
Child:
74:847f030b50ee
Synchronized with git revision f1904ba15c06215a7530efd2d5a16c25af9d29ff

Full URL: https://github.com/mbedmicro/mbed/commit/f1904ba15c06215a7530efd2d5a16c25af9d29ff/

KL46Z: Added Sleep, LED3 and LED4 definitions, switches

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 72:248c61396e08 1 /* mbed Microcontroller Library
mbed_official 72:248c61396e08 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 72:248c61396e08 3 *
mbed_official 72:248c61396e08 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 72:248c61396e08 5 * you may not use this file except in compliance with the License.
mbed_official 72:248c61396e08 6 * You may obtain a copy of the License at
mbed_official 72:248c61396e08 7 *
mbed_official 72:248c61396e08 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 72:248c61396e08 9 *
mbed_official 72:248c61396e08 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 72:248c61396e08 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 72:248c61396e08 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 72:248c61396e08 13 * See the License for the specific language governing permissions and
mbed_official 72:248c61396e08 14 * limitations under the License.
mbed_official 72:248c61396e08 15 */
mbed_official 72:248c61396e08 16 #ifndef MBED_CLK_FREQS_H
mbed_official 72:248c61396e08 17 #define MBED_CLK_FREQS_H
mbed_official 72:248c61396e08 18
mbed_official 72:248c61396e08 19 #ifdef __cplusplus
mbed_official 72:248c61396e08 20 extern "C" {
mbed_official 72:248c61396e08 21 #endif
mbed_official 72:248c61396e08 22
mbed_official 72:248c61396e08 23 //Get the peripheral bus clock frequency
mbed_official 72:248c61396e08 24 static inline uint32_t bus_frequency(void) {
mbed_official 72:248c61396e08 25 return SystemCoreClock / (((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV4_MASK) >> SIM_CLKDIV1_OUTDIV4_SHIFT) + 1);
mbed_official 72:248c61396e08 26 }
mbed_official 72:248c61396e08 27
mbed_official 72:248c61396e08 28 //Get external oscillator (crystal) frequency
mbed_official 72:248c61396e08 29 static uint32_t extosc_frequency(void) {
mbed_official 72:248c61396e08 30 uint32_t MCGClock = SystemCoreClock * (1u + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV1_MASK) >> SIM_CLKDIV1_OUTDIV1_SHIFT));
mbed_official 72:248c61396e08 31
mbed_official 72:248c61396e08 32 if ((MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(2)) //MCG clock = external reference clock
mbed_official 72:248c61396e08 33 return MCGClock;
mbed_official 72:248c61396e08 34
mbed_official 72:248c61396e08 35 if ((MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(0)) { //PLL/FLL is selected
mbed_official 72:248c61396e08 36 uint32_t divider, multiplier;
mbed_official 72:248c61396e08 37 if ((MCG->C6 & MCG_C6_PLLS_MASK) == 0x0u) { //FLL is selected
mbed_official 72:248c61396e08 38 if ((MCG->S & MCG_S_IREFST_MASK) == 0x0u) { //FLL uses external reference
mbed_official 72:248c61396e08 39 divider = (uint8_t)(1u << ((MCG->C1 & MCG_C1_FRDIV_MASK) >> MCG_C1_FRDIV_SHIFT));
mbed_official 72:248c61396e08 40 if ((MCG->C2 & MCG_C2_RANGE0_MASK) != 0x0u)
mbed_official 72:248c61396e08 41 divider <<= 5u;
mbed_official 72:248c61396e08 42 /* Select correct multiplier to calculate the MCG output clock */
mbed_official 72:248c61396e08 43 switch (MCG->C4 & (MCG_C4_DMX32_MASK | MCG_C4_DRST_DRS_MASK)) {
mbed_official 72:248c61396e08 44 case 0x0u:
mbed_official 72:248c61396e08 45 multiplier = 640u;
mbed_official 72:248c61396e08 46 break;
mbed_official 72:248c61396e08 47 case 0x20u:
mbed_official 72:248c61396e08 48 multiplier = 1280u;
mbed_official 72:248c61396e08 49 break;
mbed_official 72:248c61396e08 50 case 0x40u:
mbed_official 72:248c61396e08 51 multiplier = 1920u;
mbed_official 72:248c61396e08 52 break;
mbed_official 72:248c61396e08 53 case 0x60u:
mbed_official 72:248c61396e08 54 multiplier = 2560u;
mbed_official 72:248c61396e08 55 break;
mbed_official 72:248c61396e08 56 case 0x80u:
mbed_official 72:248c61396e08 57 multiplier = 732u;
mbed_official 72:248c61396e08 58 break;
mbed_official 72:248c61396e08 59 case 0xA0u:
mbed_official 72:248c61396e08 60 multiplier = 1464u;
mbed_official 72:248c61396e08 61 break;
mbed_official 72:248c61396e08 62 case 0xC0u:
mbed_official 72:248c61396e08 63 multiplier = 2197u;
mbed_official 72:248c61396e08 64 break;
mbed_official 72:248c61396e08 65 case 0xE0u:
mbed_official 72:248c61396e08 66 default:
mbed_official 72:248c61396e08 67 multiplier = 2929u;
mbed_official 72:248c61396e08 68 break;
mbed_official 72:248c61396e08 69 }
mbed_official 72:248c61396e08 70
mbed_official 72:248c61396e08 71 return MCGClock * divider / multiplier;
mbed_official 72:248c61396e08 72 }
mbed_official 72:248c61396e08 73 } else { //PLL is selected
mbed_official 72:248c61396e08 74 divider = (1u + (MCG->C5 & MCG_C5_PRDIV0_MASK));
mbed_official 72:248c61396e08 75 multiplier = ((MCG->C6 & MCG_C6_VDIV0_MASK) + 24u);
mbed_official 72:248c61396e08 76 return MCGClock * divider / multiplier;
mbed_official 72:248c61396e08 77 }
mbed_official 72:248c61396e08 78 }
mbed_official 72:248c61396e08 79
mbed_official 72:248c61396e08 80 //In all other cases either there is no crystal or we cannot determine it
mbed_official 72:248c61396e08 81 //For example when the FLL is running on the internal reference, and there is also an
mbed_official 72:248c61396e08 82 //external crystal. However these are unlikely situations
mbed_official 72:248c61396e08 83 return 0;
mbed_official 72:248c61396e08 84 }
mbed_official 72:248c61396e08 85
mbed_official 72:248c61396e08 86
mbed_official 72:248c61396e08 87 #ifdef __cplusplus
mbed_official 72:248c61396e08 88 }
mbed_official 72:248c61396e08 89 #endif
mbed_official 72:248c61396e08 90
mbed_official 72:248c61396e08 91 #endif