GlobLib
HAL and API libraries for MCUs and hardware.

This module contains low level functions for power configuration. More...

Files

file  stm32f103cb_power.h
 Header file for stm32f103cb Power.
 

Functions

void POWER_reset (void)
 Resets the system.
 
void POWER_sleep (void)
 Put the system in sleep mode. More...
 
void POWER_noSleep (void)
 Disable sleep mode. More...
 
void POWER_standby (void)
 Put the device into standby mode. More...
 
uint8_t POWER_fromStandby (void)
 Check if the system is restarting from standby mode. More...
 
void POWER_stop (void)
 Put the device into stop mode. More...
 
uint8_t POWER_fromStop (void)
 Check if MCU was in stop mode and reset flags. More...
 

Detailed Description

This module contains low level functions for power configuration.

There are four power modes that the MCU can operate in. Each proceeding mode has a lower power consumption but higher restart time.

This module also contains the hard fault handler. In its implementation, the handler determines if the bootloader is being used (Data register 1 of the backup domain = 1) and resets to boot mode.

If the bootloader is not being used, the system simply stalls.

Author
Stuart Ianna
Version
1.0
Date
July 2018
Warning
None
Bug:
Todo:
Compilers
  • arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Example Usage

This program works over USART_1. It provides four options which can be selected through terminal.

#include <coms128.h>
void data(uint8_t byte);
volatile uint8_t flag;
void callback(void);
void rising(void);
void systemInit(void);
int main(void){
systemInit();
//RTC runs in stop mode
//It only gets set up once
RTC_setup(100);
//Display method of reset
printl("Standby reset");
}
else{
printl("Soft reset");
}
while(1){
switch(flag){
case 1:
flag = 0;
printl("Sleeping, wake on systick ISR");
delayms(100); //Delay for message to print.
SYSTICK_setup(3000000,&callback); //3 seconds
printl("Woke from sleep");
break;
case 2:
flag = 0;
printl("Stoping, wake on EXTI ISR");
delayms(100); //Delay for message to print.
printl("Woke from stop");
break;
case 3:
flag = 0;
printl("Standby, wake after 3 seconds");
delayms(100); //Delay for message to print.
//Standby wakes from RTC alarm
break;
default:
//Do nothing
break;
}
}
}
//Chosse which power mode to use
// 1 = Sleep
// 2 = Stop
// 3 = Standby
// 4 = Reset
void data(uint8_t byte){
switch(byte){
case '1':
flag = 1;
break;
case '2':
flag = 2;
break;
case '3':
flag = 3;
break;
case '4':
break;
default:
//Echo characters
print((char)byte);
break;
}
}
//Systick callback to wake from sleep mode
void callback(void){
//Disable sleep mode
//If not disabled sleep mode begins again after ISR
//Stop the timer
}
//Rising edge on port A pin 0
void rising(void){
systemInit();
}
}
void systemInit(void){
COMS(USART_1);
}

Function Documentation

uint8_t POWER_fromStandby ( void  )

Check if the system is restarting from standby mode.

This should always be used if standby mode is used. This resets the standby wake flags. mode.

Definition at line 99 of file stm32f103cb_power.c.

uint8_t POWER_fromStop ( void  )

Check if MCU was in stop mode and reset flags.

This should always be used if stop mode is used.

Definition at line 84 of file stm32f103cb_power.c.

void POWER_noSleep ( void  )

Disable sleep mode.

This should be called inside an ISR.

Definition at line 59 of file stm32f103cb_power.c.

void POWER_sleep ( void  )

Put the system in sleep mode.

ISR are still enabled. This mode can be exited by calling Power_noSleep() inside an ISR.

Definition at line 53 of file stm32f103cb_power.c.

void POWER_standby ( void  )

Put the device into standby mode.

The RTC must be enabled with an alarm event to exit from standby mode.

Definition at line 65 of file stm32f103cb_power.c.

void POWER_stop ( void  )

Put the device into stop mode.

The device needs to be woken with an EXTI interrupt or RTC alarm event. All clocks need to be reinitialized after stop mode.

Definition at line 75 of file stm32f103cb_power.c.