Skip to content

Commit 967509d

Browse files
committed
[NUCLEO_F103RB] Add sleep
1 parent 956064b commit 967509d

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#define DEVICE_PWMOUT 1
3939

40-
#define DEVICE_SLEEP 0
40+
#define DEVICE_SLEEP 1
4141

4242
//=======================================
4343

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ static void handle_interrupt_in(uint32_t channel) {
3838
{
3939
EXTI_ClearITPendingBit(exti_line);
4040
}
41-
// Check if it's a rising or a falling event
42-
if (EXTI->RTSR & (uint32_t)(1 << channel)) {
43-
irq_handler(channel_ids[channel], IRQ_RISE);
41+
42+
// Warning:
43+
// On this device we don't know if a rising or falling event occured.
44+
// In case both rise and fall events are set, only the FALL event will be reported.
45+
if (EXTI->FTSR & (uint32_t)(1 << channel)) {
46+
irq_handler(channel_ids[channel], IRQ_FALL);
4447
}
4548
else {
46-
irq_handler(channel_ids[channel], IRQ_FALL);
49+
irq_handler(channel_ids[channel], IRQ_RISE);
4750
}
4851
}
4952

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "sleep_api.h"
17+
#include "cmsis.h"
18+
19+
static void SYSCLKConfig_STOP(void)
20+
{
21+
ErrorStatus HSEStartUpStatus;
22+
23+
RCC_HSEConfig(RCC_HSE_ON); // Enable HSE
24+
25+
HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready
26+
27+
if (HSEStartUpStatus == SUCCESS) {
28+
RCC_PLLCmd(ENABLE); // Enable PLL
29+
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} // Wait till PLL is ready
30+
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
31+
while(RCC_GetSYSCLKSource() != 0x08) {} // Wait till PLL is used as system clock source
32+
}
33+
}
34+
35+
void sleep(void)
36+
{
37+
SCB->SCR = 0; // Normal sleep mode for ARM core
38+
__WFI();
39+
}
40+
41+
void deepsleep(void)
42+
{
43+
// Enable PWR clock
44+
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
45+
46+
// Request to enter STOP mode with regulator in low power mode
47+
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
48+
49+
// At this stage the system has resumed from STOP mode.
50+
// Re-configure the system clock: enable HSE, PLL and select
51+
// PLL as system clock source (because HSE and PLL are disabled in STOP mode).
52+
SYSCLKConfig_STOP();
53+
}

0 commit comments

Comments
 (0)