-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
103 lines (74 loc) · 2.83 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/*******************************************
* AUTHOR IDENTITY
*
* Initials Name
* -------- ----------------------------
* ANR Aditya
********************************************/
#include <stdint.h>
#include <string.h>
#include "stm32f030xx.h"
#include "stm32f030xx_gpio_driver.h"
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
int main(void)
{
/* The following is GPIO LED configuration */
GPIO_Handle_t GpioLed;
/* Clearing the local structure so as to not initialize garbage values to GPIO peripheral */
memset(&GpioLed, 0u, sizeof(GpioLed));
GpioLed.pGPIOx = GPIOA;
GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN5;
GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUTPUT;
GpioLed.GPIO_PinConfig.GPIO_PinSpeed = GPIO_HI_SPEED;
GpioLed.GPIO_PinConfig.GPIO_PinPuPdControl = GPIO_NOPUPD;
GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_PUSH_PULL;
// Enable Clock Control
GPIO_PClockControl (GPIOA, ENABLE);
// GPIO initialization
GPIO_Init (&GpioLed);
/* Writing a '0' to the LED GPIO pin initially */
GPIO_WriteToOutputPin (GPIOA, GPIO_PIN5, GPIO_PIN_RESET);
/* Following is the GPIO button configuration */
GPIO_Handle_t GpioButton;
/* Clearing the local structure so as to not initialize garbage values to GPIO peripheral */
memset(&GpioButton, 0u, sizeof(GpioButton));
GpioButton.pGPIOx = GPIOC;
GpioButton.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN13;
GpioButton.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_IT_FT;
GpioButton.GPIO_PinConfig.GPIO_PinSpeed = GPIO_HI_SPEED;
GpioButton.GPIO_PinConfig.GPIO_PinPuPdControl = GPIO_PU_ONLY;
// Enable Clock Control
GPIO_PClockControl (GPIOC, ENABLE);
// GPIO initialization
GPIO_Init (&GpioButton);
/* IRQ configurations - priority can be 0 - 3 */
GPIO_IRQConfig(IRQ_NO_EXTI4_15, 3u, ENABLE);
while(1);
return 0;
}
void EXTI4_15_IRQHandler(void)
{
/* Clearing the interrupt bit */
GPIO_IRQHandling(GPIO_PIN13);
/* Toggling the on board GPIO on GPIOA5 */
GPIO_ToggleOutputPin(GPIOA, GPIO_PIN5);
}