configs/stm32l476-mdk: Add support for the on-board LEDs.

This commit is contained in:
Gregory Nutt 2017-11-12 12:56:38 -06:00
parent 8b64f8ae49
commit d594d1f56e
9 changed files with 324 additions and 19 deletions

View File

@ -106,5 +106,5 @@ picocom:
$ sudo apt install picocom
$ sudo picocom -b 115200 /dev/ttyUSB2
Everything else defaults correction. Ctrl-A then Ctrl-X will terminate
Everything else defaults correctly. Ctrl-A then Ctrl-X will terminate
either the minicom or the picocom session.

View File

@ -109,6 +109,65 @@
#define GPIO_SPI2_SCK GPIO_SPI2_SCK_2 /* PB13 */
#define GPIO_SPI2_NSS GPIO_SPI2_NSS_2 /* PB12 */
/* LED definitions ******************************************************************/
/* The Reference Moto Mod contains three LEDs. Two LEDs, are by convention, used to
* indicate the Reference Moto Mod battery state of charge, and the other is
* available for you to use in your applications.
*
* 1. The red LED on PD7. Part of the (rear-firing) red/green LED.
* 2. The green LED on PE7. Part of the (rear-firing) red/green LED.
* 3. The white (top-firing) LED on PE8
*
* When the I/O is HIGH value, the LED is OFF.
* When the I/O is LOW, the LED is ON.
*
* Following this convention, only the white LED is made available even though they
* all could be user-application controlled if desired.
*/
/* LED index values for use with board_userled() */
#define BOARD_RED_LED 0
#define BOARD_GREEN_LED 1
#ifndef CONFIG_ARCH_LEDS
# define BOARD_WHITE_LED 2
# define BOARD_NLEDS 3
#else
# define BOARD_NLEDS 2
#endif
/* LED bits for use with board_userled_all() */
#define BOARD_RED_LED_BIT (1 << BOARD_RED_LED)
#define BOARD_GREEN_LED_BIT (1 << BOARD_GREEN_LED)
#ifndef CONFIG_ARCH_LEDS
# define BOARD_WHITE_LED_BIT (1 << BOARD_WHITE_LED)
#endif
/* None of the LEDs are used by the board port unless CONFIG_ARCH_LEDS is defined.
* In that case, the white LED (only) will be controlled. Usage by the board port
* is defined in include/board.h and src/stm32_autoleds.c. The white LED will be
* used to encode OS-related events as follows:
*
* ------------------- ---------------------------- ------
* SYMBOL Meaning LED
* ------------------- ---------------------------- ------ */
#define LED_STARTED 0 /* NuttX has been started OFF */
#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */
#define LED_STACKCREATED 1 /* Idle stack created ON */
#define LED_INIRQ 2 /* In an interrupt N/C */
#define LED_SIGNAL 2 /* In a signal handler N/C */
#define LED_ASSERTION 2 /* An assertion failed N/C */
#define LED_PANIC 3 /* The system has crashed FLASH */
#undef LED_IDLE /* MCU is is sleep mode Not used */
/* Thus if the white LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If white LED is flashing at approximately 2Hz,
* then a fatal error has been detected and the system has halted.
*/
/* Buttons **************************************************************************/
/* The board only has one button */

View File

@ -1,7 +1,5 @@
# CONFIG_ARCH_FPU is not set
# CONFIG_ARCH_LEDS is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_DF_H is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH_BOARD_STM32L476_MDK=y

View File

@ -105,10 +105,6 @@ ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif
LDFLAGS += -Map=${TOPDIR}/nuttx.map
#CFLAGS += -Wa,-adhln
#CXXFLAGS += -Wa,-adhln
HOSTCC = gcc
HOSTINCLUDES = -I.
HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe

View File

@ -36,14 +36,18 @@
-include $(TOPDIR)/Make.defs
ASRCS =
CSRCS = stm32_boot.c stm32_spi.c
CSRCS = stm32_boot.c stm32_spi.c stm32_userleds.c
ifeq ($(CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG),y)
CSRCS += stm32_clockconfig.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += stm32_buttons.c
CSRCS += stm32_buttons.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)

View File

@ -0,0 +1,133 @@
/****************************************************************************
* configs/stm32l476-mdk/src/sam_autoleds.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* The Reference Moto Mod contains three LEDs. Two LEDs, are by convention,
* used to indicate the Reference Moto Mod battery state of charge, and the
* other is available for you to use in your applications.
*
* 1. The red LED on PD7. Part of the (rear-firing) red/green LED.
* 2. The green LED on PE7. Part of the (rear-firing) red/green LED.
* 3. The white (top-firing) LED on PE8
*
* When the I/O is HIGH value, the LED is OFF.
* When the I/O is LOW, the LED is ON.
*
* Following this convention, only the white LED is made available even though
* they all could be user-application controlled if desired.
*
* None of the LEDs are used by the board port unless CONFIG_ARCH_LEDS is defined.
* In that case, the white LED (only) will be controlled. Usage by the board port
* is defined in include/board.h and src/stm32_autoleds.c. The white LED will be
* used to encode OS-related events as follows:
*
* ------------------ ------------------------ ------
* SYMBOL Meaning LED
* ------------------ ------------------------ ------
*
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
* LED_IDLE MCU is is sleep mode Not used
*
* Thus if the white LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If white LED is flashing at approximately 2Hz,
* then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "stm32l4_gpio.h"
#include "stm32l476-mdk.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
/* Configure LED GPIOs for output */
stm32l4_configgpio(GPIO_LED_RED);
stm32l4_configgpio(GPIO_LED_GREEN);
stm32l4_configgpio(GPIO_LED_WHITE);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
if (led == 1 || led == 3)
{
stm32l4_gpiowrite(GPIO_LED_WHITE, false); /* Low illuminates */
}
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
if (led == 3)
{
stm32l4_gpiowrite(GPIO_LED_WHITE, true); /* High extinguishes */
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -67,17 +67,17 @@
void stm32l4_board_initialize(void)
{
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
/* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the weak function
* stm32_spiinitialize() has been brought into the link.
*/
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
stm32l4_spiinitialize();
#endif
}

View File

@ -0,0 +1,105 @@
/****************************************************************************
* configs/stm32l476-mdk/src/sam_userleds.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <arch/board/board.h>
#include "stm32l4_gpio.h"
#include "stm32l476-mdk.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
****************************************************************************/
void board_userled_initialize(void)
{
#ifndef CONFIG_ARCH_LEDS
/* Configure LED GPIOs for output */
stm32l4_configgpio(GPIO_LED_RED);
stm32l4_configgpio(GPIO_LED_GREEN);
stm32l4_configgpio(GPIO_LED_WHITE);
#endif
}
/****************************************************************************
* Name: board_userled
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_RED_LED)
{
stm32l4_gpiowrite(GPIO_LED_RED, !ledon); /* Low illuminates */
}
else if (led == BOARD_GREEN_LED)
{
stm32l4_gpiowrite(GPIO_LED_GREEN, !ledon); /* Low illuminates */
}
#ifndef CONFIG_ARCH_LEDS
else if (led == BOARD_WHITE_LED)
{
stm32l4_gpiowrite(GPIO_LED_WHITE, !ledon); /* Low illuminates */
}
#endif
}
/****************************************************************************
* Name: board_userled_all
****************************************************************************/
void board_userled_all(uint8_t ledset)
{
/* Low illuminates */
stm32l4_gpiowrite(GPIO_LED_RED, (ledset & BOARD_RED_LED_BIT) == 0);
stm32l4_gpiowrite(GPIO_LED_GREEN, (ledset & BOARD_GREEN_LED_BIT) == 0);
#ifndef CONFIG_ARCH_LEDS
stm32l4_gpiowrite(GPIO_LED_WHITE, (ledset & BOARD_WHITE_LED_BIT) == 0);
#endif
}

View File

@ -71,20 +71,29 @@
# undef HAVE_RTC_DRIVER
#endif
/* LED.
* LD4: the red LED on PB2
* LD5: the green LED on PE8
/* LEDs.
* The Reference Moto Mod contains three LEDs. Two LEDs, are by convention,
* used to indicate the Reference Moto Mod battery state of charge, and the
* other is available for you to use in your applications.
*
* - When the I/O is HIGH value, the LED is on.
* - When the I/O is LOW, the LED is off.
* 1. The red LED on PD7. Part of the (rear-firing) red/green LED.
* 2. The green LED on PE7. Part of the (rear-firing) red/green LED.
* 3. The white (top-firing) LED on PE8
*
* When the I/O is HIGH value, the LED is OFF.
* When the I/O is LOW, the LED is ON.
*/
#define GPIO_LED_RED \
(GPIO_PORTB | GPIO_PIN2 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PUSHPULL | \
(GPIO_PORTD | GPIO_PIN7 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_PUSHPULL | \
GPIO_PULLUP | GPIO_SPEED_50MHz)
#define GPIO_LED_GRN \
(GPIO_PORTE | GPIO_PIN8 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PUSHPULL | \
#define GPIO_LED_GREEN \
(GPIO_PORTE | GPIO_PIN7 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_PUSHPULL | \
GPIO_PULLUP | GPIO_SPEED_50MHz)
#define GPIO_LED_WHITE \
(GPIO_PORTE | GPIO_PIN8 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_PUSHPULL | \
GPIO_PULLUP | GPIO_SPEED_50MHz)
/* BUTTONS -- NOTE that all have EXTI interrupts configured */
@ -96,6 +105,7 @@
#define GPIO_BTN_POWER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN2)
/* SPI1 off */
#define GPIO_SPI1_MOSI_OFF (GPIO_INPUT | GPIO_PULLDOWN | \
GPIO_PORTE | GPIO_PIN15)
#define GPIO_SPI1_MISO_OFF (GPIO_INPUT | GPIO_PULLDOWN | \