2011-11-22 21:07:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/stm32/stm32_gpio.c
|
|
|
|
*
|
2016-02-14 02:11:09 +01:00
|
|
|
* Copyright (C) 2009, 2011, 2016 Gregory Nutt. All rights reserved.
|
2011-11-22 21:07:42 +01:00
|
|
|
* 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 <sys/types.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2016-02-15 02:58:30 +01:00
|
|
|
#include <nuttx/irq.h>
|
2011-11-22 21:07:42 +01:00
|
|
|
|
2016-02-14 02:11:09 +01:00
|
|
|
#include "up_arch.h"
|
2011-11-22 21:07:42 +01:00
|
|
|
#include "chip.h"
|
|
|
|
#include "stm32_gpio.h"
|
|
|
|
#include "stm32_rcc.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
/* Port letters for prettier debug output */
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
static const char g_portchar[STM32_NGPIO_PORTS] =
|
|
|
|
{
|
2015-10-21 04:30:57 +02:00
|
|
|
#if STM32_NGPIO_PORTS > 11
|
2011-11-22 21:07:42 +01:00
|
|
|
# error "Additional support required for this number of GPIOs"
|
2015-10-21 04:30:57 +02:00
|
|
|
#elif STM32_NGPIO_PORTS > 10
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'
|
|
|
|
#elif STM32_NGPIO_PORTS > 9
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'
|
2011-11-22 21:07:42 +01:00
|
|
|
#elif STM32_NGPIO_PORTS > 8
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'
|
|
|
|
#elif STM32_NGPIO_PORTS > 7
|
2012-03-10 01:02:11 +01:00
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
|
2011-11-22 21:07:42 +01:00
|
|
|
#elif STM32_NGPIO_PORTS > 6
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G'
|
|
|
|
#elif STM32_NGPIO_PORTS > 5
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F'
|
|
|
|
#elif STM32_NGPIO_PORTS > 4
|
|
|
|
'A', 'B', 'C', 'D', 'E'
|
|
|
|
#elif STM32_NGPIO_PORTS > 3
|
|
|
|
'A', 'B', 'C', 'D'
|
|
|
|
#elif STM32_NGPIO_PORTS > 2
|
|
|
|
'A', 'B', 'C'
|
|
|
|
#elif STM32_NGPIO_PORTS > 1
|
|
|
|
'A', 'B'
|
|
|
|
#elif STM32_NGPIO_PORTS > 0
|
|
|
|
'A'
|
|
|
|
#else
|
|
|
|
# error "Bad number of GPIOs"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: stm32_dumpgpio
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump all GPIO registers associated with the provided base address
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int stm32_dumpgpio(uint32_t pinset, const char *msg)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
uint32_t base;
|
|
|
|
unsigned int port;
|
|
|
|
|
|
|
|
/* Get the base address associated with the GPIO port */
|
|
|
|
|
|
|
|
port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
|
|
|
|
base = g_gpiobase[port];
|
|
|
|
|
|
|
|
/* The following requires exclusive access to the GPIO registers */
|
|
|
|
|
2016-02-14 02:11:09 +01:00
|
|
|
flags = enter_critical_section();
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2011-11-22 21:07:42 +01:00
|
|
|
#if defined(CONFIG_STM32_STM32F10XX)
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2011-11-22 21:07:42 +01:00
|
|
|
lldbg("GPIO%c pinset: %08x base: %08x -- %s\n",
|
|
|
|
g_portchar[port], pinset, base, msg);
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2011-11-22 21:07:42 +01:00
|
|
|
if ((getreg32(STM32_RCC_APB2ENR) & RCC_APB2ENR_IOPEN(port)) != 0)
|
|
|
|
{
|
|
|
|
lldbg(" CR: %08x %08x IDR: %04x ODR: %04x LCKR: %04x\n",
|
2012-01-10 17:25:52 +01:00
|
|
|
getreg32(base + STM32_GPIO_CRH_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_CRL_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_IDR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_ODR_OFFSET),
|
2011-11-22 21:07:42 +01:00
|
|
|
getreg32(base + STM32_GPIO_LCKR_OFFSET));
|
|
|
|
lldbg(" EVCR: %02x MAPR: %08x CR: %04x %04x %04x %04x\n",
|
|
|
|
getreg32(STM32_AFIO_EVCR), getreg32(STM32_AFIO_MAPR),
|
2012-01-10 17:25:52 +01:00
|
|
|
getreg32(STM32_AFIO_EXTICR1),
|
|
|
|
getreg32(STM32_AFIO_EXTICR2),
|
|
|
|
getreg32(STM32_AFIO_EXTICR3),
|
|
|
|
getreg32(STM32_AFIO_EXTICR4));
|
2011-11-22 21:07:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lldbg(" GPIO%c not enabled: APB2ENR: %08x\n",
|
|
|
|
g_portchar[port], getreg32(STM32_RCC_APB2ENR));
|
|
|
|
}
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2013-05-20 18:08:44 +02:00
|
|
|
#elif defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
|
|
|
|
DEBUGASSERT(port < STM32_NGPIO_PORTS);
|
|
|
|
|
|
|
|
lldbg("GPIO%c pinset: %08x base: %08x -- %s\n",
|
|
|
|
g_portchar[port], pinset, base, msg);
|
|
|
|
|
|
|
|
if ((getreg32(STM32_RCC_AHBENR) & RCC_AHBENR_GPIOEN(port)) != 0)
|
|
|
|
{
|
|
|
|
lldbg(" MODE: %08x OTYPE: %04x OSPEED: %08x PUPDR: %08x\n",
|
|
|
|
getreg32(base + STM32_GPIO_MODER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OTYPER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OSPEED_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_PUPDR_OFFSET));
|
|
|
|
lldbg(" IDR: %04x ODR: %04x BSRR: %08x LCKR: %04x\n",
|
|
|
|
getreg32(base + STM32_GPIO_IDR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_ODR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_BSRR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_LCKR_OFFSET));
|
|
|
|
lldbg(" AFRH: %08x AFRL: %08x\n",
|
|
|
|
getreg32(base + STM32_GPIO_AFRH_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_AFRL_OFFSET));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lldbg(" GPIO%c not enabled: AHBENR: %08x\n",
|
|
|
|
g_portchar[port], getreg32(STM32_RCC_AHBENR));
|
|
|
|
}
|
|
|
|
|
2015-03-02 17:33:42 +01:00
|
|
|
#elif defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX)
|
2013-02-08 15:42:18 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(port < STM32_NGPIO_PORTS);
|
|
|
|
|
|
|
|
lldbg("GPIO%c pinset: %08x base: %08x -- %s\n",
|
|
|
|
g_portchar[port], pinset, base, msg);
|
|
|
|
|
|
|
|
/* GPIOs are always enabled */
|
|
|
|
|
|
|
|
lldbg(" MODE: %08x OTYPE: %04x OSPEED: %08x PUPDR: %08x\n",
|
|
|
|
getreg32(base + STM32_GPIO_MODER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OTYPER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OSPEED_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_PUPDR_OFFSET));
|
|
|
|
lldbg(" IDR: %04x ODR: %04x BSRR: %08x LCKR: %04x\n",
|
|
|
|
getreg32(base + STM32_GPIO_IDR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_ODR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_BSRR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_LCKR_OFFSET));
|
|
|
|
lldbg(" AFRH: %08x AFRL: %08x BRR: %04x\n",
|
2013-05-18 23:32:50 +02:00
|
|
|
getreg32(base + STM32_GPIO_AFRH_OFFSET),
|
2013-02-08 15:42:18 +01:00
|
|
|
getreg32(base + STM32_GPIO_AFRL_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_BRR_OFFSET));
|
|
|
|
|
2012-03-10 01:02:11 +01:00
|
|
|
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2011-11-22 21:07:42 +01:00
|
|
|
DEBUGASSERT(port < STM32_NGPIO_PORTS);
|
|
|
|
|
|
|
|
lldbg("GPIO%c pinset: %08x base: %08x -- %s\n",
|
|
|
|
g_portchar[port], pinset, base, msg);
|
2013-02-08 15:42:18 +01:00
|
|
|
|
2012-01-10 17:25:52 +01:00
|
|
|
if ((getreg32(STM32_RCC_AHB1ENR) & RCC_AHB1ENR_GPIOEN(port)) != 0)
|
2011-11-22 21:07:42 +01:00
|
|
|
{
|
2012-01-10 17:25:52 +01:00
|
|
|
lldbg(" MODE: %08x OTYPE: %04x OSPEED: %08x PUPDR: %08x\n",
|
|
|
|
getreg32(base + STM32_GPIO_MODER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OTYPER_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_OSPEED_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_PUPDR_OFFSET));
|
|
|
|
lldbg(" IDR: %04x ODR: %04x BSRR: %08x LCKR: %04x\n",
|
|
|
|
getreg32(base + STM32_GPIO_IDR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_ODR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_BSRR_OFFSET),
|
|
|
|
getreg32(base + STM32_GPIO_LCKR_OFFSET));
|
2011-11-22 21:07:42 +01:00
|
|
|
lldbg(" AFRH: %08x AFRL: %08x\n",
|
2013-05-18 23:32:50 +02:00
|
|
|
getreg32(base + STM32_GPIO_AFRH_OFFSET),
|
2012-01-10 17:25:52 +01:00
|
|
|
getreg32(base + STM32_GPIO_AFRL_OFFSET));
|
2011-11-22 21:07:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-10 17:25:52 +01:00
|
|
|
lldbg(" GPIO%c not enabled: AHB1ENR: %08x\n",
|
|
|
|
g_portchar[port], getreg32(STM32_RCC_AHB1ENR));
|
2011-11-22 21:07:42 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
# error "Unsupported STM32 chip"
|
|
|
|
#endif
|
2016-02-14 02:11:09 +01:00
|
|
|
leave_critical_section(flags);
|
2011-11-22 21:07:42 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG */
|