mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/mbed_overrides.c@527:74d34ce5a2b5, 2015-04-28 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Apr 28 22:45:18 2015 +0100
- Revision:
- 527:74d34ce5a2b5
- Parent:
- 525:c320967f86b9
- Child:
- 548:1abac31e188e
Synchronized with git revision 55891732d461662a2320cd6f0918ba66e7864ae9
Full URL: https://github.com/mbedmicro/mbed/commit/55891732d461662a2320cd6f0918ba66e7864ae9/
[Silicon Labs] Fix a bug preventing LEUART from being clocked correctly
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 | 525:c320967f86b9 | 37 | CMU_ClockSelectSet(cmuClock_HF, HFXO); |
mbed_official | 525:c320967f86b9 | 38 | SystemHFXOClockSet(HFXO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 39 | #elif( CORE_CLOCK_SOURCE == HFRCO) |
mbed_official | 525:c320967f86b9 | 40 | CMU_ClockSelectSet(cmuClock_HF, HFRCO); |
mbed_official | 525:c320967f86b9 | 41 | CMU_HFRCOBandSet(HFRCO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 42 | #else |
mbed_official | 525:c320967f86b9 | 43 | #error "Core clock selection not valid (mbed_overrides.c)" |
mbed_official | 525:c320967f86b9 | 44 | #endif |
mbed_official | 525:c320967f86b9 | 45 | |
mbed_official | 525:c320967f86b9 | 46 | CMU_ClockEnable(cmuClock_CORELE, true); |
mbed_official | 525:c320967f86b9 | 47 | |
mbed_official | 525:c320967f86b9 | 48 | #if( LOW_ENERGY_CLOCK_SOURCE == LFXO ) |
mbed_official | 525:c320967f86b9 | 49 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 525:c320967f86b9 | 50 | CMU_ClockSelectSet(cmuClock_LFA, LFXO); |
mbed_official | 525:c320967f86b9 | 51 | #endif |
mbed_official | 525:c320967f86b9 | 52 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 527:74d34ce5a2b5 | 53 | /* cmuClock_LFB (to date) only has LEUART peripherals. |
mbed_official | 527:74d34ce5a2b5 | 54 | * Do NOT set it up here, as LEUARTs might have been initialized |
mbed_official | 527:74d34ce5a2b5 | 55 | * before this code is called. (Limitation of the override mechanism of ARMCC) |
mbed_official | 527:74d34ce5a2b5 | 56 | */ |
mbed_official | 527:74d34ce5a2b5 | 57 | //TODO: Look for a more elegant fix. |
mbed_official | 527:74d34ce5a2b5 | 58 | //CMU_ClockSelectSet(cmuClock_LFB, LFXO); |
mbed_official | 525:c320967f86b9 | 59 | #endif |
mbed_official | 525:c320967f86b9 | 60 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 525:c320967f86b9 | 61 | CMU_ClockSelectSet(cmuClock_LFE, LFXO); |
mbed_official | 525:c320967f86b9 | 62 | #endif |
mbed_official | 525:c320967f86b9 | 63 | SystemLFXOClockSet(LFXO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 64 | |
mbed_official | 525:c320967f86b9 | 65 | #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO ) |
mbed_official | 525:c320967f86b9 | 66 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 525:c320967f86b9 | 67 | CMU_ClockSelectSet(cmuClock_LFA, LFRCO); |
mbed_official | 525:c320967f86b9 | 68 | #endif |
mbed_official | 525:c320967f86b9 | 69 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 525:c320967f86b9 | 70 | //CMU_ClockSelectSet(cmuClock_LFB, LFRCO); |
mbed_official | 525:c320967f86b9 | 71 | #endif |
mbed_official | 525:c320967f86b9 | 72 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 525:c320967f86b9 | 73 | CMU_ClockSelectSet(cmuClock_LFE, LFRCO); |
mbed_official | 525:c320967f86b9 | 74 | #endif |
mbed_official | 525:c320967f86b9 | 75 | CMU_HFRCOBandSet(HFRCO_FREQUENCY); |
mbed_official | 525:c320967f86b9 | 76 | |
mbed_official | 525:c320967f86b9 | 77 | #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO) |
mbed_official | 525:c320967f86b9 | 78 | #ifdef CMU_LFACLKSEL_REG |
mbed_official | 525:c320967f86b9 | 79 | CMU_ClockSelectSet(cmuClock_LFA, ULFRCO); |
mbed_official | 525:c320967f86b9 | 80 | #endif |
mbed_official | 525:c320967f86b9 | 81 | #ifdef CMU_LFBCLKSEL_REG |
mbed_official | 525:c320967f86b9 | 82 | CMU_ClockSelectSet(cmuClock_LFB, ULFRCO); |
mbed_official | 525:c320967f86b9 | 83 | #endif |
mbed_official | 525:c320967f86b9 | 84 | #ifdef CMU_LFECLKSEL_REG |
mbed_official | 525:c320967f86b9 | 85 | CMU_ClockSelectSet(cmuClock_LFE, ULFRCO); |
mbed_official | 525:c320967f86b9 | 86 | #endif |
mbed_official | 525:c320967f86b9 | 87 | #else |
mbed_official | 525:c320967f86b9 | 88 | #error "Low energy clock selection not valid" |
mbed_official | 525:c320967f86b9 | 89 | #endif |
mbed_official | 525:c320967f86b9 | 90 | |
mbed_official | 525:c320967f86b9 | 91 | /* Enable BC line driver to avoid garbage on CDC port */ |
mbed_official | 525:c320967f86b9 | 92 | gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1); |
mbed_official | 525:c320967f86b9 | 93 | } |
mbed_official | 525:c320967f86b9 | 94 | |
mbed_official | 525:c320967f86b9 | 95 | void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask) { |
mbed_official | 525:c320967f86b9 | 96 | uint32_t freq = 14000000, baudrate; |
mbed_official | 525:c320967f86b9 | 97 | USART_OVS_TypeDef ovs; |
mbed_official | 525:c320967f86b9 | 98 | |
mbed_official | 525:c320967f86b9 | 99 | if(CMU->HFPERCLKEN0 & clockmask) { |
mbed_official | 525:c320967f86b9 | 100 | /* Different methods for sync vs async */ |
mbed_official | 525:c320967f86b9 | 101 | if(usart->CTRL & USART_CTRL_SYNC) { |
mbed_official | 525:c320967f86b9 | 102 | ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK); |
mbed_official | 525:c320967f86b9 | 103 | baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs); |
mbed_official | 525:c320967f86b9 | 104 | USART_BaudrateSyncSet(usart, 0, baudrate); |
mbed_official | 525:c320967f86b9 | 105 | } else { |
mbed_official | 525:c320967f86b9 | 106 | ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK); |
mbed_official | 525:c320967f86b9 | 107 | baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs); |
mbed_official | 525:c320967f86b9 | 108 | USART_BaudrateAsyncSet(usart, 0, baudrate, ovs); |
mbed_official | 525:c320967f86b9 | 109 | } |
mbed_official | 525:c320967f86b9 | 110 | } |
mbed_official | 525:c320967f86b9 | 111 | } |