comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/SysTick/TimeBase/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 SysTick/TimeBase/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 "main.h"
24
25 /** @addtogroup STM32F10x_StdPeriph_Examples
26 * @{
27 */
28
29 /** @addtogroup SysTick_TimeBase
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 /* Private macro -------------------------------------------------------------*/
36 /* Private variables ---------------------------------------------------------*/
37 static __IO uint32_t TimingDelay;
38
39 /* Private function prototypes -----------------------------------------------*/
40 void Delay(__IO uint32_t nTime);
41
42 /* Private functions ---------------------------------------------------------*/
43
44 /**
45 * @brief Main program.
46 * @param None
47 * @retval None
48 */
49 int main(void)
50 {
51 /*!< At this stage the microcontroller clock setting is already configured,
52 this is done through SystemInit() function which is called from startup
53 file (startup_stm32f10x_xx.s) before to branch to application main.
54 To reconfigure the default setting of SystemInit() function, refer to
55 system_stm32f10x.c file
56 */
57
58 /* Initialize Leds mounted on STM3210X-EVAL board */
59 STM_EVAL_LEDInit(LED1);
60 STM_EVAL_LEDInit(LED2);
61 STM_EVAL_LEDInit(LED3);
62 STM_EVAL_LEDInit(LED4);
63
64 /* Turn on LED1 and LED3 */
65 STM_EVAL_LEDOn(LED1);
66 STM_EVAL_LEDOn(LED3);
67
68 /* Setup SysTick Timer for 1 msec interrupts.
69 ------------------------------------------
70 1. The SysTick_Config() function is a CMSIS function which configure:
71 - The SysTick Reload register with value passed as function parameter.
72 - Configure the SysTick IRQ priority to the lowest value (0x0F).
73 - Reset the SysTick Counter register.
74 - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
75 - Enable the SysTick Interrupt.
76 - Start the SysTick Counter.
77
78 2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
79 SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
80 SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
81 inside the misc.c file.
82
83 3. You can change the SysTick IRQ priority by calling the
84 NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
85 call. The NVIC_SetPriority() is defined inside the core_cm3.h file.
86
87 4. To adjust the SysTick time base, use the following formula:
88
89 Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
90
91 - Reload Value is the parameter to be passed for SysTick_Config() function
92 - Reload Value should not exceed 0xFFFFFF
93 */
94 if (SysTick_Config(SystemCoreClock / 1000))
95 {
96 /* Capture error */
97 while (1);
98 }
99
100 while (1)
101 {
102 /* Toggle LED2 and LED4 */
103 STM_EVAL_LEDToggle(LED2);
104 STM_EVAL_LEDToggle(LED4);
105
106 /* Insert 50 ms delay */
107 Delay(50);
108
109 /* Toggle LED1 and LED3 */
110 STM_EVAL_LEDToggle(LED1);
111 STM_EVAL_LEDToggle(LED3);
112
113 /* Insert 100 ms delay */
114 Delay(100);
115 }
116 }
117
118 /**
119 * @brief Inserts a delay time.
120 * @param nTime: specifies the delay time length, in milliseconds.
121 * @retval None
122 */
123 void Delay(__IO uint32_t nTime)
124 {
125 TimingDelay = nTime;
126
127 while(TimingDelay != 0);
128 }
129
130 /**
131 * @brief Decrements the TimingDelay variable.
132 * @param None
133 * @retval None
134 */
135 void TimingDelay_Decrement(void)
136 {
137 if (TimingDelay != 0x00)
138 {
139 TimingDelay--;
140 }
141 }
142
143 #ifdef USE_FULL_ASSERT
144
145 /**
146 * @brief Reports the name of the source file and the source line number
147 * where the assert_param error has occurred.
148 * @param file: pointer to the source file name
149 * @param line: assert_param error line source number
150 * @retval None
151 */
152 void assert_failed(uint8_t* file, uint32_t line)
153 {
154 /* User can add his own implementation to report the file name and line number,
155 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
156
157 /* Infinite loop */
158 while (1)
159 {
160 }
161 }
162
163 #endif
164
165 /**
166 * @}
167 */
168
169 /**
170 * @}
171 */
172
173 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/