ViewTool STM32F107: Add support for on-board LEDs and buttons

This commit is contained in:
Gregory Nutt 2013-11-30 14:15:15 -06:00
parent 6b18d2d376
commit b35bc21fb9
8 changed files with 827 additions and 68 deletions

View File

@ -15,6 +15,18 @@ README
http://www.viewtool.com/ for further information.
Contents
========
o User and Wake-Up keys
o LEDs
o Serial Console
o Toolchains
- NOTE about Windows native toolchains
o Configurations
- Information Common to All Configurations
- Configuration sub-directories
User and Wake-Up keys
=====================
@ -27,13 +39,37 @@ User and Wake-Up keys
LEDs
====
All pulled high and can be illuminated by driving the output to low
There are four LEDs on the ViewTool STM32F103/F107 board that can be controlled
by software: LED1 through LED4. All pulled high and can be illuminated by
driving the output to low
LED1 PA6
LED2 PA7
LED3 PB12
LED4 PB13
These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
defined. In that case, the usage by the board port is defined in
include/board.h and src/stm32_leds.c. The LEDs are used to encode OS-related
events as follows:
SYMBOL Meaning LED state
LED1 LED2 LED3 LED4
----------------- ----------------------- ---- ---- ---- ----
LED_STARTED NuttX has been started ON OFF OFF OFF
LED_HEAPALLOCATE Heap has been allocated OFF ON OFF OFF
LED_IRQSENABLED Interrupts enabled ON ON OFF OFF
LED_STACKCREATED Idle stack created OFF OFF ON OFF
LED_INIRQ In an interrupt N/C N/C N/C Soft glow
LED_SIGNAL In a signal handler N/C N/C N/C Soft glow
LED_ASSERTION An assertion failed N/C N/C N/C Soft glow
LED_PANIC The system has crashed N/C N/C N/C 2Hz Flashing
LED_IDLE MCU is is sleep mode Not used
After booting, LED1-3 are not longer used by the system and can be used for
other purposes by the application (Of course, all LEDs are available to the
application if CONFIG_ARCH_LEDS is not defined.
Serial Console
==============
@ -50,4 +86,121 @@ Serial Console
5 RTS? 9 CTS? PA12 USART1_RTS
6 CTS? 11 RTS? PA11 USART1_CTS
Note: This requires USART1 pin remapping
Note: This requires USART1 pin remapping
Toolchains
==========
NOTE about Windows native toolchains
------------------------------------
There are several limitations to using a Windows based toolchain in a
Cygwin environment. The three biggest are:
1. The Windows toolchain cannot follow Cygwin paths. Path conversions are
performed automatically in the Cygwin makefiles using the 'cygpath'
utility but you might easily find some new path problems. If so, check
out 'cygpath -w'
2. Windows toolchains cannot follow Cygwin symbolic links. Many symbolic
links are used in Nuttx (e.g., include/arch). The make system works
around these problems for the Windows tools by copying directories
instead of linking them. But this can also cause some confusion for
you: For example, you may edit a file in a "linked" directory and find
that your changes had no effect. That is because you are building the
copy of the file in the "fake" symbolic directory. If you use a\
Windows toolchain, you should get in the habit of making like this:
make clean_context all
An alias in your .bashrc file might make that less painful.
3. Dependencies are not made when using Windows versions of the GCC. This is
because the dependencies are generated using Windows pathes which do not
work with the Cygwin make.
MKDEP = $(TOPDIR)/tools/mknulldeps.sh
Configurations
==============
Information Common to All Configurations
----------------------------------------
Each SAM3U-EK configuration is maintained in a sub-directory and
can be selected as follow:
cd tools
./configure.sh viewtool-stm32f107/<subdir>
cd -
. ./setenv.sh
Before sourcing the setenv.sh file above, you should examine it and perform
edits as necessary so that TOOLCHAIN_BIN is the correct path to the directory
than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of the following.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
and misc/tools/
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output on USART1.
3. Unless otherwise stated, the configurations are setup for
Cygwin under Windows:
Build Setup:
CONFIG_HOST_WINDOWS=y : Windows operating system
CONFIG_WINDOWS_CYGWIN=y : POSIX environment under windows
4. All of these configurations use the Code Sourcery for Windows toolchain
(unless stated otherwise in the description of the configuration). That
toolchain selection can easily be reconfigured using 'make menuconfig'.
Here are the relevant current settings:
System Type -> Toolchain:
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : GNU EABI toolchain for windows
The setenv.sh file is available for you to use to set the PATH
variable. The path in the that file may not, however, be correct
for your installation.
See also the "NOTE about Windows native toolchains" in the section call
"GNU Toolchain Options" above.
Configuration sub-directories
-----------------------------
nsh:
This configuration directory provide the basuic NuttShell (NSH).
NOTES:
1. This configuration uses the default USART1 serial console. That
is easily changed by reconfiguring to (1) enable a different
serial peripheral, and (2) selecting that serial peripheral as
the console device.
2. By default, this configuration is set up to build on Windows
under either a Cygwin or MSYS environment using a recent, Windows-
native, generic ARM EABI GCC toolchain (such as the CodeSourcery
toolchain). Both the build environment and the toolchain
selection can easily be changed by reconfiguring:
CONFIG_HOST_WINDOWS=y : Windows operating system
CONFIG_WINDOWS_CYGWIN=y : POSIX environment under windows
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows

View File

@ -45,6 +45,7 @@
#ifndef __ASSEMBLY__
# include <stdint.h>
#endif
#include "stm32_rcc.h"
#include "stm32_sdio.h"
#include "stm32.h"
@ -117,6 +118,72 @@
# define STM32_PLL_PLL3MUL RCC_CFGR2_PLL3MULx10 /* MCO 5MHz * 10 = 50MHz */
#endif
/* LED definitions ******************************************************************/
/* There are four LEDs on the ViewTool STM32F103/F107 board that can be controlled
* by software: LED1 through LED4. All pulled high and can be illuminated by
* driving the output to low
*
* LED1 PA6
* LED2 PA7
* LED3 PB12
* LED4 PB13
*/
/* LED index values for use with stm32_setled() */
#define BOARD_LED1 0
#define BOARD_LED2 1
#define BOARD_LED3 2
#define BOARD_LED4 3
#define BOARD_NLEDS 4
/* LED bits for use with stm32_setleds() */
#define BOARD_LED1_BIT (1 << BOARD_LED1)
#define BOARD_LED2_BIT (1 << BOARD_LED2)
#define BOARD_LED3_BIT (1 << BOARD_LED3)
#define BOARD_LED4_BIT (1 << BOARD_LED4)
/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/stm32_leds.c. The LEDs are used to encode OS-related
* events as follows:
*
* SYMBOL Val Meaning LED state
* LED1 LED2 LED3 LED4
* ----------------- --- ----------------------- ---- ---- ---- ---- */
#define LED_STARTED 0 /* NuttX has been started ON OFF OFF OFF */
#define LED_HEAPALLOCATE 1 /* Heap has been allocated OFF ON OFF OFF */
#define LED_IRQSENABLED 2 /* Interrupts enabled ON ON OFF OFF */
#define LED_STACKCREATED 3 /* Idle stack created OFF OFF ON OFF */
#define LED_INIRQ 4 /* In an interrupt N/C N/C N/C GLOW */
#define LED_SIGNAL 4 /* In a signal handler N/C N/C N/C GLOW */
#define LED_ASSERTION 4 /* An assertion failed N/C N/C N/C GLOW */
#define LED_PANIC 4 /* The system has crashed N/C N/C N/C FLASH */
#undef LED_IDLE /* MCU is is sleep mode Not used */
/* After booting, LED1-3 are not longer used by the system and can be used for
* other purposes by the application (Of course, all LEDs are available to the
* application if CONFIG_ARCH_LEDS is not defined.
*/
/* Buttons **************************************************************************/
/* All pulled high and will be sensed low when depressed.
*
* SW2 PC11 Needs J42 closed
* SW3 PC12 Needs J43 closed
* SW4 PA0 Needs J44 closed
*/
#define BUTTON_SW2 0
#define BUTTON_SW3 1
#define BUTTON_SW4 2
#define NUM_BUTTONS 3
#define BUTTON_SW2_BIT (1 << BUTTON_SW2)
#define BUTTON_SW3_BIT (1 << BUTTON_SW3)
#define BUTTON_SW4_BIT (1 << BUTTON_SW4)
/************************************************************************************
* Public Data
************************************************************************************/
@ -144,7 +211,64 @@ extern "C" {
*
************************************************************************************/
EXTERN void stm32_boardinitialize(void);
void stm32_boardinitialize(void);
/************************************************************************************
* Name: up_setled and up_setleds
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LEDs. If
* CONFIG_ARCH_LEDS is not defined, then the following interfaces are available to
* control the LEDs from user applications.
*
************************************************************************************/
#ifndef CONFIG_ARCH_LEDS
void up_setled(int led, bool ledon);
void up_setleds(uint8_t ledset);
#endif
/************************************************************************************
* Name: up_buttoninit
*
* Description:
* up_buttoninit() must be called to initialize button resources. After that,
* up_buttons() may be called to collect the current state of all buttons or
* up_irqbutton() may be called to register button interrupt handlers.
*
************************************************************************************/
#ifdef CONFIG_ARCH_BUTTONS
void up_buttoninit(void);
/************************************************************************************
* Name: up_buttons
*
* Description:
* After up_buttoninit() has been called, up_buttons() may be called to collect
* the state of all buttons. up_buttons() returns an 8-bit bit set with each bit
* associated with a button. See the BUTTON* definitions above for the meaning of
* each bit in the returned value.
*
************************************************************************************/
uint8_t up_buttons(void);
/************************************************************************************
* Name: up_irqbutton
*
* Description:
* This function may be called to register an interrupt handler that will be
* called when a button is depressed or released. The ID value is one of the
* BUTTON* definitions provided above. The previous interrupt handler address is
* returned (so that it may restored, if so desired).
*
************************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
#endif /* CONFIG_ARCH_IRQBUTTONS */
#endif /* CONFIG_ARCH_BUTTONS */
#undef EXTERN
#if defined(__cplusplus)

View File

@ -8,10 +8,14 @@ CONFIG_NUTTX_NEWCONFIG=y
# Build Setup
#
# CONFIG_EXPERIMENTAL is not set
CONFIG_HOST_LINUX=y
# CONFIG_HOST_LINUX is not set
# CONFIG_HOST_OSX is not set
# CONFIG_HOST_WINDOWS is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
#
# Build Configuration
@ -99,12 +103,15 @@ CONFIG_ARCH_HAVE_MPU=y
#
# ARMV7M Configuration Options
#
# CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC is not set
# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set
# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL=y
# CONFIG_ARMV7M_TOOLCHAIN_CODEREDW is not set
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y
# CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM is not set
# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW is not set
# CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE is not set
# CONFIG_SERIAL_TERMIOS is not set
# CONFIG_NET_MULTICAST is not set
#
# STM32 Configuration Options
@ -319,7 +326,7 @@ CONFIG_ARCH_BOARD="viewtool-stm32f107"
CONFIG_ARCH_HAVE_LEDS=y
CONFIG_ARCH_LEDS=y
CONFIG_ARCH_HAVE_BUTTONS=y
# CONFIG_ARCH_BUTTONS is not set
CONFIG_ARCH_BUTTONS=y
CONFIG_NSH_MMCSDMINOR=0
#
@ -414,8 +421,6 @@ CONFIG_ARCH_HAVE_I2CRESET=y
# CONFIG_LCD is not set
# CONFIG_MMCSD is not set
# CONFIG_MTD is not set
# CONFIG_NETDEVICES is not set
# CONFIG_NET_SLIP is not set
# CONFIG_PIPES is not set
# CONFIG_PM is not set
# CONFIG_POWER is not set
@ -464,49 +469,9 @@ CONFIG_USART1_2STOP=0
#
# Networking Support
#
CONFIG_ARCH_HAVE_NET=y
# CONFIG_ARCH_HAVE_NET is not set
# CONFIG_ARCH_HAVE_PHY is not set
CONFIG_NET=y
# CONFIG_NET_NOINTS is not set
CONFIG_NET_MULTIBUFFER=y
# CONFIG_NET_PROMISCUOUS is not set
# CONFIG_NET_IPv6 is not set
CONFIG_NSOCKET_DESCRIPTORS=10
CONFIG_NET_NACTIVESOCKETS=16
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_BUFSIZE=650
# CONFIG_NET_TCPURGDATA is not set
#
# TCP/IP Networking
#
CONFIG_NET_TCP=y
CONFIG_NET_TCP_CONNS=40
CONFIG_NET_MAX_LISTENPORTS=40
CONFIG_NET_TCP_READAHEAD_BUFSIZE=562
CONFIG_NET_NTCP_READAHEAD_BUFFERS=8
CONFIG_NET_TCP_RECVDELAY=0
# CONFIG_NET_TCPBACKLOG is not set
# CONFIG_NET_TCP_SPLIT is not set
# CONFIG_NET_SENDFILE is not set
#
# UDP Networking
#
CONFIG_NET_UDP=y
# CONFIG_NET_UDP_CHECKSUMS is not set
CONFIG_NET_UDP_CONNS=8
# CONFIG_NET_BROADCAST is not set
# CONFIG_NET_RXAVAIL is not set
CONFIG_NET_ICMP=y
CONFIG_NET_ICMP_PING=y
# CONFIG_NET_PINGADDRCONF is not set
# CONFIG_NET_IGMP is not set
# CONFIG_NET_STATISTICS is not set
CONFIG_NET_RECEIVE_WINDOW=562
CONFIG_NET_ARPTAB_SIZE=16
# CONFIG_NET_ARP_IPIN is not set
# CONFIG_NET_ROUTE is not set
# CONFIG_NET is not set
#
# File Systems
@ -520,7 +485,6 @@ CONFIG_NET_ARPTAB_SIZE=16
# CONFIG_FS_WRITABLE is not set
# CONFIG_FS_RAMMAP is not set
# CONFIG_FS_FAT is not set
# CONFIG_NFS is not set
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
# CONFIG_FS_SMARTFS is not set
@ -638,7 +602,6 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
# CONFIG_EXAMPLES_MM is not set
# CONFIG_EXAMPLES_MODBUS is not set
# CONFIG_EXAMPLES_MOUNT is not set
# CONFIG_EXAMPLES_NETTEST is not set
# CONFIG_EXAMPLES_NRF24L01TERM is not set
CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_NULL is not set
@ -668,12 +631,10 @@ CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_TIFF is not set
# CONFIG_EXAMPLES_TOUCHSCREEN is not set
# CONFIG_EXAMPLES_UDP is not set
# CONFIG_EXAMPLES_DISCOVER is not set
# CONFIG_EXAMPLES_UIP is not set
# CONFIG_EXAMPLES_USBSERIAL is not set
# CONFIG_EXAMPLES_USBTERM is not set
# CONFIG_EXAMPLES_WATCHDOG is not set
# CONFIG_EXAMPLES_XMLRPC is not set
#
# Graphics Support
@ -709,9 +670,6 @@ CONFIG_NETUTILS_TFTPC=y
CONFIG_NETUTILS_UIPLIB=y
CONFIG_NETUTILS_WEBCLIENT=y
CONFIG_NSH_WGET_USERAGENT="NuttX/6.xx.x (; http://www.nuttx.org/)"
# CONFIG_NETUTILS_WEBSERVER is not set
# CONFIG_NETUTILS_DISCOVER is not set
# CONFIG_NETUTILS_XMLRPC is not set
#
# FreeModBus
@ -789,12 +747,6 @@ CONFIG_NSH_CONSOLE=y
#
# CONFIG_NSH_CONDEV is not set
# CONFIG_NSH_ARCHINIT is not set
# CONFIG_NSH_TELNET is not set
CONFIG_NSH_IPADDR=0xc0a80232
CONFIG_NSH_DRIPADDR=0xc0a80201
CONFIG_NSH_NETMASK=0xffffff00
CONFIG_NSH_NOMAC=y
CONFIG_NSH_MAX_ROUNDTRIP=20
#
# NxWidgets/NxWM

View File

@ -40,12 +40,16 @@ CFLAGS += -I$(TOPDIR)/sched
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = stm32_boot.c stm32_spi.c
CSRCS = stm32_boot.c stm32_leds.c stm32_spi.c
ifeq ($(CONFIG_CAN),y)
CSRCS += stm32_can.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += stm32_buttons.c
endif
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)

View File

@ -78,4 +78,8 @@ void stm32_boardinitialize(void)
stm32_spiinitialize();
}
#endif
/* Configure on-board LEDs (unconditionally). */
stm32_ledinit();
}

View File

@ -0,0 +1,167 @@
/****************************************************************************
* configs/viewtool-stm32f107/src/stm32_buttons.c
*
* Copyright (C) 2013 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 <arch/board/board.h>
#include "viewtool_stm32f107.h"
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/* Pin configuration for each STM3210E-EVAL button. This array is indexed by
* the BUTTON_* and JOYSTICK_* definitions in board.h
*/
static const uint16_t g_buttons[NUM_BUTTONS] =
{
GPIO_SW2, GPIO_SW3, GPIO_SW4
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_buttoninit
*
* Description:
* up_buttoninit() must be called to initialize button resources. After
* that, up_buttons() may be called to collect the current state of all
* buttons or up_irqbutton() may be called to register button interrupt
* handlers.
*
****************************************************************************/
void up_buttoninit(void)
{
int i;
/* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
* configured for some pins but NOT used in this file
*/
for (i = 0; i < NUM_BUTTONS; i++)
{
stm32_configgpio(g_buttons[i]);
}
}
/****************************************************************************
* Name: up_buttons
****************************************************************************/
uint8_t up_buttons(void)
{
uint8_t ret = 0;
int i;
/* Check that state of each key */
for (i = 0; i < NUM_BUTTONS; i++)
{
/* A LOW value means that the key is pressed for most keys. The exception
* is the WAKEUP button.
*/
bool released = stm32_gpioread(g_buttons[i]);
/* Accumulate the set of depressed (not released) keys */
if (!released)
{
ret |= (1 << i);
}
}
return ret;
}
/************************************************************************************
* Button support.
*
* Description:
* up_buttoninit() must be called to initialize button resources. After
* that, up_buttons() may be called to collect the current state of all
* buttons or up_irqbutton() may be called to register button interrupt
* handlers.
*
* After up_buttoninit() has been called, up_buttons() may be called to
* collect the state of all buttons. up_buttons() returns an 8-bit bit set
* with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT
* definitions in board.h for the meaning of each bit.
*
* up_irqbutton() may be called to register an interrupt handler that will
* be called when a button is depressed or released. The ID value is a
* button enumeration value that uniquely identifies a button resource. See the
* BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration
* value. The previous interrupt handler address is returned (so that it may
* restored, if so desired).
*
************************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t up_irqbutton(int id, xcpt_t irqhandler)
{
xcpt_t oldhandler = NULL;
/* The following should be atomic */
if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON)
{
oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler);
}
return oldhandler;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */

View File

@ -0,0 +1,305 @@
/****************************************************************************
* configs/viewtool-stm32f107/src/stm32_leds.c
*
* Copyright (C) 2013 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 "stm32_gpio.h"
#include "viewtool_stm32f107.h"
/****************************************************************************
* Definitions
****************************************************************************/
/* CONFIG_DEBUG_LEDS enables debug output from this file (needs CONFIG_DEBUG
* with CONFIG_DEBUG_VERBOSE too)
*/
#ifdef CONFIG_DEBUG_LEDS
# define leddbg lldbg
# define ledvdbg llvdbg
#else
# define leddbg(x...)
# define ledvdbg(x...)
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: led_onbits
*
* Description:
* Clear all LEDs to the bit encoded state
*
****************************************************************************/
static void led_onbits(unsigned int clrbits)
{
if ((clrbits & BOARD_LED1_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED1, false);
}
if ((clrbits & BOARD_LED2_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED2, false);
}
if ((clrbits & BOARD_LED3_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED3, false);
}
if ((clrbits & BOARD_LED4_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED4, false);
}
}
/****************************************************************************
* Name: led_offbits
*
* Description:
* Clear all LEDs to the bit encoded state
*
****************************************************************************/
static void led_offbits(unsigned int clrbits)
{
if ((clrbits & BOARD_LED1_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED1, true);
}
if ((clrbits & BOARD_LED2_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED2, true);
}
if ((clrbits & BOARD_LED3_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED3, true);
}
if ((clrbits & BOARD_LED4_BIT) != 0)
{
stm32_gpiowrite(GPIO_LED4, true);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_ledinit
*
* Description:
* Configure LEDs. LEDs are left in the OFF state.
*
****************************************************************************/
void stm32_ledinit(void)
{
/* Configure LED1-4 GPIOs for output. Initial state is OFF */
stm32_configgpio(GPIO_LED1);
stm32_configgpio(GPIO_LED2);
stm32_configgpio(GPIO_LED3);
stm32_configgpio(GPIO_LED4);
}
/****************************************************************************
* Name: up_ledon
*
* Description:
* Select the "logical" ON state:
*
* SYMBOL Val Meaning LED state
* LED1 LED2 LED3 LED4
* ----------------- --- ----------------------- ---- ---- ---- ----
* LED_STARTED 0 NuttX has been started ON OFF OFF OFF
* LED_HEAPALLOCATE 1 Heap has been allocated OFF ON OFF OFF
* LED_IRQSENABLED 2 Interrupts enabled ON ON OFF OFF
* LED_STACKCREATED 3 Idle stack created OFF OFF ON OFF
* LED_INIRQ 4 In an interrupt N/C N/C N/C GLOW
* LED_SIGNAL 4 In a signal handler N/C N/C N/C GLOW
* LED_ASSERTION 4 An assertion failed N/C N/C N/C GLOW
* LED_PANIC 4 The system has crashed N/C N/C N/C FLASH
* ED_IDLE MCU is is sleep mode Not used
*
****************************************************************************/
#ifdef CONFIG_ARCH_LEDS
void up_ledon(int led)
{
switch (led)
{
case 0:
led_offbits(BOARD_LED2_BIT | BOARD_LED3_BIT |BOARD_LED4_BIT);
led_onbits(BOARD_LED1_BIT);
break;
case 1:
led_offbits(BOARD_LED1_BIT | BOARD_LED3_BIT |BOARD_LED4_BIT);
led_onbits(BOARD_LED2_BIT);
break;
case 2:
led_offbits(BOARD_LED3_BIT |BOARD_LED4_BIT);
led_onbits(BOARD_LED1_BIT | BOARD_LED2_BIT);
break;
case 3:
led_offbits(BOARD_LED1_BIT | BOARD_LED2_BIT |BOARD_LED4_BIT);
led_onbits(BOARD_LED3_BIT);
break;
case 4:
stm32_gpiowrite(GPIO_LED4, false);
break;
}
}
#endif
/****************************************************************************
* Name: up_ledoff
*
* Description:
* Select the "logical" OFF state:
*
* SYMBOL Val Meaning LED state
* LED1 LED2 LED3 LED4
* ----------------- --- ----------------------- ---- ---- ---- ----
* LED_STARTED 0 NuttX has been started ON OFF OFF OFF
* LED_HEAPALLOCATE 1 Heap has been allocated OFF ON OFF OFF
* LED_IRQSENABLED 2 Interrupts enabled ON ON OFF OFF
* LED_STACKCREATED 3 Idle stack created OFF OFF ON OFF
* LED_INIRQ 4 In an interrupt N/C N/C N/C GLOW
* LED_SIGNAL 4 In a signal handler N/C N/C N/C GLOW
* LED_ASSERTION 4 An assertion failed N/C N/C N/C GLOW
* LED_PANIC 4 The system has crashed N/C N/C N/C FLASH
* ED_IDLE MCU is is sleep mode Not used
*
****************************************************************************/
#ifdef CONFIG_ARCH_LEDS
void up_ledoff(int led)
{
switch (led)
{
case 0:
case 1:
case 2:
case 3:
break;
case 4:
stm32_gpiowrite(GPIO_LED4, true);
break;
}
}
#endif
/************************************************************************************
* Name: stm32_setled, and stm32_setleds
*
* Description:
* These interfaces allow user control of the board LEDs.
*
* If CONFIG_ARCH_LEDS is defined, then NuttX will control both on-board LEDs up
* until the completion of boot. The it will continue to control LED2; LED1 is
* avaiable for application use.
*
* If CONFIG_ARCH_LEDS is not defined, then both LEDs are available for application
* use.
*
************************************************************************************/
void stm32_setled(int led, bool ledon)
{
uint32_t pinset;
switch (led)
{
case BOARD_LED1:
pinset = GPIO_LED1;
break;
case BOARD_LED2:
pinset = GPIO_LED2;
break;
case BOARD_LED3:
pinset = GPIO_LED3;
break;
case BOARD_LED4:
#ifndef CONFIG_ARCH_LEDS
pinset = GPIO_LED4;
break;
#endif
default:
return;
}
stm32_gpiowrite(pinset, !ledon);
}
void stm32_setleds(uint8_t ledset)
{
#ifdef CONFIG_ARCH_LEDS
led_offbits(ledset & ~BOARD_LED4_BIT);
led_offbits(~(ledset | BOARD_LED4_BIT));
#else
led_offbits(ledset);
led_offbits(~ledset);
#endif
}

View File

@ -46,13 +46,53 @@
/******************************************************************************
* Pre-processor Definitions
******************************************************************************/
/* LEDs
*
* There are four LEDs on the ViewTool STM32F103/F107 board that can be controlled
* by software: LED1 through LED4. All pulled high and can be illuminated by
* driving the output to low
*
* LED1 PA6
* LED2 PA7
* LED3 PB12
* LED4 PB13
*/
#ifndef __ASSEMBLY__
#define GPIO_LED1 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz|\
GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN6)
#define GPIO_LED2 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz|\
GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN7)
#define GPIO_LED3 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz|\
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN12)
#define GPIO_LED4 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz|\
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN13)
/* Buttons **************************************************************************/
/* All pulled high and will be sensed low when depressed.
*
* SW2 PC11 Needs J42 closed
* SW3 PC12 Needs J43 closed
* SW4 PA0 Needs J44 closed
*/
#define MIN_IRQBUTTON BUTTON_SW2
#define MAX_IRQBUTTON BUTTON_SW4
#define NUM_IRQBUTTONS (BUTTON_SW4 - BUTTON_SW2 + 1)
#define GPIO_SW2 (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \
GPIO_EXTI | GPIO_PORTC | GPIO_PIN11)
#define GPIO_SW3 (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \
GPIO_EXTI | GPIO_PORTC | GPIO_PIN12)
#define GPIO_SW4 (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \
GPIO_EXTI | GPIO_PORTA | GPIO_PIN10)
/************************************************************************************
* Public Functions
************************************************************************************/
#ifndef __ASSEMBLY__
/************************************************************************************
* Name: stm32_spiinitialize
*
@ -63,5 +103,15 @@
void weak_function stm32_spiinitialize(void);
/****************************************************************************
* Name: up_ledinit
*
* Description:
* Configure LEDs. LEDs are left in the OFF state.
*
****************************************************************************/
void stm32_ledinit(void);
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_VIEWTOOLS_STM32F107_SRC_INTERNAL_H */