Line data Source code
1 : /** 2 : * @file stm32f4_gpio.c 3 : * @brief Implementation for toggling the red LED onboard the 4 : * stm32f446re development board. 5 : * 6 : * Copyright (c) 2025 Cory McKiel. 7 : * Licensed under the MIT License. See LICENSE file in the project root. 8 : */ 9 : #ifdef DESKTOP_BUILD 10 : #include "registers.h" 11 : #else 12 : #include "stm32f4xx.h" 13 : #endif /* DESKTOP_BUILD */ 14 : 15 : #include "gpio.h" 16 : 17 : #define GPIOAEN (1U << 0) /*!< Bit to enable GPIO port A. */ 18 : #define PIN5 (1U << 5) /*!< Pin five for GPIO port A. */ 19 : #define LED_PIN (PIN5) /*!< The onboard LED is wired to GPIO port A, pin 5. */ 20 : 21 1 : hal_status_t hal_gpio_init() 22 : { 23 : // Enable the peripheral bus clock. 24 1 : RCC->AHB1ENR |= GPIOAEN; 25 : 26 : // Configure the GPIO. 27 1 : GPIOA->MODER &=~ (1U << 11); 28 1 : GPIOA->MODER |= (1U << 10); 29 : 30 : // Return HAL_STATUS_OK unconditionally. 31 : // This implementation does not support the interface's full error reporting capability. 32 1 : return HAL_STATUS_OK; 33 : } 34 : 35 2 : hal_status_t hal_gpio_toggle_led() 36 : { 37 : // XOR flips bit each call. 38 2 : GPIOA->ODR ^= LED_PIN; 39 : 40 : // Return HAL_STATUS_OK unconditionally. 41 : // This implementation does not support the interface's full error reporting capability. 42 2 : return HAL_STATUS_OK; 43 : }