From 80977b8053984eb4d996cc7c74bc844b972f0206 Mon Sep 17 00:00:00 2001 From: Manon Sanchez Date: Mon, 20 Mar 2023 14:20:52 +0100 Subject: [PATCH] Added the activation of the specific clock to the GPIO port, during their initialization. Added comments. --- ProjetsKEIL/Drivers/Driver_GPIO.c | 26 +++++++++++++++++++++++++- ProjetsKEIL/Drivers/Driver_GPIO.h | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ProjetsKEIL/Drivers/Driver_GPIO.c b/ProjetsKEIL/Drivers/Driver_GPIO.c index aefea5c..279c924 100644 --- a/ProjetsKEIL/Drivers/Driver_GPIO.c +++ b/ProjetsKEIL/Drivers/Driver_GPIO.c @@ -1,9 +1,29 @@ #include "Driver_GPIO.h" #include "stm32f10x.h" #include "stdio.h" - +/* GPIO init function */ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) { + + /* Activation of the GPIO port specific clock */ + if (GPIOStructPtr->GPIO == GPIOA) + { + RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; + } + else if (GPIOStructPtr->GPIO == GPIOB) + { + RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; + } + else if (GPIOStructPtr->GPIO == GPIOC) + { + RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; + } + else if (GPIOStructPtr->GPIO == GPIOD) + { + RCC->APB2ENR |= RCC_APB2ENR_IOPDEN; + } + + /* Reset, and then configuration writing of the selected GPIO Pin */ if(GPIOStructPtr->GPIO_Pin <= 8) { @@ -24,18 +44,22 @@ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin); } } +/* Read of the state of the GPIO */ int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) { return ((GPIO->ODR & (0x1<>GPIO_Pin); } +/* Set the state of the GPIO */ void MyGPIO_Set (GPIO_TypeDef * GPIO , char GPIO_Pin) { GPIO->ODR &= 0x1<ODR |= ~(0x1<