[PATCH v4 6/7] bsps/stm32f4: Add missing GPIO functionality

Duc Doan dtbpkmte at gmail.com
Sat Jul 23 03:53:21 UTC 2022


---
 bsps/arm/stm32f4/gpio/gpio.c                | 32 +++++++++++++++++++++
 bsps/arm/stm32f4/include/bsp/stm32f4_gpio.h | 20 +++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/bsps/arm/stm32f4/gpio/gpio.c b/bsps/arm/stm32f4/gpio/gpio.c
index efc005bd9f..ac4d3b4f56 100644
--- a/bsps/arm/stm32f4/gpio/gpio.c
+++ b/bsps/arm/stm32f4/gpio/gpio.c
@@ -562,3 +562,35 @@ void exti_handler(void *arg) {
     }
 }
 
+/************ STM32F4 Other specific GPIO functions ************/
+void stm32f4_gpio_lock_pin(
+    rtems_gpio *base
+)
+{
+    stm32f4_gpio *gpio = get_gpio_from_base(base);
+    LL_GPIO_LockPin(
+            gpio->port,
+            STM32F4_GET_HAL_GPIO_PIN(gpio->pin)
+    );
+}
+
+void stm32f4_gpio_set_af(
+    rtems_gpio *base,
+    uint32_t alternate
+)
+{
+    stm32f4_gpio *gpio = get_gpio_from_base(base);
+    if (gpio->pin < 8)
+        LL_GPIO_SetAFPin_0_7(
+                gpio->port,
+                STM32F4_GET_HAL_GPIO_PIN(gpio->pin),
+                alternate
+        );
+    else
+        LL_GPIO_SetAFPin_8_15(
+                gpio->port,
+                STM32F4_GET_HAL_GPIO_PIN(gpio->pin),
+                alternate
+        );
+}
+
diff --git a/bsps/arm/stm32f4/include/bsp/stm32f4_gpio.h b/bsps/arm/stm32f4/include/bsp/stm32f4_gpio.h
index eecd87b3fd..814b1b4105 100644
--- a/bsps/arm/stm32f4/include/bsp/stm32f4_gpio.h
+++ b/bsps/arm/stm32f4/include/bsp/stm32f4_gpio.h
@@ -53,4 +53,24 @@ typedef struct {
     GPIO_TypeDef *port;
 } stm32f4_gpio;
 
+/**
+  * @brief Lock configuration of a pin.
+  *
+  * @param[in] base The pointer to the GPIO object.
+  */
+extern void stm32f4_gpio_lock_pin(
+    rtems_gpio *base
+);
+
+/**
+  * @brief Sets the alternate function for a pin.
+  *
+  * @param[in] base The pointer to the GPIO object.
+  * @param alternate Alternate function, from 0-15.
+  */
+extern void stm32f4_gpio_set_af(
+    rtems_gpio *base,
+    uint32_t alternate
+);
+
 #endif /* LIBBSP_ARM_STM32F4_BSP_GPIO */
-- 
2.36.1



More information about the devel mailing list