I don't know

Dependents:   MX106-finaltest

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Sep 25 14:15:10 2015 +0100
Revision:
627:4fa1328d9c60
Parent:
608:14dd4108b341
Synchronized with git revision fe238a91ab7a4d1d72c4cab9da04967c619d54ad

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

Silicon Labs - Add support for low-power async Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 627:4fa1328d9c60 1 /***************************************************************************//**
mbed_official 627:4fa1328d9c60 2 * @file mbed_overrides.c
mbed_official 627:4fa1328d9c60 3 *******************************************************************************
mbed_official 627:4fa1328d9c60 4 * @section License
mbed_official 627:4fa1328d9c60 5 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
mbed_official 627:4fa1328d9c60 6 *******************************************************************************
mbed_official 525:c320967f86b9 7 *
mbed_official 627:4fa1328d9c60 8 * Permission is granted to anyone to use this software for any purpose,
mbed_official 627:4fa1328d9c60 9 * including commercial applications, and to alter it and redistribute it
mbed_official 627:4fa1328d9c60 10 * freely, subject to the following restrictions:
mbed_official 525:c320967f86b9 11 *
mbed_official 627:4fa1328d9c60 12 * 1. The origin of this software must not be misrepresented; you must not
mbed_official 627:4fa1328d9c60 13 * claim that you wrote the original software.
mbed_official 627:4fa1328d9c60 14 * 2. Altered source versions must be plainly marked as such, and must not be
mbed_official 627:4fa1328d9c60 15 * misrepresented as being the original software.
mbed_official 627:4fa1328d9c60 16 * 3. This notice may not be removed or altered from any source distribution.
mbed_official 525:c320967f86b9 17 *
mbed_official 627:4fa1328d9c60 18 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
mbed_official 627:4fa1328d9c60 19 * obligation to support this Software. Silicon Labs is providing the
mbed_official 627:4fa1328d9c60 20 * Software "AS IS", with no express or implied warranties of any kind,
mbed_official 627:4fa1328d9c60 21 * including, but not limited to, any implied warranties of merchantability
mbed_official 627:4fa1328d9c60 22 * or fitness for any particular purpose or warranties against infringement
mbed_official 627:4fa1328d9c60 23 * of any proprietary rights of a third party.
mbed_official 627:4fa1328d9c60 24 *
mbed_official 627:4fa1328d9c60 25 * Silicon Labs will not be liable for any consequential, incidental, or
mbed_official 627:4fa1328d9c60 26 * special damages, or any other relief, or for any claim by any third party,
mbed_official 627:4fa1328d9c60 27 * arising from your use of this Software.
mbed_official 627:4fa1328d9c60 28 *
mbed_official 627:4fa1328d9c60 29 ******************************************************************************/
mbed_official 627:4fa1328d9c60 30
mbed_official 525:c320967f86b9 31 #include "em_chip.h"
mbed_official 525:c320967f86b9 32 #include "em_device.h"
mbed_official 525:c320967f86b9 33 #include "em_cmu.h"
mbed_official 525:c320967f86b9 34 #include "em_emu.h"
mbed_official 525:c320967f86b9 35 #include "device_peripherals.h"
mbed_official 525:c320967f86b9 36 #include "device.h"
mbed_official 525:c320967f86b9 37 #include "em_usart.h"
mbed_official 525:c320967f86b9 38 #include "gpio_api.h"
mbed_official 525:c320967f86b9 39
mbed_official 525:c320967f86b9 40 gpio_t bc_enable;
mbed_official 525:c320967f86b9 41
mbed_official 525:c320967f86b9 42 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask);
mbed_official 525:c320967f86b9 43
mbed_official 525:c320967f86b9 44 /* Called before main - implement here if board needs it.
mbed_official 525:c320967f86b9 45 * Otherwise, let the application override this if necessary */
mbed_official 525:c320967f86b9 46 void mbed_sdk_init()
mbed_official 525:c320967f86b9 47 {
mbed_official 525:c320967f86b9 48 CHIP_Init();
mbed_official 525:c320967f86b9 49
mbed_official 525:c320967f86b9 50 /* Set up the clock sources for this chip */
mbed_official 525:c320967f86b9 51 #if( CORE_CLOCK_SOURCE == HFXO)
mbed_official 608:14dd4108b341 52 CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
mbed_official 525:c320967f86b9 53 SystemHFXOClockSet(HFXO_FREQUENCY);
mbed_official 525:c320967f86b9 54 #elif( CORE_CLOCK_SOURCE == HFRCO)
mbed_official 608:14dd4108b341 55 CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
mbed_official 525:c320967f86b9 56 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
mbed_official 525:c320967f86b9 57 #else
mbed_official 525:c320967f86b9 58 #error "Core clock selection not valid (mbed_overrides.c)"
mbed_official 525:c320967f86b9 59 #endif
mbed_official 525:c320967f86b9 60
mbed_official 525:c320967f86b9 61 CMU_ClockEnable(cmuClock_CORELE, true);
mbed_official 525:c320967f86b9 62
mbed_official 525:c320967f86b9 63 #if( LOW_ENERGY_CLOCK_SOURCE == LFXO )
mbed_official 525:c320967f86b9 64 #ifdef CMU_LFACLKSEL_REG
mbed_official 608:14dd4108b341 65 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
mbed_official 525:c320967f86b9 66 #endif
mbed_official 525:c320967f86b9 67 #ifdef CMU_LFBCLKSEL_REG
mbed_official 548:1abac31e188e 68 /* cmuClock_LFB (to date) only has LEUART peripherals.
mbed_official 627:4fa1328d9c60 69 * This gets set automatically whenever you create serial objects using LEUART
mbed_official 548:1abac31e188e 70 */
mbed_official 525:c320967f86b9 71 #endif
mbed_official 525:c320967f86b9 72 #ifdef CMU_LFECLKSEL_REG
mbed_official 608:14dd4108b341 73 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFXO);
mbed_official 525:c320967f86b9 74 #endif
mbed_official 525:c320967f86b9 75 SystemLFXOClockSet(LFXO_FREQUENCY);
mbed_official 525:c320967f86b9 76
mbed_official 525:c320967f86b9 77 #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO )
mbed_official 525:c320967f86b9 78 #ifdef CMU_LFACLKSEL_REG
mbed_official 608:14dd4108b341 79 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
mbed_official 525:c320967f86b9 80 #endif
mbed_official 525:c320967f86b9 81 #ifdef CMU_LFBCLKSEL_REG
mbed_official 627:4fa1328d9c60 82 //CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFRCO);
mbed_official 525:c320967f86b9 83 #endif
mbed_official 525:c320967f86b9 84 #ifdef CMU_LFECLKSEL_REG
mbed_official 608:14dd4108b341 85 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO);
mbed_official 525:c320967f86b9 86 #endif
mbed_official 525:c320967f86b9 87 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
mbed_official 525:c320967f86b9 88
mbed_official 525:c320967f86b9 89 #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO)
mbed_official 525:c320967f86b9 90 #ifdef CMU_LFACLKSEL_REG
mbed_official 608:14dd4108b341 91 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
mbed_official 525:c320967f86b9 92 #endif
mbed_official 525:c320967f86b9 93 #ifdef CMU_LFBCLKSEL_REG
mbed_official 608:14dd4108b341 94 CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_ULFRCO);
mbed_official 525:c320967f86b9 95 #endif
mbed_official 525:c320967f86b9 96 #ifdef CMU_LFECLKSEL_REG
mbed_official 608:14dd4108b341 97 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_ULFRCO);
mbed_official 525:c320967f86b9 98 #endif
mbed_official 525:c320967f86b9 99 #else
mbed_official 525:c320967f86b9 100 #error "Low energy clock selection not valid"
mbed_official 525:c320967f86b9 101 #endif
mbed_official 525:c320967f86b9 102
mbed_official 525:c320967f86b9 103 /* Enable BC line driver to avoid garbage on CDC port */
mbed_official 525:c320967f86b9 104 gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1);
mbed_official 525:c320967f86b9 105 }
mbed_official 525:c320967f86b9 106
mbed_official 548:1abac31e188e 107 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask)
mbed_official 548:1abac31e188e 108 {
mbed_official 525:c320967f86b9 109 uint32_t freq = 14000000, baudrate;
mbed_official 525:c320967f86b9 110 USART_OVS_TypeDef ovs;
mbed_official 525:c320967f86b9 111
mbed_official 525:c320967f86b9 112 if(CMU->HFPERCLKEN0 & clockmask) {
mbed_official 525:c320967f86b9 113 /* Different methods for sync vs async */
mbed_official 525:c320967f86b9 114 if(usart->CTRL & USART_CTRL_SYNC) {
mbed_official 525:c320967f86b9 115 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 116 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs);
mbed_official 525:c320967f86b9 117 USART_BaudrateSyncSet(usart, 0, baudrate);
mbed_official 525:c320967f86b9 118 } else {
mbed_official 525:c320967f86b9 119 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 120 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs);
mbed_official 525:c320967f86b9 121 USART_BaudrateAsyncSet(usart, 0, baudrate, ovs);
mbed_official 525:c320967f86b9 122 }
mbed_official 525:c320967f86b9 123 }
mbed_official 525:c320967f86b9 124 }