mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
469:fc4922e0c183
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 469:fc4922e0c183 1 /* mbed Microcontroller Library
mbed_official 469:fc4922e0c183 2 *******************************************************************************
mbed_official 630:825f75ca301e 3 * Copyright (c) 2015, STMicroelectronics
mbed_official 469:fc4922e0c183 4 * All rights reserved.
mbed_official 469:fc4922e0c183 5 *
mbed_official 469:fc4922e0c183 6 * Redistribution and use in source and binary forms, with or without
mbed_official 469:fc4922e0c183 7 * modification, are permitted provided that the following conditions are met:
mbed_official 469:fc4922e0c183 8 *
mbed_official 469:fc4922e0c183 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 469:fc4922e0c183 10 * this list of conditions and the following disclaimer.
mbed_official 469:fc4922e0c183 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 469:fc4922e0c183 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 469:fc4922e0c183 13 * and/or other materials provided with the distribution.
mbed_official 469:fc4922e0c183 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 469:fc4922e0c183 15 * may be used to endorse or promote products derived from this software
mbed_official 469:fc4922e0c183 16 * without specific prior written permission.
mbed_official 469:fc4922e0c183 17 *
mbed_official 469:fc4922e0c183 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 469:fc4922e0c183 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 469:fc4922e0c183 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 469:fc4922e0c183 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 469:fc4922e0c183 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 469:fc4922e0c183 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 469:fc4922e0c183 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 469:fc4922e0c183 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 469:fc4922e0c183 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 469:fc4922e0c183 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 469:fc4922e0c183 28 *******************************************************************************
mbed_official 469:fc4922e0c183 29 */
mbed_official 469:fc4922e0c183 30 #include "sleep_api.h"
mbed_official 469:fc4922e0c183 31
mbed_official 469:fc4922e0c183 32 #if DEVICE_SLEEP
mbed_official 469:fc4922e0c183 33
mbed_official 469:fc4922e0c183 34 #include "cmsis.h"
mbed_official 469:fc4922e0c183 35
mbed_official 469:fc4922e0c183 36 #if defined(TARGET_STM32F070RB)
mbed_official 630:825f75ca301e 37 void sleep(void) {
mbed_official 469:fc4922e0c183 38 TIM_HandleTypeDef TimMasterHandle;
mbed_official 469:fc4922e0c183 39
mbed_official 469:fc4922e0c183 40 TimMasterHandle.Instance = TIM1;
mbed_official 469:fc4922e0c183 41
mbed_official 469:fc4922e0c183 42 // Disable HAL tick and us_ticker update interrupts
mbed_official 469:fc4922e0c183 43 __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
mbed_official 469:fc4922e0c183 44
mbed_official 469:fc4922e0c183 45 // Request to enter SLEEP mode
mbed_official 469:fc4922e0c183 46 HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
mbed_official 469:fc4922e0c183 47
mbed_official 469:fc4922e0c183 48 // Enable HAL tick and us_ticker update interrupts
mbed_official 469:fc4922e0c183 49 __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE));
mbed_official 469:fc4922e0c183 50 }
mbed_official 469:fc4922e0c183 51
mbed_official 469:fc4922e0c183 52 #elif defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
mbed_official 630:825f75ca301e 53 void sleep(void) {
mbed_official 469:fc4922e0c183 54 // Stop HAL systick
mbed_official 469:fc4922e0c183 55 HAL_SuspendTick();
mbed_official 469:fc4922e0c183 56 // Request to enter SLEEP mode
mbed_official 469:fc4922e0c183 57 HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
mbed_official 469:fc4922e0c183 58 // Restart HAL systick
mbed_official 469:fc4922e0c183 59 HAL_ResumeTick();
mbed_official 469:fc4922e0c183 60 }
mbed_official 469:fc4922e0c183 61
mbed_official 469:fc4922e0c183 62 #else
mbed_official 469:fc4922e0c183 63 static TIM_HandleTypeDef TimMasterHandle;
mbed_official 469:fc4922e0c183 64
mbed_official 630:825f75ca301e 65 void sleep(void) {
mbed_official 469:fc4922e0c183 66 TimMasterHandle.Instance = TIM2;
mbed_official 469:fc4922e0c183 67
mbed_official 469:fc4922e0c183 68 // Disable HAL tick interrupt
mbed_official 469:fc4922e0c183 69 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
mbed_official 469:fc4922e0c183 70
mbed_official 469:fc4922e0c183 71 // Request to enter SLEEP mode
mbed_official 469:fc4922e0c183 72 HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
mbed_official 469:fc4922e0c183 73
mbed_official 469:fc4922e0c183 74 // Enable HAL tick interrupt
mbed_official 469:fc4922e0c183 75 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
mbed_official 469:fc4922e0c183 76 }
mbed_official 469:fc4922e0c183 77 #endif
mbed_official 469:fc4922e0c183 78
mbed_official 469:fc4922e0c183 79 #if defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
mbed_official 630:825f75ca301e 80 void deepsleep(void) {
mbed_official 469:fc4922e0c183 81 // Request to enter STOP mode with regulator in low power mode
mbed_official 469:fc4922e0c183 82 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
mbed_official 469:fc4922e0c183 83
mbed_official 469:fc4922e0c183 84 HAL_InitTick(TICK_INT_PRIORITY);
mbed_official 469:fc4922e0c183 85
mbed_official 469:fc4922e0c183 86 // After wake-up from STOP reconfigure the PLL
mbed_official 469:fc4922e0c183 87 SetSysClock();
mbed_official 469:fc4922e0c183 88
mbed_official 469:fc4922e0c183 89 HAL_InitTick(TICK_INT_PRIORITY);
mbed_official 469:fc4922e0c183 90 }
mbed_official 469:fc4922e0c183 91
mbed_official 469:fc4922e0c183 92 #else
mbed_official 630:825f75ca301e 93 void deepsleep(void) {
mbed_official 469:fc4922e0c183 94 // Request to enter STOP mode with regulator in low power mode
mbed_official 469:fc4922e0c183 95 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
mbed_official 469:fc4922e0c183 96
mbed_official 469:fc4922e0c183 97 // After wake-up from STOP reconfigure the PLL
mbed_official 469:fc4922e0c183 98 SetSysClock();
mbed_official 469:fc4922e0c183 99 }
mbed_official 469:fc4922e0c183 100 #endif
mbed_official 469:fc4922e0c183 101
mbed_official 469:fc4922e0c183 102 #endif