nuttx/arch/arm/src/stm32f0l0/stm32_gpio.c

456 lines
13 KiB
C
Raw Normal View History

2017-04-14 16:06:01 +02:00
/****************************************************************************
* arch/arm/src/stm32f0l0/stm32_gpio.c
2017-04-14 16:06:01 +02:00
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Alan Carvalho de Assis <acassis@gmail.com>
2017-04-14 16:06:01 +02:00
*
* 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 <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <arch/irq.h>
#include <arch/stm32f0l0/chip.h>
2017-04-14 16:06:01 +02:00
#include "up_arch.h"
#include "chip.h"
#include "stm32_gpio.h"
2017-04-14 16:06:01 +02:00
#if defined(CONFIG_STM32F0L0_HAVE_IP_EXTI_V1)
# include "hardware/stm32_syscfg.h"
#elif defined(CONFIG_STM32F0L0_HAVE_IP_EXTI_V2)
# include "hardware/stm32_exti.h"
#endif
2017-04-14 16:06:01 +02:00
/****************************************************************************
* Public Data
****************************************************************************/
/* Base addresses for each GPIO block */
const uint32_t g_gpiobase[STM32_NPORTS] =
2017-04-14 16:06:01 +02:00
{
#if STM32_NPORTS > 0
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
STM32_GPIOA_BASE, /* One GPIO ports, GPIOA */
2017-04-14 16:06:01 +02:00
#endif
#if STM32_NPORTS > 1
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
STM32_GPIOB_BASE, /* Two GPIO ports, GPIOA-B */
2017-04-14 16:06:01 +02:00
#endif
#if STM32_NPORTS > 2
STM32_GPIOC_BASE, /* Three GPIO ports, GPIOA-C*/
2017-04-14 16:06:01 +02:00
#endif
#if STM32_NPORTS > 3
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
STM32_GPIOD_BASE, /* Four GPIO ports, GPIOA-D */
2017-04-14 16:06:01 +02:00
#endif
#if defined(STM32_GPIOE_BASE)
STM32_GPIOE_BASE, /* GPIOE */
#endif
#if defined(STM32_GPIOF_BASE)
STM32_GPIOF_BASE, /* GPIOF */
2017-04-14 16:06:01 +02:00
#endif
#if defined(STM32_GPIOH_BASE)
STM32_GPIOH_BASE, /* GPIOH */
2017-04-14 16:06:01 +02:00
#endif
};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: stm32_gpioinit
2017-04-14 16:06:01 +02:00
*
* Description:
* Based on configuration within the .config file, it does:
* - Remaps positions of alternative functions.
*
* Typically called from stm32_start().
2017-04-14 16:06:01 +02:00
*
* Assumptions:
* This function is called early in the initialization sequence so that
* no mutual exlusion is necessary.
*
****************************************************************************/
void stm32_gpioinit(void)
2017-04-14 16:06:01 +02:00
{
}
/****************************************************************************
* Name: stm32_configgpio
2017-04-14 16:06:01 +02:00
*
* Description:
* Configure a GPIO pin based on bit-encoded description of the pin.
* Once it is configured as Alternative (GPIO_ALT|GPIO_CNF_AFPP|...)
* function, it must be unconfigured with stm32_unconfiggpio() with
2017-04-14 16:06:01 +02:00
* the same cfgset first before it can be set to non-alternative function.
*
* Returned Value:
2017-04-14 16:06:01 +02:00
* OK on success
* A negated errono valu on invalid port, or when pin is locked as ALT
* function.
*
* To-Do: Auto Power Enable
****************************************************************************/
int stm32_configgpio(uint32_t cfgset)
2017-04-14 16:06:01 +02:00
{
uintptr_t base;
uint32_t regval;
uint32_t setting;
unsigned int regoffset;
unsigned int port;
unsigned int pin;
unsigned int pos;
unsigned int pinmode;
irqstate_t flags;
/* Verify that this hardware supports the select GPIO port */
port = (cfgset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
if (port >= STM32_NPORTS)
2017-04-14 16:06:01 +02:00
{
return -EINVAL;
}
/* Get the port base address */
base = g_gpiobase[port];
/* Get the pin number and select the port configuration register for that
* pin
*/
pin = (cfgset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
/* Set up the mode register (and remember whether the pin mode) */
switch (cfgset & GPIO_MODE_MASK)
{
default:
case GPIO_INPUT: /* Input mode */
pinmode = GPIO_MODER_INPUT;
break;
case GPIO_OUTPUT: /* General purpose output mode */
stm32_gpiowrite(cfgset, (cfgset & GPIO_OUTPUT_SET) != 0); /* Set the initial output value */
2017-04-14 16:06:01 +02:00
pinmode = GPIO_MODER_OUTPUT;
break;
case GPIO_ALT: /* Alternate function mode */
pinmode = GPIO_MODER_ALT;
break;
case GPIO_ANALOG: /* Analog mode */
pinmode = GPIO_MODER_ANALOG;
break;
}
/* Interrupts must be disabled from here on out so that we have mutually
* exclusive access to all of the GPIO configuration registers.
*/
flags = enter_critical_section();
/* Now apply the configuration to the mode register */
regval = getreg32(base + STM32_GPIO_MODER_OFFSET);
2017-04-14 16:06:01 +02:00
regval &= ~GPIO_MODER_MASK(pin);
regval |= ((uint32_t)pinmode << GPIO_MODER_SHIFT(pin));
putreg32(regval, base + STM32_GPIO_MODER_OFFSET);
2017-04-14 16:06:01 +02:00
/* Set up the pull-up/pull-down configuration (all but analog pins) */
setting = GPIO_PUPDR_NONE;
if (pinmode != GPIO_MODER_ANALOG)
{
switch (cfgset & GPIO_PUPD_MASK)
{
default:
case GPIO_FLOAT: /* No pull-up, pull-down */
break;
case GPIO_PULLUP: /* Pull-up */
setting = GPIO_PUPDR_PULLUP;
break;
case GPIO_PULLDOWN: /* Pull-down */
setting = GPIO_PUPDR_PULLDOWN;
break;
}
}
regval = getreg32(base + STM32_GPIO_PUPDR_OFFSET);
2017-04-14 16:06:01 +02:00
regval &= ~GPIO_PUPDR_MASK(pin);
regval |= (setting << GPIO_PUPDR_SHIFT(pin));
putreg32(regval, base + STM32_GPIO_PUPDR_OFFSET);
2017-04-14 16:06:01 +02:00
/* Set the alternate function (Only alternate function pins) */
if (pinmode == GPIO_MODER_ALT)
{
setting = (cfgset & GPIO_AF_MASK) >> GPIO_AF_SHIFT;
}
else
{
setting = 0;
}
if (pin < 8)
{
regoffset = STM32_GPIO_AFRL_OFFSET;
2017-04-14 16:06:01 +02:00
pos = pin;
}
else
{
regoffset = STM32_GPIO_AFRH_OFFSET;
2017-04-14 16:06:01 +02:00
pos = pin - 8;
}
regval = getreg32(base + regoffset);
regval &= ~GPIO_AFR_MASK(pos);
regval |= (setting << GPIO_AFR_SHIFT(pos));
putreg32(regval, base + regoffset);
/* Set speed (Only outputs and alternate function pins) */
if (pinmode == GPIO_MODER_OUTPUT || pinmode == GPIO_MODER_ALT)
{
switch (cfgset & GPIO_SPEED_MASK)
{
default:
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
#if defined(STM32_GPIO_VERY_LOW_SPEED)
case GPIO_SPPED_VERYLOW: /* Very Low speed output */
setting = GPIO_OSPEED_VERYLOW;
2017-04-14 16:06:01 +02:00
break;
case GPIO_SPEED_LOW: /* Low speed output */
setting = GPIO_OSPEED_LOW;
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
break;
case GPIO_SPEED_MEDIUM: /* Medium speed output */
setting = GPIO_OSPEED_MEDIUM;
2017-04-14 16:06:01 +02:00
break;
case GPIO_SPEED_HIGH: /* High speed output */
setting = GPIO_OSPEED_HIGH;
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
break;
#else
case GPIO_SPEED_LOW: /* Low speed output */
setting = GPIO_OSPEED_LOW;
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
break;
case GPIO_SPEED_MEDIUM: /* Medium speed output */
setting = GPIO_OSPEED_MEDIUM;
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
break;
case GPIO_SPEED_HIGH: /* High speed output */
setting = GPIO_OSPEED_HIGH;
2017-04-14 16:06:01 +02:00
break;
Brings in initial WIP support for the STML0. This initial commit is in pretty bad shape and, hence it it marked EXPERIMENTAL." Squashed commit of the following: arch/arm/src/stm32f0l0: Various changes for a clean compilation. Still does not compile correctly due to missing FLASH latency definitions. arch/arm/src/stm32f0l0/hardware: Add framework for the STM32 L0. Currently set to same as the STM32F0. arch/arm/src/stm32f0l0/hardware: Very fragmentary FLASH header register definitions for the STM32 L0. arch/arm/src/stm32f0l0: Bring in DMA v1. Cannot possibly be functionaly yet due to the limited number for M0 interrupts. arch/arm/src/stm32f0l0: Add STM32 F0/L0 LSE and backup power domain controls. arch/arm/src/stm32f0l0/hardware/stm32l0_pwr.h: Add STM32L0 PWR header file. arch/arm/include/stm32f0l0/chip.h: Clean up WIP chip header file. arch/arm/include/stm32f0l0/chip.h: WIP. arm/src/stm32f0l0: Resolve some small differences between F0 and L0 GPIO pin options. arch/arm/src/stm32f0l0: Better integrate STM32L0 header files. nuttx/arch/arm/include/stm32f0l0: Add STM32L0 IRQ number definition file. arch/arm/src/stm32f0l0: Add STM32L0 RCC driver. arch/arm/src/stm32f0l0/hardware: Adds basic STM32L0 header files. arch/arm/src/stm32f0l0: Add STM32L0 chip selections. configs/: Hook new STM32L0 boards into the configuration system. configs: nucleo boards use as default ST LINK MCO as clock input from MCU and for this HSEBYP must be enabled configs: add basic support for nucleo-l073rz configs: add basic support for b-l072z-lrwan1
2018-12-19 19:36:35 +01:00
#endif
2017-04-14 16:06:01 +02:00
}
}
else
{
setting = 0;
}
regval = getreg32(base + STM32_GPIO_OSPEED_OFFSET);
2017-04-14 16:06:01 +02:00
regval &= ~GPIO_OSPEED_MASK(pin);
regval |= (setting << GPIO_OSPEED_SHIFT(pin));
putreg32(regval, base + STM32_GPIO_OSPEED_OFFSET);
2017-04-14 16:06:01 +02:00
/* Set push-pull/open-drain (Only outputs and alternate function pins) */
regval = getreg32(base + STM32_GPIO_OTYPER_OFFSET);
2017-04-14 16:06:01 +02:00
setting = GPIO_OTYPER_OD(pin);
if ((pinmode == GPIO_MODER_OUTPUT || pinmode == GPIO_MODER_ALT) &&
(cfgset & GPIO_OPENDRAIN) != 0)
{
regval |= setting;
}
else
{
regval &= ~setting;
}
putreg32(regval, base + STM32_GPIO_OTYPER_OFFSET);
2017-04-14 16:06:01 +02:00
/* Otherwise, it is an input pin. Should it configured as an EXTI interrupt? */
if ((cfgset & GPIO_EXTI) != 0)
{
uint32_t regaddr;
int shift;
#if defined(CONFIG_STM32F0L0_HAVE_IP_EXTI_V1)
2017-04-14 16:06:01 +02:00
/* Set the bits in the SYSCFG EXTICR register */
regaddr = STM32_SYSCFG_EXTICR(pin);
2017-04-14 16:06:01 +02:00
regval = getreg32(regaddr);
shift = SYSCFG_EXTICR_EXTI_SHIFT(pin);
regval &= ~(SYSCFG_EXTICR_PORT_MASK << shift);
regval |= (((uint32_t)port) << shift);
putreg32(regval, regaddr);
#elif defined(CONFIG_STM32F0L0_HAVE_IP_EXTI_V2)
/* Set the bits in the EXTI EXTICR register */
regaddr = STM32_EXTI_EXTICR(pin);
regval = getreg32(regaddr);
shift = EXTI_EXTICR_EXTI_SHIFT(pin);
regval &= ~(EXTI_EXTICR_PORT_MASK << shift);
regval |= (((uint32_t)port) << shift);
putreg32(regval, regaddr);
#else
# error unknown EXTI IP core
#endif
2017-04-14 16:06:01 +02:00
}
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: stm32_unconfiggpio
2017-04-14 16:06:01 +02:00
*
* Description:
* Unconfigure a GPIO pin based on bit-encoded description of the pin, set it
* into default HiZ state (and possibly mark it's unused) and unlock it whether
* it was previsouly selected as alternative function (GPIO_ALT|GPIO_CNF_AFPP|...).
*
* This is a safety function and prevents hardware from schocks, as unexpected
* write to the Timer Channel Output GPIO to fixed '1' or '0' while it should
* operate in PWM mode could produce excessive on-board currents and trigger
* over-current/alarm function.
*
* Returned Value:
2017-04-14 16:06:01 +02:00
* OK on success
* A negated errno value on invalid port
*
* To-Do: Auto Power Disable
****************************************************************************/
int stm32_unconfiggpio(uint32_t cfgset)
2017-04-14 16:06:01 +02:00
{
/* Reuse port and pin number and set it to default HiZ INPUT */
cfgset &= GPIO_PORT_MASK | GPIO_PIN_MASK;
cfgset |= GPIO_INPUT | GPIO_FLOAT;
/* To-Do: Mark its unuse for automatic power saving options */
return stm32_configgpio(cfgset);
2017-04-14 16:06:01 +02:00
}
/****************************************************************************
* Name: stm32_gpiowrite
2017-04-14 16:06:01 +02:00
*
* Description:
* Write one or zero to the selected GPIO pin
*
****************************************************************************/
void stm32_gpiowrite(uint32_t pinset, bool value)
2017-04-14 16:06:01 +02:00
{
uint32_t base;
uint32_t bit;
unsigned int port;
unsigned int pin;
port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
if (port < STM32_NPORTS)
2017-04-14 16:06:01 +02:00
{
/* Get the port base address */
base = g_gpiobase[port];
/* Get the pin number */
pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
/* Set or clear the output on the pin */
if (value)
{
bit = GPIO_BSRR_SET(pin);
}
else
{
bit = GPIO_BSRR_RESET(pin);
}
putreg32(bit, base + STM32_GPIO_BSRR_OFFSET);
2017-04-14 16:06:01 +02:00
}
}
/****************************************************************************
* Name: stm32_gpioread
2017-04-14 16:06:01 +02:00
*
* Description:
* Read one or zero from the selected GPIO pin
*
****************************************************************************/
bool stm32_gpioread(uint32_t pinset)
2017-04-14 16:06:01 +02:00
{
uint32_t base;
unsigned int port;
unsigned int pin;
port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
if (port < STM32_NPORTS)
2017-04-14 16:06:01 +02:00
{
/* Get the port base address */
base = g_gpiobase[port];
/* Get the pin number and return the input state of that pin */
pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
return ((getreg32(base + STM32_GPIO_IDR_OFFSET) & (1 << pin)) != 0);
2017-04-14 16:06:01 +02:00
}
return 0;
}