From 3fef1b9a8c5168c12213d88c9ab7cf6fca3d4751 Mon Sep 17 00:00:00 2001 From: Satish Nair Date: Fri, 4 Apr 2014 16:20:16 +0530 Subject: [PATCH 1/2] Important - Assigned RTC Alarm higher priority than RTC Seconds interrupt --- SPARK_Firmware_Driver/inc/platform_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SPARK_Firmware_Driver/inc/platform_config.h b/SPARK_Firmware_Driver/inc/platform_config.h index 74204d5..f01ae8f 100644 --- a/SPARK_Firmware_Driver/inc/platform_config.h +++ b/SPARK_Firmware_Driver/inc/platform_config.h @@ -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 From db3bee82b98613d7a642be9f2d21a2b04f66aa5f Mon Sep 17 00:00:00 2001 From: Satish Nair Date: Fri, 4 Apr 2014 16:20:30 +0530 Subject: [PATCH 2/2] Enter Standby Mode at startup if flag is set and enable RTC interrupts --- SPARK_Firmware_Driver/src/hw_config.c | 41 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/SPARK_Firmware_Driver/src/hw_config.c b/SPARK_Firmware_Driver/src/hw_config.c index 99693f6..6d25ba3 100644 --- a/SPARK_Firmware_Driver/src/hw_config.c +++ b/SPARK_Firmware_Driver/src/hw_config.c @@ -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(); @@ -286,8 +299,6 @@ 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 */ } @@ -295,12 +306,6 @@ void RTC_Configuration(void) { /* 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); @@ -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)