From 0f2ea7deaf0cba2f0ca07f6611c5a9e87d531f5b Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 26 Aug 2025 17:03:24 +0000 Subject: Initial commit --- project_starter_files/Core/Src/LED.c | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 project_starter_files/Core/Src/LED.c (limited to 'project_starter_files/Core/Src/LED.c') diff --git a/project_starter_files/Core/Src/LED.c b/project_starter_files/Core/Src/LED.c new file mode 100644 index 0000000..8b1b9b2 --- /dev/null +++ b/project_starter_files/Core/Src/LED.c @@ -0,0 +1,49 @@ +#include "LED.h" + + +//****************************************************************************************** +// User LED = LD2 Green LED = PA.5 +//****************************************************************************************** +#define LED_PIN 5 + +void LED_Init(void){ + + // Enable the peripheral clock of GPIO Port + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; + + // GPIO Mode: Input(00), Output(01), AlterFunc(10), Analog(11, reset) + GPIOA->MODER &= ~(3U<<(2*LED_PIN)); + GPIOA->MODER |= 1U<<(2*LED_PIN); // Output(01) + + // GPIO Speed: Low speed (00), Medium speed (01), Fast speed (10), High speed (11) + GPIOA->OSPEEDR &= ~(3U<<(2*LED_PIN)); + GPIOA->OSPEEDR |= 3U<<(2*LED_PIN); // High speed + + // GPIO Output Type: Output push-pull (0, reset), Output open drain (1) + GPIOA->OTYPER &= ~(1U<PUPDR &= ~(3U<<(2*LED_PIN)); // No pull-up, no pull-down + +} + +//****************************************************************************************** +// Turn LED On +//****************************************************************************************** +void LED_On(void){ + GPIOA->ODR |= (1UL<ODR &= ~(1UL<ODR ^= (1UL<