1 | #include "main.h"
|
2 |
|
3 | GPIO_InitTypeDef GPIO_InitStructure;
|
4 | static __IO uint32_t TimingDelayLed1;
|
5 | static __IO uint32_t TimingDelayLed2;
|
6 |
|
7 | int main(void)
|
8 | {
|
9 | /*!< At this stage the microcontroller clock setting is already configured,
|
10 | this is done through SystemInit() function which is called from startup
|
11 | file (startup_stm32f2xx.s) before to branch to application main.
|
12 | To reconfigure the default setting of SystemInit() function, refer to
|
13 | system_stm32f2xx.c file
|
14 | */
|
15 |
|
16 | /* Initialize Leds mounted on STM322xG-EVAL board */
|
17 | STM_EVAL_LEDInit(LED1);
|
18 | STM_EVAL_LEDInit(LED2);
|
19 |
|
20 | /* Turn on LED1 and LED3 */
|
21 | STM_EVAL_LEDOn(LED1);
|
22 | STM_EVAL_LEDOn(LED2);
|
23 |
|
24 | /* Setup SysTick Timer for 1 msec interrupts.
|
25 | ------------------------------------------
|
26 | 1. The SysTick_Config() function is a CMSIS function which configure:
|
27 | - The SysTick Reload register with value passed as function parameter.
|
28 | - Configure the SysTick IRQ priority to the lowest value (0x0F).
|
29 | - Reset the SysTick Counter register.
|
30 | - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
|
31 | - Enable the SysTick Interrupt.
|
32 | - Start the SysTick Counter.
|
33 |
|
34 | 2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
|
35 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
|
36 | SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
|
37 | inside the misc.c file.
|
38 |
|
39 | 3. You can change the SysTick IRQ priority by calling the
|
40 | NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
|
41 | call. The NVIC_SetPriority() is defined inside the core_cm3.h file.
|
42 |
|
43 | 4. To adjust the SysTick time base, use the following formula:
|
44 |
|
45 | Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
|
46 |
|
47 | - Reload Value is the parameter to be passed for SysTick_Config() function
|
48 | - Reload Value should not exceed 0xFFFFFF
|
49 | */
|
50 | if (SysTick_Config(SystemCoreClock / 1000))
|
51 | {
|
52 | /* Capture error */
|
53 | while (1);
|
54 | }
|
55 |
|
56 | TimingDelayLed1 = 255;
|
57 | TimingDelayLed2 = 127;
|
58 |
|
59 | while (1)
|
60 | {
|
61 | __no_operation();
|
62 | }
|
63 | }
|
64 |
|
65 | void SysTick_Handler(void)
|
66 | {
|
67 | if (TimingDelayLed1 != 0x00)
|
68 | {
|
69 | TimingDelayLed1--;
|
70 | }
|
71 | else if(TimingDelayLed1 == 0x00)
|
72 | {
|
73 | TimingDelayLed1 = 255;
|
74 | STM_EVAL_LEDToggle(LED1);
|
75 | }
|
76 |
|
77 | if (TimingDelayLed2 != 0x00)
|
78 | {
|
79 | TimingDelayLed2--;
|
80 | }
|
81 | else if(TimingDelayLed2 == 0x00)
|
82 | {
|
83 | TimingDelayLed2 = 127;
|
84 | STM_EVAL_LEDToggle(LED2);
|
85 | }
|
86 |
|
87 | }
|