comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/PWR/STANDBY/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file PWR/STANDBY/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body.
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24 #include "stm32_eval.h"
25
26 /** @addtogroup STM32F10x_StdPeriph_Examples
27 * @{
28 */
29
30 /** @addtogroup PWR_STANDBY
31 * @{
32 */
33
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 /* Private macro -------------------------------------------------------------*/
37 /* Private variables ---------------------------------------------------------*/
38
39 /* Private function prototypes -----------------------------------------------*/
40 void RTC_Configuration(void);
41 void SysTick_Configuration(void);
42
43 /* Private functions ---------------------------------------------------------*/
44
45 /**
46 * @brief Main program.
47 * @param None
48 * @retval None
49 */
50 int main(void)
51 {
52 /*!< At this stage the microcontroller clock setting is already configured,
53 this is done through SystemInit() function which is called from startup
54 file (startup_stm32f10x_xx.s) before to branch to application main.
55 To reconfigure the default setting of SystemInit() function, refer to
56 system_stm32f10x.c file
57 */
58
59 /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
60 STM_EVAL_LEDInit(LED1);
61 STM_EVAL_LEDInit(LED2);
62 STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
63
64 /* Turn on LED1 */
65 STM_EVAL_LEDOn(LED1);
66
67 /* Enable PWR and BKP clock */
68 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
69
70 /* Enable WKUP pin */
71 PWR_WakeUpPinCmd(ENABLE);
72
73 /* Allow access to BKP Domain */
74 PWR_BackupAccessCmd(ENABLE);
75
76 /* Configure RTC clock source and prescaler */
77 RTC_Configuration();
78
79 /* Configure the SysTick to generate an interrupt each 250 ms */
80 SysTick_Configuration();
81
82 while (1)
83 {
84 }
85 }
86
87 /**
88 * @brief Configures RTC clock source and prescaler.
89 * @param None
90 * @retval None
91 */
92 void RTC_Configuration(void)
93 {
94 /* Check if the StandBy flag is set */
95 if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
96 {/* System resumed from STANDBY mode */
97
98 /* Turn on LED2 */
99 STM_EVAL_LEDOn(LED2);
100
101 /* Clear StandBy flag */
102 PWR_ClearFlag(PWR_FLAG_SB);
103
104 /* Wait for RTC APB registers synchronisation */
105 RTC_WaitForSynchro();
106 /* No need to configure the RTC as the RTC configuration(clock source, enable,
107 prescaler,...) is kept after wake-up from STANDBY */
108 }
109 else
110 {/* StandBy flag is not set */
111
112 /* RTC clock source configuration ----------------------------------------*/
113 /* Reset Backup Domain */
114 BKP_DeInit();
115
116 /* Enable LSE OSC */
117 RCC_LSEConfig(RCC_LSE_ON);
118 /* Wait till LSE is ready */
119 while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
120 {
121 }
122
123 /* Select the RTC Clock Source */
124 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
125
126 /* Enable the RTC Clock */
127 RCC_RTCCLKCmd(ENABLE);
128
129 /* RTC configuration -----------------------------------------------------*/
130 /* Wait for RTC APB registers synchronisation */
131 RTC_WaitForSynchro();
132
133 /* Set the RTC time base to 1s */
134 RTC_SetPrescaler(32767);
135 /* Wait until last write operation on RTC registers has finished */
136 RTC_WaitForLastTask();
137 }
138 }
139
140 /**
141 * @brief Configures the SysTick to generate an interrupt each 250 ms.
142 * @param None
143 * @retval None
144 */
145 void SysTick_Configuration(void)
146 {
147 /* SysTick interrupt each 250 ms with SysTick Clock equal to (HCLK/8) */
148 if (SysTick_Config((SystemCoreClock/8) / 4))
149 {
150 /* Capture error */
151 while (1);
152 }
153
154 /* Select AHB clock(HCLK) divided by 8 as SysTick clock source */
155 SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
156
157 /* Set SysTick Preemption Priority to 1 */
158 NVIC_SetPriority(SysTick_IRQn, 0x04);
159 }
160
161 #ifdef USE_FULL_ASSERT
162
163 /**
164 * @brief Reports the name of the source file and the source line number
165 * where the assert_param error has occurred.
166 * @param file: pointer to the source file name
167 * @param line: assert_param error line source number
168 * @retval None
169 */
170 void assert_failed(uint8_t* file, uint32_t line)
171 {
172 /* User can add his own implementation to report the file name and line number,
173 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
174
175 /* Infinite loop */
176 while (1)
177 {
178 }
179 }
180
181 #endif
182
183 /**
184 * @}
185 */
186
187 /**
188 * @}
189 */
190
191 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/