Skip to content

Commit

Permalink
Merge pull request #20 from spark/feature/sleep-mode-update
Browse files Browse the repository at this point in the history
Feature/sleep mode update
  • Loading branch information
Zachary Crockett committed Apr 10, 2014
2 parents c4836e9 + db3bee8 commit 516c379
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions SPARK_Firmware_Driver/inc/platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@
#define DMA1_CHANNEL5_IRQ_PRIORITY 0 //CC3000_SPI_TX_DMA Interrupt
#define EXTI15_10_IRQ_PRIORITY 1 //CC3000_WIFI_INT_EXTI & User Interrupt
#define USB_LP_IRQ_PRIORITY 2 //USB_LP_CAN1_RX0 Interrupt
#define RTC_IRQ_PRIORITY 3 //RTC Seconds Interrupt
#define RTCALARM_IRQ_PRIORITY 4 //RTC Alarm Interrupt
#define RTCALARM_IRQ_PRIORITY 3 //RTC Alarm Interrupt
#define RTC_IRQ_PRIORITY 4 //RTC Seconds Interrupt
#define TIM1_CC_IRQ_PRIORITY 5 //TIM1_CC4 Interrupt
#define EXTI2_IRQ_PRIORITY 6 //BUTTON1_EXTI Interrupt
#define USART2_IRQ_PRIORITY 7 //USART2 Interrupt
Expand Down
41 changes: 24 additions & 17 deletions SPARK_Firmware_Driver/src/hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,27 @@ void Set_System(void)
system_stm32f10x.c file
*/

DWT_Init();

/* Enable PWR and BKP clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

/* Enable write access to Backup domain */
PWR_BackupAccessCmd(ENABLE);

/* Should we execute System Standby mode */
if(BKP_ReadBackupRegister(BKP_DR9) == 0xA5A5)
{
/* Clear Standby mode system flag */
BKP_WriteBackupRegister(BKP_DR9, 0xFFFF);

/* Request to enter STANDBY mode */
PWR_EnterSTANDBYMode();

/* Following code will not be reached */
while(1);
}

DWT_Init();

/* NVIC configuration */
NVIC_Configuration();

Expand Down Expand Up @@ -286,21 +299,13 @@ void RTC_Configuration(void)
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();

BKP_WriteBackupRegister(BKP_DR9, 0xFFFF);

/* No need to configure the RTC as the RTC configuration(clock source, enable,
prescaler,...) is kept after wake-up from STANDBY */
}
else
{
/* StandBy flag is not set */

if(BKP_ReadBackupRegister(BKP_DR9) == 0xA5A5)
{
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
PWR_EnterSTANDBYMode();
}

/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);

Expand All @@ -322,25 +327,27 @@ void RTC_Configuration(void)
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();

/* Enable the RTC Second and RTC Alarm interrupt */
RTC_ITConfig(RTC_IT_SEC | RTC_IT_ALR, ENABLE);

/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();

/* Set RTC prescaler: set RTC period to 1sec */
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}

/* Enable the RTC Second and RTC Alarm interrupt */
RTC_ITConfig(RTC_IT_SEC | RTC_IT_ALR, ENABLE);

/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}

void Enter_STANDBY_Mode(void)
{
/* Execute Standby mode on next system reset */
BKP_WriteBackupRegister(BKP_DR9, 0xA5A5);

NVIC_SystemReset();
/* Reset System */
NVIC_SystemReset();
}

void IWDG_Reset_Enable(uint32_t msTimeout)
Expand Down

0 comments on commit 516c379

Please sign in to comment.