diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c index befd887061..fd2c21e022 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_userleds.c @@ -59,7 +59,7 @@ uint32_t board_userled_initialize(void) { int i; - /* Configure LED1-8 GPIOs for output */ + /* Configure LED GPIOs for output */ for (i = 0; i < BOARD_NLEDS; i++) { @@ -89,7 +89,7 @@ void board_userled_all(uint32_t ledset) { int i; - /* Configure LED1-8 GPIOs for output */ + /* Configure LED GPIOs for output */ for (i = 0; i < BOARD_NLEDS; i++) { diff --git a/boards/arm/stm32/stm32f411e-disco/include/board.h b/boards/arm/stm32/stm32f411e-disco/include/board.h index 434549f726..0e24099526 100644 --- a/boards/arm/stm32/stm32f411e-disco/include/board.h +++ b/boards/arm/stm32/stm32f411e-disco/include/board.h @@ -297,19 +297,45 @@ /* LEDs * - * The STM32F411E Discovery board has four user leds but only one is - * configured so far. - * LD2 connected to PD12. + * The STM32F411E Discovery board has four user leds + * LD3 connected to PD13. + * LD4 connected to PD12. + * LD5 connected to PD14. + * LD6 connected to PD15. */ /* LED index values for use with board_userled() */ -#define BOARD_LD2 0 -#define BOARD_NLEDS 1 +#define BOARD_LD3 0 +#define BOARD_LD4 1 +#define BOARD_LD5 2 +#define BOARD_LD6 3 +#define BOARD_NLEDS 4 /* LED bits for use with board_userled_all() */ -#define BOARD_LD2_BIT (1 << BOARD_LD2) +#define BOARD_LD3_BIT (1 << BOARD_LD3) +#define BOARD_LD4_BIT (1 << BOARD_LD4) +#define BOARD_LD5_BIT (1 << BOARD_LD5) +#define BOARD_LD6_BIT (1 << BOARD_LD6) + +/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board. + * The following definitions describe how NuttX controls + * the LEDs: + * + * SYMBOL Meaning LED + * ------------------- ---------------------------- -------------------- + */ + +#define LED_STARTED 0 /* NuttX has been started None */ +#define LED_HEAPALLOCATE 1 /* Heap has been allocated ON(1), OFF(2) */ +#define LED_IRQSENABLED 2 /* Interrupts enabled OFF(1), ON(2) */ +#define LED_STACKCREATED 3 /* Idle stack created ON(1), ON(2) */ +#define LED_INIRQ 4 /* In an interrupt (no change) */ +#define LED_SIGNAL 5 /* In a signal handler (no change) */ +#define LED_ASSERTION 6 /* An assertion failed ON(3) */ +#define LED_PANIC 7 /* The system has crashed FLASH(1,2) */ +#define LED_IDLE 8 /* idle loop FLASH(4) */ /* Buttons * diff --git a/boards/arm/stm32/stm32f411e-disco/src/Make.defs b/boards/arm/stm32/stm32f411e-disco/src/Make.defs index 877b62860c..416fe63646 100644 --- a/boards/arm/stm32/stm32f411e-disco/src/Make.defs +++ b/boards/arm/stm32/stm32f411e-disco/src/Make.defs @@ -26,6 +26,12 @@ ifeq ($(CONFIG_NSH_LIBRARY),y) CSRCS += stm32_appinit.c endif +ifeq ($(CONFIG_ARCH_LEDS),y) + CSRCS += stm32_autoleds.c +else + CSRCS += stm32_userleds.c +endif + ifeq ($(CONFIG_STM32_OTGFS),y) CSRCS += stm32_usb.c endif diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c new file mode 100644 index 0000000000..abd6b23ce5 --- /dev/null +++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * boards/arm/stm32/stm32f411e-disco/src/stm32_autoleds.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 + +#include "chip.h" +#include "arm_internal.h" +#include "stm32.h" +#include "stm32f411e-disco.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure LED GPIO for output */ + + stm32_configgpio(GPIO_LD3); + stm32_configgpio(GPIO_LD4); + stm32_configgpio(GPIO_LD5); + stm32_configgpio(GPIO_LD6); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + switch (led) + { + case LED_HEAPALLOCATE: + { + stm32_gpiowrite(GPIO_LD3, true); + stm32_gpiowrite(GPIO_LD4, false); + } + break; + + case LED_IRQSENABLED: + { + stm32_gpiowrite(GPIO_LD3, false); + stm32_gpiowrite(GPIO_LD4, true); + } + break; + + case LED_STACKCREATED: + { + stm32_gpiowrite(GPIO_LD3, true); + stm32_gpiowrite(GPIO_LD4, true); + } + break; + + case LED_ASSERTION: + { + stm32_gpiowrite(GPIO_LD5, true); + } + break; + + case LED_PANIC: + { + stm32_gpiowrite(GPIO_LD3, true); + stm32_gpiowrite(GPIO_LD4, true); + } + break; + + case LED_IDLE: + { + stm32_gpiowrite(GPIO_LD6, true); + } + break; + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + switch (led) + { + case LED_PANIC: + { + stm32_gpiowrite(GPIO_LD3, false); + stm32_gpiowrite(GPIO_LD4, false); + } + break; + + case LED_IDLE: + { + stm32_gpiowrite(GPIO_LD6, false); + } + break; + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c index 7aefa12e23..62ed147709 100644 --- a/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_bringup.c @@ -82,5 +82,15 @@ int stm32_bringup(void) } #endif +#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 + return ret; } diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c new file mode 100644 index 0000000000..644208aea6 --- /dev/null +++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_userleds.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * boards/arm/stm32/stm32f411e-disco/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 "stm32f411e-disco.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_LD3, + GPIO_LD4, + GPIO_LD5, + GPIO_LD6, +}; + +/**************************************************************************** + * 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 */ diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h b/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h index a2dc009f44..daec169d24 100644 --- a/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h +++ b/boards/arm/stm32/stm32f411e-disco/src/stm32f411e-disco.h @@ -36,18 +36,32 @@ /* Configuration ************************************************************/ -/* LED. User LD2: the green LED is a user LED connected to Arduino signal - * D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on - * the STM32 target. +/* User LED. * * - When the I/O is HIGH value, the LED is on. * - When the I/O is LOW, the LED is off. */ -#define GPIO_LD2 \ +/* User LD3: The orange LED is a user LED connected to the I/O PD13 */ +#define GPIO_LD3 \ + (GPIO_PORTD | GPIO_PIN13 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \ + GPIO_SPEED_50MHz) + +/* User LD4: The green LED is a user LED connected to the I/O PD12 */ +#define GPIO_LD4 \ (GPIO_PORTD | GPIO_PIN12 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \ GPIO_SPEED_50MHz) +/* User LD5: The red LED is a user LED connected to the I/O PD14 */ +#define GPIO_LD5 \ + (GPIO_PORTD | GPIO_PIN14 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \ + GPIO_SPEED_50MHz) + +/* User LD6: The blue LED is a user LED connected to the I/O PD15 */ +#define GPIO_LD6 \ + (GPIO_PORTD | GPIO_PIN15 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \ + GPIO_SPEED_50MHz) + /* Buttons * * B1 USER: the user button is connected to the I/O PA0 of the STM32