I don't know
Fork of mbed-src by
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/mbed_overrides.c@608:14dd4108b341, 2015-08-14 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Aug 14 08:45:08 2015 +0100
- Revision:
- 608:14dd4108b341
- Parent:
- 548:1abac31e188e
- Child:
- 627:4fa1328d9c60
Synchronized with git revision 77a08517db34a83c9b5478adf089e5a641797b2a
Full URL: https://github.com/mbedmicro/mbed/commit/77a08517db34a83c9b5478adf089e5a641797b2a/
[Silicon Labs] Fix incorrect clock selection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 525:c320967f86b9 | 1 | /* mbed Microcontroller Library |
mbed_official | 525:c320967f86b9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 525:c320967f86b9 | 3 | * |
mbed_official | 525:c320967f86b9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 525:c320967f86b9 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 525:c320967f86b9 | 6 | * You may obtain a copy of the License at |
mbed_official | 525:c320967f86b9 | 7 | * |
mbed_official | 525:c320967f86b9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 525:c320967f86b9 | 9 | * |
mbed_official | 525:c320967f86b9 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 525:c320967f86b9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 525:c320967f86b9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 525:c320967f86b9 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 525:c320967f86b9 | 14 | * limitations under the License. |
mbed_official | 525:c320967f86b9 | 15 | */ |
mbed_official | 525:c320967f86b9 | 16 | #include "em_chip.h" |
mbed_official | 525:c320967f86b9 | 17 | #include "em_device.h" |
mbed_official | 525:c320967f86b9 | 18 | #include "em_cmu.h" |
mbed_official | 525:c320967f86b9 | 19 | #include "em_emu.h" |
mbed_official | 525:c320967f86b9 | 20 | #include "device_peripherals.h" |
mbed_official | 525:c320967f86b9 | 21 | #include "device.h" |
mbed_official | 525:c320967f86b9 | 22 | #include "em_usart.h" |
mbed_official | 525:c320967f86b9 | 23 | #include "gpio_api.h" |
mbed_official | 525:c320967f86b9 | 24 | |
mbed_official | 525:c320967f86b9 | 25 | gpio_t bc_enable; |
mbed_official | 525:c320967f86b9 | 26 | |
mbed_official | 525:c320967f86b9 | 27 | void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask); |
mbed_official | 525:c320967f86b9 | 28 | |
mbed_official | 525:c320967f86b9 | 29 | /* Called before main - implement here if board needs it. |
mbed_official | 525:c320967f86b9 | 30 | * Otherwise, let the application override this if necessary */ |
mbed_official | 525:c320967f86b9 | 31 | void mbed_sdk_init() |
mbed_official | 525:c320967f86b9 | 32 | { |
mbed_official | 525:c320967f86b9 | 33 | CHIP_Init(); |
mbed_official | 525:c320967f86b9 | 34 | |
mbed_official | 525:c320967f86b9 | 35 | /* Set up the clock sources for this chip */ |
mbed_official | 525:c320967f86b9 | 36 | #if( CORE_CLOCK_SOURCE == HFXO) |
mbed_official | 608:14dd4108b341 | 37 | CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); |
mbed_official | 608:14dd4108b341 | 38 | CMU_ClockSelectSet(cmuClock_HFPER, cmuSelect_HFXO); |
mbed_official | 525:c320967f86b9 | 39 | SystemHFXOClockSet(HFXO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 40 | #elif( CORE_CLOCK_SOURCE == HFRCO) |
mbed_official | 608:14dd4108b341 | 41 | CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO); |
mbed_official | 608:14dd4108b341 | 42 | CMU_ClockSelectSet(cmuClock_HFPER, cmuSelect_HFRCO); |
mbed_official | 525:c320967f86b9 | 43 | CMU_HFRCOBandSet(HFRCO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 44 | #else |
mbed_official | 525:c320967f86b9 | 45 | #error "Core clock selection not valid (mbed_overrides.c)" |
mbed_official | 525:c320967f86b9 | 46 | #endif |
mbed_official | 525:c320967f86b9 | 47 | |
mbed_official | 525:c320967f86b9 | 48 | CMU_ClockEnable(cmuClock_CORELE, true); |
mbed_official | 525:c320967f86b9 | 49 | |
mbed_official | 525:c320967f86b9 | 50 | #if( LOW_ENERGY_CLOCK_SOURCE == LFXO ) |
mbed_official | 525:c320967f86b9 | 51 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 608:14dd4108b341 | 52 | CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO); |
mbed_official | 525:c320967f86b9 | 53 | #endif |
mbed_official | 525:c320967f86b9 | 54 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 548:1abac31e188e | 55 | /* cmuClock_LFB (to date) only has LEUART peripherals. |
mbed_official | 548:1abac31e188e | 56 | * Do NOT set it up here, as LEUARTs might have been initialized |
mbed_official | 548:1abac31e188e | 57 | * before this code is called. (Limitation of the override mechanism of ARMCC) |
mbed_official | 548:1abac31e188e | 58 | */ |
mbed_official | 548:1abac31e188e | 59 | //TODO: Look for a more elegant fix. |
mbed_official | 527:74d34ce5a2b5 | 60 | //CMU_ClockSelectSet(cmuClock_LFB, LFXO); |
mbed_official | 525:c320967f86b9 | 61 | #endif |
mbed_official | 525:c320967f86b9 | 62 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 608:14dd4108b341 | 63 | CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFXO); |
mbed_official | 525:c320967f86b9 | 64 | #endif |
mbed_official | 525:c320967f86b9 | 65 | SystemLFXOClockSet(LFXO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 66 | |
mbed_official | 525:c320967f86b9 | 67 | #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO ) |
mbed_official | 525:c320967f86b9 | 68 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 608:14dd4108b341 | 69 | CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO); |
mbed_official | 525:c320967f86b9 | 70 | #endif |
mbed_official | 525:c320967f86b9 | 71 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 525:c320967f86b9 | 72 | //CMU_ClockSelectSet(cmuClock_LFB, LFRCO); |
mbed_official | 525:c320967f86b9 | 73 | #endif |
mbed_official | 525:c320967f86b9 | 74 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 608:14dd4108b341 | 75 | CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO); |
mbed_official | 525:c320967f86b9 | 76 | #endif |
mbed_official | 525:c320967f86b9 | 77 | CMU_HFRCOBandSet(HFRCO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 78 | |
mbed_official | 525:c320967f86b9 | 79 | #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO) |
mbed_official | 525:c320967f86b9 | 80 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 608:14dd4108b341 | 81 | CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO); |
mbed_official | 525:c320967f86b9 | 82 | #endif |
mbed_official | 525:c320967f86b9 | 83 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 608:14dd4108b341 | 84 | CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_ULFRCO); |
mbed_official | 525:c320967f86b9 | 85 | #endif |
mbed_official | 525:c320967f86b9 | 86 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 608:14dd4108b341 | 87 | CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_ULFRCO); |
mbed_official | 525:c320967f86b9 | 88 | #endif |
mbed_official | 525:c320967f86b9 | 89 | #else |
mbed_official | 525:c320967f86b9 | 90 | #error "Low energy clock selection not valid" |
mbed_official | 525:c320967f86b9 | 91 | #endif |
mbed_official | 525:c320967f86b9 | 92 | |
mbed_official | 525:c320967f86b9 | 93 | /* Enable BC line driver to avoid garbage on CDC port */ |
mbed_official | 525:c320967f86b9 | 94 | gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1); |
mbed_official | 525:c320967f86b9 | 95 | } |
mbed_official | 525:c320967f86b9 | 96 | |
mbed_official | 548:1abac31e188e | 97 | void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask) |
mbed_official | 548:1abac31e188e | 98 | { |
mbed_official | 525:c320967f86b9 | 99 | uint32_t freq = 14000000, baudrate; |
mbed_official | 525:c320967f86b9 | 100 | USART_OVS_TypeDef ovs; |
mbed_official | 525:c320967f86b9 | 101 | |
mbed_official | 525:c320967f86b9 | 102 | if(CMU->HFPERCLKEN0 & clockmask) { |
mbed_official | 525:c320967f86b9 | 103 | /* Different methods for sync vs async */ |
mbed_official | 525:c320967f86b9 | 104 | if(usart->CTRL & USART_CTRL_SYNC) { |
mbed_official | 525:c320967f86b9 | 105 | ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK); |
mbed_official | 525:c320967f86b9 | 106 | baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs); |
mbed_official | 525:c320967f86b9 | 107 | USART_BaudrateSyncSet(usart, 0, baudrate); |
mbed_official | 525:c320967f86b9 | 108 | } else { |
mbed_official | 525:c320967f86b9 | 109 | ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK); |
mbed_official | 525:c320967f86b9 | 110 | baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs); |
mbed_official | 525:c320967f86b9 | 111 | USART_BaudrateAsyncSet(usart, 0, baudrate, ovs); |
mbed_official | 525:c320967f86b9 | 112 | } |
mbed_official | 525:c320967f86b9 | 113 | } |
mbed_official | 525:c320967f86b9 | 114 | } |