From 447f03cfd09fca4db68fc9c12586aaa17e5a8495 Mon Sep 17 00:00:00 2001 From: Samuel Martinez Date: Wed, 12 Jun 2024 14:01:37 -0400 Subject: [PATCH] Led and buttons examples Description: Test LED examples on freedom-k66f, nucleo-f401re and blackpill-f411ce boards. Update linker file for bluepill-f103c6. --- .../kinetis/freedom-k66f/src/freedom-k66f.h | 5 + .../kinetis/freedom-k66f/src/k66_bringup.c | 26 ++++- .../stm32/nucleo-f4x1re/src/stm32_bringup.c | 14 +++ .../stm32/stm32f103-minimum/scripts/ld.script | 2 +- .../stm32f411-minimum/src/CMakeLists.txt | 4 + .../arm/stm32/stm32f411-minimum/src/Make.defs | 4 + .../stm32f411-minimum/src/stm32_bringup.c | 14 +++ .../stm32f411-minimum/src/stm32_userleds.c | 100 ++++++++++++++++++ 8 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 boards/arm/stm32/stm32f411-minimum/src/stm32_userleds.c diff --git a/boards/arm/kinetis/freedom-k66f/src/freedom-k66f.h b/boards/arm/kinetis/freedom-k66f/src/freedom-k66f.h index 264a40c0fb..d34d5613c8 100644 --- a/boards/arm/kinetis/freedom-k66f/src/freedom-k66f.h +++ b/boards/arm/kinetis/freedom-k66f/src/freedom-k66f.h @@ -44,6 +44,11 @@ #define HAVE_SPI 1 #define HAVE_USBDEV 1 +#undef HAVE_LEDS +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) +# define HAVE_LEDS 1 +#endif + #if defined(CONFIG_KINETIS_RTC) #define HAVE_RTC_DRIVER 1 #endif diff --git a/boards/arm/kinetis/freedom-k66f/src/k66_bringup.c b/boards/arm/kinetis/freedom-k66f/src/k66_bringup.c index e21be8eecb..4120928df9 100644 --- a/boards/arm/kinetis/freedom-k66f/src/k66_bringup.c +++ b/boards/arm/kinetis/freedom-k66f/src/k66_bringup.c @@ -32,8 +32,21 @@ #include #include +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_EXAMPLES_LEDS_DEVPATH +# define LED_DRIVER_PATH CONFIG_EXAMPLES_LEDS_DEVPATH +#else +# define LED_DRIVER_PATH "/dev/userleds" +#endif + #include -#include + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif #include "kinetis_spi.h" #include "freedom-k66f.h" @@ -59,6 +72,17 @@ int k66_bringup(void) #endif int ret; +#ifdef HAVE_LEDS + /* Register the LED driver */ + + ret = userled_lower_initialize(LED_DRIVER_PATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + return ret; + } +#endif + #ifdef HAVE_PROC /* Mount the proc filesystem */ diff --git a/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c b/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c index d31bcc16dd..be71318e18 100644 --- a/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c +++ b/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c @@ -41,6 +41,10 @@ # include #endif +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + #include "nucleo-f4x1re.h" #include @@ -93,6 +97,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_INPUT_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 diff --git a/boards/arm/stm32/stm32f103-minimum/scripts/ld.script b/boards/arm/stm32/stm32f103-minimum/scripts/ld.script index 142db107dd..6329729701 100644 --- a/boards/arm/stm32/stm32f103-minimum/scripts/ld.script +++ b/boards/arm/stm32/stm32f103-minimum/scripts/ld.script @@ -32,7 +32,7 @@ MEMORY { - flash (rx) : ORIGIN = 0x08000000, LENGTH = 64K + flash (rx) : ORIGIN = 0x08000000, LENGTH = 128K sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K } diff --git a/boards/arm/stm32/stm32f411-minimum/src/CMakeLists.txt b/boards/arm/stm32/stm32f411-minimum/src/CMakeLists.txt index 6dd6b45ddd..6ee723460f 100644 --- a/boards/arm/stm32/stm32f411-minimum/src/CMakeLists.txt +++ b/boards/arm/stm32/stm32f411-minimum/src/CMakeLists.txt @@ -28,6 +28,10 @@ if(CONFIG_ARCH_LEDS) list(APPEND SRCS stm32_autoleds.c) endif() +if(CONFIG_USERLED) + list(APPEND SRCS stm32_userleds.c) +endif() + if(CONFIG_SPI) list(APPEND SRCS stm32_spi.c) endif() diff --git a/boards/arm/stm32/stm32f411-minimum/src/Make.defs b/boards/arm/stm32/stm32f411-minimum/src/Make.defs index c95bd96278..b9fbe021b5 100644 --- a/boards/arm/stm32/stm32f411-minimum/src/Make.defs +++ b/boards/arm/stm32/stm32f411-minimum/src/Make.defs @@ -30,6 +30,10 @@ ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += stm32_autoleds.c endif +ifeq ($(CONFIG_USERLED),y) + CSRCS += stm32_userleds.c +endif + ifeq ($(CONFIG_ADC_HX711),y) CSRCS += stm32_hx711.c endif diff --git a/boards/arm/stm32/stm32f411-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f411-minimum/src/stm32_bringup.c index 3acbb2187c..fa710238c3 100644 --- a/boards/arm/stm32/stm32f411-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f411-minimum/src/stm32_bringup.c @@ -30,6 +30,10 @@ #include "stm32.h" +#ifdef CONFIG_USERLED +# include +#endif + #ifdef CONFIG_STM32_OTGFS # include "stm32_usbhost.h" #endif @@ -84,6 +88,16 @@ int stm32_bringup(void) { int ret = OK; +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_STM32F411MINIMUM_GPIO ret = stm32_gpio_initialize(); if (ret != OK) diff --git a/boards/arm/stm32/stm32f411-minimum/src/stm32_userleds.c b/boards/arm/stm32/stm32f411-minimum/src/stm32_userleds.c new file mode 100644 index 0000000000..287de39fa0 --- /dev/null +++ b/boards/arm/stm32/stm32f411-minimum/src/stm32_userleds.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * boards/arm/stm32/stm32f411-minimum/src/stm32_userleds.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "chip.h" +#include "stm32.h" +#include "stm32f411-minimum.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + /* Configure LED GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + stm32_configgpio(g_ledcfg[i]); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < BOARD_NLEDS) + { + stm32_gpiowrite(g_ledcfg[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + /* Configure LED GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } +} + +#endif /* !CONFIG_ARCH_LEDS */