mirror of https://github.com/ARMmbed/mbed-os.git
STM32: common pinmap using LL layer to access registers
this first makes pinmap.c a common file then rework it with several goals: - avoid gpio / irq / pin management extra dependencies - improve performances when switching between pin modes This change is based on LL layer to access to registers level instead of using HAL higher level API. The family specific functions are implemented in pin_device.h of each family. Mostly this is F1 family that is differnt from other ones.pull/3665/head
parent
dce2ca75d8
commit
21bc5af3c2
|
|
@ -36,54 +36,118 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define STM_PIN_DATA(MODE, PUPD, AFNUM) ((int)(((MODE & 0x0F) << 0) |\
|
||||
((PUPD & 0x07) << 4) |\
|
||||
((AFNUM & 0x0F) << 7)))
|
||||
/* STM PIN data as used in pin_function is coded on 32 bits as below
|
||||
* [2:0] Function (like in MODER reg) : Input / Output / Alt / Analog
|
||||
* [3] Output Push-Pull / Open Drain (as in OTYPER reg)
|
||||
* [5:4] as in PUPDR reg: No Pull, Pull-up, Pull-Donc
|
||||
* [7:6] Reserved for speed config (as in OSPEEDR), but not used yet
|
||||
* [11:8] Alternate Num (as in AFRL/AFRG reg)
|
||||
* [16:12] Channel (Analog/Timer specific)
|
||||
* [17] Inverted (Analog/Timer specific)
|
||||
* [18] Analog ADC control - Only valid for specific families
|
||||
* [32:19] Reserved
|
||||
*/
|
||||
|
||||
#define STM_PIN_DATA_EXT(MODE, PUPD, AFNUM, CHANNEL, INVERTED) ((int)(((MODE & 0x0F) << 0) |\
|
||||
((PUPD & 0x07) << 4) |\
|
||||
((AFNUM & 0x0F) << 7) |\
|
||||
((CHANNEL & 0x1F) << 11) |\
|
||||
((INVERTED & 0x01) << 16)))
|
||||
#define STM_PIN_FUNCTION_MASK 0x07
|
||||
#define STM_PIN_FUNCTION_SHIFT 0
|
||||
#define STM_PIN_FUNCTION_BITS (STM_PIN_FUNCTION_MASK << STM_PIN_FUNCTION_SHIFT)
|
||||
|
||||
#define STM_PIN_MODE(X) (((X) >> 0) & 0x0F)
|
||||
#define STM_PIN_PUPD(X) (((X) >> 4) & 0x07)
|
||||
#define STM_PIN_AFNUM(X) (((X) >> 7) & 0x0F)
|
||||
#define STM_PIN_CHANNEL(X) (((X) >> 11) & 0x1F)
|
||||
#define STM_PIN_INVERTED(X) (((X) >> 16) & 0x01)
|
||||
#define STM_PIN_OD_MASK 0x01
|
||||
#define STM_PIN_OD_SHIFT 3
|
||||
#define STM_PIN_OD_BITS (STM_PIN_OD_MASK << STM_PIN_OD_SHIFT)
|
||||
|
||||
#define STM_MODE_INPUT (0)
|
||||
#define STM_MODE_OUTPUT_PP (1)
|
||||
#define STM_MODE_OUTPUT_OD (2)
|
||||
#define STM_MODE_AF_PP (3)
|
||||
#define STM_MODE_AF_OD (4)
|
||||
#define STM_MODE_ANALOG (5)
|
||||
#define STM_MODE_IT_RISING (6)
|
||||
#define STM_MODE_IT_FALLING (7)
|
||||
#define STM_MODE_IT_RISING_FALLING (8)
|
||||
#define STM_MODE_EVT_RISING (9)
|
||||
#define STM_MODE_EVT_FALLING (10)
|
||||
#define STM_MODE_EVT_RISING_FALLING (11)
|
||||
#define STM_MODE_IT_EVT_RESET (12)
|
||||
// The last mode is only valid for specific families, so we put it in the end
|
||||
#define STM_MODE_ANALOG_ADC_CONTROL (13)
|
||||
#define STM_PIN_PUPD_MASK 0x03
|
||||
#define STM_PIN_PUPD_SHIFT 4
|
||||
#define STM_PIN_PUPD_BITS (STM_PIN_PUPD_MASK << STM_PIN_PUPD_SHIFT)
|
||||
|
||||
#define STM_PIN_SPEED_MASK 0x03
|
||||
#define STM_PIN_SPEED_SHIFT 6
|
||||
#define STM_PIN_SPEED_BITS (STM_PIN_SPEED_MASK << STM_PIN_SPEED_SHIFT)
|
||||
|
||||
#define STM_PIN_AFNUM_MASK 0x0F
|
||||
#define STM_PIN_AFNUM_SHIFT 8
|
||||
#define STM_PIN_AFNUM_BITS (STM_PIN_AFNUM_MASK << STM_PIN_AFNUM_SHIFT)
|
||||
|
||||
#define STM_PIN_CHAN_MASK 0x1F
|
||||
#define STM_PIN_CHAN_SHIFT 12
|
||||
#define STM_PIN_CHANNEL_BIT (STM_PIN_CHAN_MASK << STM_PIN_CHAN_SHIFT)
|
||||
|
||||
#define STM_PIN_INV_MASK 0x01
|
||||
#define STM_PIN_INV_SHIFT 17
|
||||
#define STM_PIN_INV_BIT (STM_PIN_INV_MASK << STM_PIN_INV_SHIFT)
|
||||
|
||||
#define STM_PIN_AN_CTRL_MASK 0x01
|
||||
#define STM_PIN_AN_CTRL_SHIFT 18
|
||||
#define STM_PIN_ANALOG_CONTROL_BIT (STM_PIN_AN_CTRL_MASK << STM_PIN_AN_CTRL_SHIFT)
|
||||
|
||||
#define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
|
||||
#define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
|
||||
#define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
|
||||
#define STM_PIN_SPEED(X) (((X) >> STM_PIN_SPEED_SHIFT) & STM_PIN_SPEED_MASK)
|
||||
#define STM_PIN_AFNUM(X) (((X) >> STM_PIN_AFNUM_SHIFT) & STM_PIN_AFNUM_MASK)
|
||||
#define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
|
||||
#define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
|
||||
#define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
|
||||
|
||||
#define STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM) ((int)(FUNC_OD) |\
|
||||
((PUPD & STM_PIN_PUPD_MASK) << STM_PIN_PUPD_SHIFT) |\
|
||||
((AFNUM & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT))
|
||||
|
||||
#define STM_PIN_DEFINE_EXT(FUNC_OD, PUPD, AFNUM, CHAN, INV) \
|
||||
((int)(FUNC_OD) |\
|
||||
((PUPD & STM_PIN_PUPD_MASK) << STM_PIN_PUPD_SHIFT) |\
|
||||
((AFNUM & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT) |\
|
||||
((CHAN & STM_PIN_CHAN_MASK) << STM_PIN_CHAN_SHIFT) |\
|
||||
((INV & STM_PIN_INV_MASK) << STM_PIN_INV_SHIFT))
|
||||
|
||||
/*
|
||||
* MACROS to support the legacy definition of PIN formats
|
||||
* The STM_MODE_ defines contain the function and the Push-pull/OpenDrain
|
||||
* configuration (legacy inheritance).
|
||||
*/
|
||||
#define STM_PIN_DATA(FUNC_OD, PUPD, AFNUM) \
|
||||
STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM)
|
||||
#define STM_PIN_DATA_EXT(FUNC_OD, PUPD, AFNUM, CHANNEL, INVERTED) \
|
||||
STM_PIN_DEFINE_EXT(FUNC_OD, PUPD, AFNUM, CHANNEL, INVERTED)
|
||||
|
||||
typedef enum {
|
||||
STM_PIN_INPUT = 0,
|
||||
STM_PIN_OUTPUT = 1,
|
||||
STM_PIN_ALTERNATE = 2,
|
||||
STM_PIN_ANALOG = 3,
|
||||
} StmPinFunction;
|
||||
|
||||
#define STM_MODE_INPUT (STM_PIN_INPUT)
|
||||
#define STM_MODE_OUTPUT_PP (STM_PIN_OUTPUT)
|
||||
#define STM_MODE_OUTPUT_OD (STM_PIN_OUTPUT | STM_PIN_OD_BITS)
|
||||
#define STM_MODE_AF_PP (STM_PIN_ALTERNATE)
|
||||
#define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
|
||||
#define STM_MODE_ANALOG (STM_PIN_ANALOG)
|
||||
#define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
|
||||
|
||||
// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
|
||||
// Low nibble = pin number
|
||||
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
|
||||
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
|
||||
|
||||
/* Defines to be used by application */
|
||||
typedef enum {
|
||||
PIN_INPUT,
|
||||
PIN_INPUT = 0,
|
||||
PIN_OUTPUT
|
||||
} PinDirection;
|
||||
|
||||
typedef enum {
|
||||
PullNone = 0,
|
||||
PullUp = 1,
|
||||
PullDown = 2,
|
||||
OpenDrain = 3,
|
||||
PullDefault = PullNone
|
||||
PullNone = 0,
|
||||
PullUp = 1,
|
||||
PullDown = 2,
|
||||
OpenDrainPullUp = 3,
|
||||
OpenDrainNoPull = 4,
|
||||
OpenDrainPullDown = 5,
|
||||
PushPullNoPull = PullNone,
|
||||
PushPullPullUp = PullUp,
|
||||
PushPullPullDown = PullDown,
|
||||
OpenDrain = OpenDrainPullUp,
|
||||
PullDefault = PullNone
|
||||
} PinMode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -91,3 +155,4 @@ typedef enum {
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "stm32f0xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset IT and EVT (not in STM32Cube HAL)
|
||||
};
|
||||
|
||||
extern GPIO_TypeDef *Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
GPIO_TypeDef *gpio = Set_GPIO_Clock(port_index);
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect SWDIO and SWCLK signals ?
|
||||
// Warning: For debugging it is necessary to reconnect under reset if this is done.
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
GPIO_TypeDef *gpio = Set_GPIO_Clock(port_index);
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "stm32f1xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
// Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
if ((pin == PA_13) || (pin == PA_14)) {
|
||||
__HAL_AFIO_REMAP_SWJ_DISABLE(); // JTAG-DP Disabled and SW-DP Disabled
|
||||
}
|
||||
if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG(); // JTAG-DP Disabled and SW-DP enabled
|
||||
}
|
||||
}
|
||||
|
||||
/* The AF selection of F1 family is specific compared to others */
|
||||
static inline void stm_pin_SetAFPin(GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
// Enable AFIO clock
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
|
||||
if (afnum > 0) {
|
||||
switch (afnum) {
|
||||
case 1: // Remap SPI1
|
||||
__HAL_AFIO_REMAP_SPI1_ENABLE();
|
||||
break;
|
||||
case 2: // Remap I2C1
|
||||
__HAL_AFIO_REMAP_I2C1_ENABLE();
|
||||
break;
|
||||
case 3: // Remap USART1
|
||||
__HAL_AFIO_REMAP_USART1_ENABLE();
|
||||
break;
|
||||
case 4: // Remap USART2
|
||||
__HAL_AFIO_REMAP_USART2_ENABLE();
|
||||
break;
|
||||
case 5: // Partial Remap USART3
|
||||
__HAL_AFIO_REMAP_USART3_PARTIAL();
|
||||
break;
|
||||
case 6: // Partial Remap TIM1
|
||||
__HAL_AFIO_REMAP_TIM1_PARTIAL();
|
||||
break;
|
||||
case 7: // Partial Remap TIM3
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||
break;
|
||||
case 8: // Full Remap TIM2
|
||||
__HAL_AFIO_REMAP_TIM2_ENABLE();
|
||||
break;
|
||||
case 9: // Full Remap TIM3
|
||||
__HAL_AFIO_REMAP_TIM3_ENABLE();
|
||||
break;
|
||||
#if defined(AFIO_MAPR_CAN_REMAP_REMAP1)
|
||||
case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9
|
||||
__HAL_AFIO_REMAP_CAN1_2();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
uint32_t function = LL_GPIO_GetPinMode(gpio, ll_pin);
|
||||
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
if (function == LL_GPIO_MODE_FLOATING)
|
||||
LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT);
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
if (function == LL_GPIO_MODE_FLOATING)
|
||||
LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT);
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
/* Input+NoPull = Floating for F1 family */
|
||||
if (function == LL_GPIO_MODE_INPUT)
|
||||
LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_FLOATING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,252 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
// Warning: the elements order must be the same as the one defined in PinNames.h
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
GPIO_MODE_INPUT, // 0 = STM_MODE_INPUT
|
||||
GPIO_MODE_OUTPUT_PP, // 1 = STM_MODE_OUTPUT_PP
|
||||
GPIO_MODE_OUTPUT_OD, // 2 = STM_MODE_OUTPUT_OD
|
||||
GPIO_MODE_AF_PP, // 3 = STM_MODE_AF_PP
|
||||
GPIO_MODE_AF_OD, // 4 = STM_MODE_AF_OD
|
||||
GPIO_MODE_ANALOG, // 5 = STM_MODE_ANALOG
|
||||
GPIO_MODE_IT_RISING, // 6 = STM_MODE_IT_RISING
|
||||
GPIO_MODE_IT_FALLING, // 7 = STM_MODE_IT_FALLING
|
||||
GPIO_MODE_IT_RISING_FALLING, // 8 = STM_MODE_IT_RISING_FALLING
|
||||
GPIO_MODE_EVT_RISING, // 9 = STM_MODE_EVT_RISING
|
||||
GPIO_MODE_EVT_FALLING, // 10 = STM_MODE_EVT_FALLING
|
||||
GPIO_MODE_EVT_RISING_FALLING, // 11 = STM_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = STM_MODE_IT_EVT_RESET (not in STM32Cube HAL)
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (input, output, alternate function or analog) + output speed + AF
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Enable AFIO clock
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
|
||||
// Configure Alternate Function
|
||||
// Warning: Must be done before the GPIO is initialized
|
||||
if (afnum > 0) {
|
||||
switch (afnum) {
|
||||
case 1: // Remap SPI1
|
||||
__HAL_AFIO_REMAP_SPI1_ENABLE();
|
||||
break;
|
||||
case 2: // Remap I2C1
|
||||
__HAL_AFIO_REMAP_I2C1_ENABLE();
|
||||
break;
|
||||
case 3: // Remap USART1
|
||||
__HAL_AFIO_REMAP_USART1_ENABLE();
|
||||
break;
|
||||
case 4: // Remap USART2
|
||||
__HAL_AFIO_REMAP_USART2_ENABLE();
|
||||
break;
|
||||
case 5: // Partial Remap USART3
|
||||
__HAL_AFIO_REMAP_USART3_PARTIAL();
|
||||
break;
|
||||
case 6: // Partial Remap TIM1
|
||||
__HAL_AFIO_REMAP_TIM1_PARTIAL();
|
||||
break;
|
||||
case 7: // Partial Remap TIM3
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||
break;
|
||||
case 8: // Full Remap TIM2
|
||||
__HAL_AFIO_REMAP_TIM2_ENABLE();
|
||||
break;
|
||||
case 9: // Full Remap TIM3
|
||||
__HAL_AFIO_REMAP_TIM3_ENABLE();
|
||||
break;
|
||||
case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9
|
||||
__HAL_AFIO_REMAP_CAN1_2();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
if ((pin == PA_13) || (pin == PA_14)) {
|
||||
__HAL_AFIO_REMAP_SWJ_DISABLE(); // JTAG-DP Disabled and SW-DP Disabled
|
||||
}
|
||||
if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG(); // JTAG-DP Disabled and SW-DP enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
__IO uint32_t* gpio_reg_hl;//gpio register depends on bit index (high or low)
|
||||
uint32_t shift;
|
||||
|
||||
if (pin_index < 8) {
|
||||
shift = (pin_index * 4);
|
||||
gpio_reg_hl = &(gpio->CRL);
|
||||
} else {
|
||||
shift = (pin_index % 8) * 4;
|
||||
gpio_reg_hl = &(gpio->CRH);
|
||||
}
|
||||
|
||||
// Configure open-drain and pull-up/down
|
||||
switch (mode) {
|
||||
case PullNone:
|
||||
break;
|
||||
case PullUp:
|
||||
case PullDown:
|
||||
// Set pull-up / pull-down for Input mode
|
||||
if ((*gpio_reg_hl & (0x03 << shift)) == 0) { // MODE bits = Input mode
|
||||
*gpio_reg_hl |= (0x08 << shift); // Set pull-up / pull-down
|
||||
*gpio_reg_hl &= ~(0x04 << shift); // ENSURES GPIOx_CRL.CNFx.bit0 = 0
|
||||
}
|
||||
// Now it's time to setup properly if pullup or pulldown. This is done in ODR register:
|
||||
// set pull-up => bit=1, set pull-down => bit = 0
|
||||
if (mode == PullUp) {
|
||||
gpio->ODR |= (0x01 << (pin_index)); // Set pull-up
|
||||
} else {
|
||||
gpio->ODR &= ~(0x01 << (pin_index)); // Set pull-down
|
||||
}
|
||||
break;
|
||||
case OpenDrain:
|
||||
// Set open-drain for Output mode (General Purpose or Alternate Function)
|
||||
if ((*gpio_reg_hl & (0x03 << shift)) > 0) { // MODE bits = Output mode
|
||||
*gpio_reg_hl |= (0x04 << shift); // Set open-drain
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode)
|
||||
{
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t pull = PullNone;
|
||||
__IO uint32_t* gpio_reg_hl;//gpio register depends on bit index (high or low)
|
||||
uint32_t shift;
|
||||
|
||||
if (pin_index < 8) {
|
||||
shift = (pin_index * 4);
|
||||
gpio_reg_hl = &(gpio->CRL);
|
||||
} else {
|
||||
shift = (pin_index % 8) * 4;
|
||||
gpio_reg_hl = &(gpio->CRH);
|
||||
}
|
||||
|
||||
/* Check if pull/pull down is active */
|
||||
if (!(*gpio_reg_hl & (0x03 << shift))) {// input
|
||||
if((!!(*gpio_reg_hl & (0x08 << shift))) // pull-up / down
|
||||
&& (!(*gpio_reg_hl & (0x04 << shift)))) { // GPIOx_CRL.CNFx.bit0 = 0
|
||||
if (!!(gpio->ODR & (0x01 << pin_index))) {
|
||||
pull = PullUp;
|
||||
} else {
|
||||
pull = PullDown;
|
||||
}
|
||||
}
|
||||
} else { //output
|
||||
if (!!(*gpio_reg_hl & (0x04 << shift))) { //open drain
|
||||
pull = OpenDrain;
|
||||
}
|
||||
}
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
// when LL is available, below include can be used
|
||||
// #include "stm32f2xx_ll_gpio.h"
|
||||
// until then let's define locally the required functions
|
||||
#define LL_GPIO_PIN_0 GPIO_BSRR_BS0 /*!< Select pin 0 */
|
||||
#define LL_GPIO_PIN_1 GPIO_BSRR_BS1 /*!< Select pin 1 */
|
||||
#define LL_GPIO_PIN_2 GPIO_BSRR_BS2 /*!< Select pin 2 */
|
||||
#define LL_GPIO_PIN_3 GPIO_BSRR_BS3 /*!< Select pin 3 */
|
||||
#define LL_GPIO_PIN_4 GPIO_BSRR_BS4 /*!< Select pin 4 */
|
||||
#define LL_GPIO_PIN_5 GPIO_BSRR_BS5 /*!< Select pin 5 */
|
||||
#define LL_GPIO_PIN_6 GPIO_BSRR_BS6 /*!< Select pin 6 */
|
||||
#define LL_GPIO_PIN_7 GPIO_BSRR_BS7 /*!< Select pin 7 */
|
||||
#define LL_GPIO_PIN_8 GPIO_BSRR_BS8 /*!< Select pin 8 */
|
||||
#define LL_GPIO_PIN_9 GPIO_BSRR_BS9 /*!< Select pin 9 */
|
||||
#define LL_GPIO_PIN_10 GPIO_BSRR_BS10 /*!< Select pin 10 */
|
||||
#define LL_GPIO_PIN_11 GPIO_BSRR_BS11 /*!< Select pin 11 */
|
||||
#define LL_GPIO_PIN_12 GPIO_BSRR_BS12 /*!< Select pin 12 */
|
||||
#define LL_GPIO_PIN_13 GPIO_BSRR_BS13 /*!< Select pin 13 */
|
||||
#define LL_GPIO_PIN_14 GPIO_BSRR_BS14 /*!< Select pin 14 */
|
||||
#define LL_GPIO_PIN_15 GPIO_BSRR_BS15 /*!< Select pin 15 */
|
||||
|
||||
#define LL_GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Select input mode */
|
||||
#define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODE0_0 /*!< Select output mode */
|
||||
#define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODE0_1 /*!< Select alternate function mode */
|
||||
#define LL_GPIO_MODE_ANALOG GPIO_MODER_MODE0 /*!< Select analog mode */
|
||||
|
||||
#define LL_GPIO_OUTPUT_PUSHPULL ((uint32_t)0x00000000U) /*!< Select push-pull as output type */
|
||||
#define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT0 /*!< Select open-drain as output type */
|
||||
|
||||
#define LL_GPIO_PULL_NO ((uint32_t)0x00000000U) /*!< Select I/O no pull */
|
||||
#define LL_GPIO_PULL_UP GPIO_PUPDR_PUPD0_0 /*!< Select I/O pull up */
|
||||
#define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPD0_1 /*!< Select I/O pull down */
|
||||
|
||||
#define LL_GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000U) /*!< Select I/O low output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDER_OSPEEDR0_0 /*!< Select I/O medium output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDER_OSPEEDR0_1 /*!< Select I/O fast output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDER_OSPEEDR0 /*!< Select I/O high output speed */
|
||||
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[0], (GPIO_AFRL_AFSEL0 << (POSITION_VAL(Pin) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin) * 4U)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[1], (GPIO_AFRH_AFSEL8 << (POSITION_VAL(Pin >> 8U) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin >> 8U) * 4U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
|
||||
{
|
||||
MODIFY_REG(GPIOx->MODER, (GPIO_MODER_MODE0 << (POSITION_VAL(Pin) * 2U)), (Mode << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin)
|
||||
{
|
||||
return (uint32_t)(READ_BIT(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODER0)) / (Pin * Pin));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
|
||||
{
|
||||
MODIFY_REG(GPIOx->PUPDR, (GPIO_PUPDR_PUPD0 << (POSITION_VAL(Pin) * 2U)), (Pull << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U)),
|
||||
(Speed << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
// Above lines shall be defined in LL when available
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset GPIO_MODE_IT_EVT
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#if defined GPIOD_BASE
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOE_BASE
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOF_BASE
|
||||
case PortF:
|
||||
gpio_add = GPIOF_BASE;
|
||||
__GPIOF_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOG_BASE
|
||||
case PortG:
|
||||
gpio_add = GPIOG_BASE;
|
||||
__GPIOG_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOH_BASE
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOI_BASE
|
||||
case PortI:
|
||||
gpio_add = GPIOI_BASE;
|
||||
__GPIOI_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOJ_BASE
|
||||
case PortJ:
|
||||
gpio_add = GPIOJ_BASE;
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOK_BASE
|
||||
case PortK:
|
||||
gpio_add = GPIOK_BASE;
|
||||
__GPIOK_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) {
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
#include "stm32f3xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
// Warning: the elements order must be the same as the one defined in PinNames.h
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
GPIO_MODE_INPUT, // 0 = STM_MODE_INPUT
|
||||
GPIO_MODE_OUTPUT_PP, // 1 = STM_MODE_OUTPUT_PP
|
||||
GPIO_MODE_OUTPUT_OD, // 2 = STM_MODE_OUTPUT_OD
|
||||
GPIO_MODE_AF_PP, // 3 = STM_MODE_AF_PP
|
||||
GPIO_MODE_AF_OD, // 4 = STM_MODE_AF_OD
|
||||
GPIO_MODE_ANALOG, // 5 = STM_MODE_ANALOG
|
||||
GPIO_MODE_IT_RISING, // 6 = STM_MODE_IT_RISING
|
||||
GPIO_MODE_IT_FALLING, // 7 = STM_MODE_IT_FALLING
|
||||
GPIO_MODE_IT_RISING_FALLING, // 8 = STM_MODE_IT_RISING_FALLING
|
||||
GPIO_MODE_EVT_RISING, // 9 = STM_MODE_EVT_RISING
|
||||
GPIO_MODE_EVT_FALLING, // 10 = STM_MODE_EVT_FALLING
|
||||
GPIO_MODE_EVT_RISING_FALLING, // 11 = STM_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = STM_MODE_IT_EVT_RESET (not in STM32Cube HAL)
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#if defined GPIOE_BASE
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOF_BASE
|
||||
case PortF:
|
||||
gpio_add = GPIOF_BASE;
|
||||
__GPIOF_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOG_BASE
|
||||
case PortG:
|
||||
gpio_add = GPIOG_BASE;
|
||||
__GPIOG_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOH_BASE
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOI_BASE
|
||||
case PortI:
|
||||
gpio_add = GPIOI_BASE;
|
||||
__GPIOI_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOJ_BASE
|
||||
case PortJ:
|
||||
gpio_add = GPIOJ_BASE;
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOK_BASE
|
||||
case PortK:
|
||||
gpio_add = GPIOK_BASE;
|
||||
__GPIOK_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) {
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
// when LL is available, below include can be used
|
||||
// #include "stm32f4xx_ll_gpio.h"
|
||||
// until then let's define locally the required functions
|
||||
#define LL_GPIO_PIN_0 GPIO_BSRR_BS_0 /*!< Select pin 0 */
|
||||
#define LL_GPIO_PIN_1 GPIO_BSRR_BS_1 /*!< Select pin 1 */
|
||||
#define LL_GPIO_PIN_2 GPIO_BSRR_BS_2 /*!< Select pin 2 */
|
||||
#define LL_GPIO_PIN_3 GPIO_BSRR_BS_3 /*!< Select pin 3 */
|
||||
#define LL_GPIO_PIN_4 GPIO_BSRR_BS_4 /*!< Select pin 4 */
|
||||
#define LL_GPIO_PIN_5 GPIO_BSRR_BS_5 /*!< Select pin 5 */
|
||||
#define LL_GPIO_PIN_6 GPIO_BSRR_BS_6 /*!< Select pin 6 */
|
||||
#define LL_GPIO_PIN_7 GPIO_BSRR_BS_7 /*!< Select pin 7 */
|
||||
#define LL_GPIO_PIN_8 GPIO_BSRR_BS_8 /*!< Select pin 8 */
|
||||
#define LL_GPIO_PIN_9 GPIO_BSRR_BS_9 /*!< Select pin 9 */
|
||||
#define LL_GPIO_PIN_10 GPIO_BSRR_BS_10 /*!< Select pin 10 */
|
||||
#define LL_GPIO_PIN_11 GPIO_BSRR_BS_11 /*!< Select pin 11 */
|
||||
#define LL_GPIO_PIN_12 GPIO_BSRR_BS_12 /*!< Select pin 12 */
|
||||
#define LL_GPIO_PIN_13 GPIO_BSRR_BS_13 /*!< Select pin 13 */
|
||||
#define LL_GPIO_PIN_14 GPIO_BSRR_BS_14 /*!< Select pin 14 */
|
||||
#define LL_GPIO_PIN_15 GPIO_BSRR_BS_15 /*!< Select pin 15 */
|
||||
|
||||
#define LL_GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Select input mode */
|
||||
#define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODER0_0 /*!< Select output mode */
|
||||
#define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODER0_1 /*!< Select alternate function mode */
|
||||
#define LL_GPIO_MODE_ANALOG GPIO_MODER_MODER0 /*!< Select analog mode */
|
||||
|
||||
#define LL_GPIO_OUTPUT_PUSHPULL ((uint32_t)0x00000000U) /*!< Select push-pull as output type */
|
||||
#define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT_0 /*!< Select open-drain as output type */
|
||||
|
||||
#define LL_GPIO_PULL_NO ((uint32_t)0x00000000U) /*!< Select I/O no pull */
|
||||
#define LL_GPIO_PULL_UP GPIO_PUPDR_PUPDR0_0 /*!< Select I/O pull up */
|
||||
#define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPDR0_1 /*!< Select I/O pull down */
|
||||
|
||||
#define LL_GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000U) /*!< Select I/O low output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDER_OSPEEDR0_0 /*!< Select I/O medium output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDER_OSPEEDR0_1 /*!< Select I/O fast output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDER_OSPEEDR0 /*!< Select I/O high output speed */
|
||||
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[0], (0xFU << (POSITION_VAL(Pin) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin) * 4U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[1], (0xFU << (POSITION_VAL(Pin >> 8U) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin >> 8U) * 4U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
|
||||
{
|
||||
MODIFY_REG(GPIOx->MODER, (GPIO_MODER_MODER0 << (POSITION_VAL(Pin) * 2U)), (Mode << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin)
|
||||
{
|
||||
return (uint32_t)(READ_BIT(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODER0)) / (Pin * Pin));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
|
||||
{
|
||||
MODIFY_REG(GPIOx->PUPDR, (GPIO_PUPDR_PUPDR0 << (POSITION_VAL(Pin) * 2U)), (Pull << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U)),
|
||||
(Speed << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
// Above lines shall be defined in LL when available
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset GPIO_MODE_IT_EVT
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#if defined GPIOD_BASE
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOE_BASE
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOF_BASE
|
||||
case PortF:
|
||||
gpio_add = GPIOF_BASE;
|
||||
__GPIOF_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOG_BASE
|
||||
case PortG:
|
||||
gpio_add = GPIOG_BASE;
|
||||
__GPIOG_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOH_BASE
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOI_BASE
|
||||
case PortI:
|
||||
gpio_add = GPIOI_BASE;
|
||||
__GPIOI_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOJ_BASE
|
||||
case PortJ:
|
||||
gpio_add = GPIOJ_BASE;
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOK_BASE
|
||||
case PortK:
|
||||
gpio_add = GPIOK_BASE;
|
||||
__GPIOK_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) {
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
// when LL is available, below include can be used
|
||||
// #include "stm32f7xx_ll_gpio.h"
|
||||
// until then let's define locally the required functions
|
||||
#define LL_GPIO_PIN_0 GPIO_BSRR_BS_0 /*!< Select pin 0 */
|
||||
#define LL_GPIO_PIN_1 GPIO_BSRR_BS_1 /*!< Select pin 1 */
|
||||
#define LL_GPIO_PIN_2 GPIO_BSRR_BS_2 /*!< Select pin 2 */
|
||||
#define LL_GPIO_PIN_3 GPIO_BSRR_BS_3 /*!< Select pin 3 */
|
||||
#define LL_GPIO_PIN_4 GPIO_BSRR_BS_4 /*!< Select pin 4 */
|
||||
#define LL_GPIO_PIN_5 GPIO_BSRR_BS_5 /*!< Select pin 5 */
|
||||
#define LL_GPIO_PIN_6 GPIO_BSRR_BS_6 /*!< Select pin 6 */
|
||||
#define LL_GPIO_PIN_7 GPIO_BSRR_BS_7 /*!< Select pin 7 */
|
||||
#define LL_GPIO_PIN_8 GPIO_BSRR_BS_8 /*!< Select pin 8 */
|
||||
#define LL_GPIO_PIN_9 GPIO_BSRR_BS_9 /*!< Select pin 9 */
|
||||
#define LL_GPIO_PIN_10 GPIO_BSRR_BS_10 /*!< Select pin 10 */
|
||||
#define LL_GPIO_PIN_11 GPIO_BSRR_BS_11 /*!< Select pin 11 */
|
||||
#define LL_GPIO_PIN_12 GPIO_BSRR_BS_12 /*!< Select pin 12 */
|
||||
#define LL_GPIO_PIN_13 GPIO_BSRR_BS_13 /*!< Select pin 13 */
|
||||
#define LL_GPIO_PIN_14 GPIO_BSRR_BS_14 /*!< Select pin 14 */
|
||||
#define LL_GPIO_PIN_15 GPIO_BSRR_BS_15 /*!< Select pin 15 */
|
||||
|
||||
#define LL_GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Select input mode */
|
||||
#define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODER0_0 /*!< Select output mode */
|
||||
#define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODER0_1 /*!< Select alternate function mode */
|
||||
#define LL_GPIO_MODE_ANALOG GPIO_MODER_MODER0 /*!< Select analog mode */
|
||||
|
||||
#define LL_GPIO_OUTPUT_PUSHPULL ((uint32_t)0x00000000U) /*!< Select push-pull as output type */
|
||||
#define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT_0 /*!< Select open-drain as output type */
|
||||
|
||||
#define LL_GPIO_PULL_NO ((uint32_t)0x00000000U) /*!< Select I/O no pull */
|
||||
#define LL_GPIO_PULL_UP GPIO_PUPDR_PUPDR0_0 /*!< Select I/O pull up */
|
||||
#define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPDR0_1 /*!< Select I/O pull down */
|
||||
|
||||
#define LL_GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000U) /*!< Select I/O low output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDER_OSPEEDR0_0 /*!< Select I/O medium output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDER_OSPEEDR0_1 /*!< Select I/O fast output speed */
|
||||
#define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDER_OSPEEDR0 /*!< Select I/O high output speed */
|
||||
|
||||
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[0], (0xFU << (POSITION_VAL(Pin) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin) * 4U)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
|
||||
{
|
||||
MODIFY_REG(GPIOx->AFR[1], (0xFU << (POSITION_VAL(Pin >> 8U) * 4U)),
|
||||
(Alternate << (POSITION_VAL(Pin >> 8U) * 4U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
|
||||
{
|
||||
MODIFY_REG(GPIOx->MODER, (GPIO_MODER_MODER0 << (POSITION_VAL(Pin) * 2U)), (Mode << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin)
|
||||
{
|
||||
return (uint32_t)(READ_BIT(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODER0)) / (Pin * Pin));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
|
||||
{
|
||||
MODIFY_REG(GPIOx->PUPDR, (GPIO_PUPDR_PUPDR0 << (POSITION_VAL(Pin) * 2U)), (Pull << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType));
|
||||
}
|
||||
__STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
|
||||
{
|
||||
MODIFY_REG(GPIOx->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U)),
|
||||
(Speed << (POSITION_VAL(Pin) * 2U)));
|
||||
}
|
||||
// Above lines shall be defined in LL when available
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,196 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset GPIO_MODE_IT_EVT
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#if defined GPIOD_BASE
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOE_BASE
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOF_BASE
|
||||
case PortF:
|
||||
gpio_add = GPIOF_BASE;
|
||||
__GPIOF_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOG_BASE
|
||||
case PortG:
|
||||
gpio_add = GPIOG_BASE;
|
||||
__GPIOG_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOH_BASE
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOI_BASE
|
||||
case PortI:
|
||||
gpio_add = GPIOI_BASE;
|
||||
__GPIOI_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOJ_BASE
|
||||
case PortJ:
|
||||
gpio_add = GPIOJ_BASE;
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined GPIOK_BASE
|
||||
case PortK:
|
||||
gpio_add = GPIOK_BASE;
|
||||
__GPIOK_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "stm32l0xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
// Warning: order must be the same as the one defined in PinNames.h !!!
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset IT and EVT (not in STM32Cube HAL)
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
#if defined(GPIOC_BASE)
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOD_BASE)
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOH_BASE)
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2)
|
||||
{
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPD0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPD0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "stm32l1xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
static const uint32_t gpio_mode[13] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000 // 12 = Reset IT and EVT (not in STM32Cube HAL)
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2)
|
||||
{
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2016, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef MBED_PIN_DEVICE_H
|
||||
#define MBED_PIN_DEVICE_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "stm32l4xx_ll_gpio.h"
|
||||
|
||||
extern const uint32_t ll_pin_defines[16];
|
||||
|
||||
/* Family specific implementations */
|
||||
static inline void stm_pin_DisconnectDebug(PinName pin)
|
||||
{
|
||||
/* empty for now */
|
||||
}
|
||||
|
||||
static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config)
|
||||
{
|
||||
switch (pull_config)
|
||||
{
|
||||
case GPIO_PULLUP:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP);
|
||||
break;
|
||||
case GPIO_PULLDOWN:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN);
|
||||
break;
|
||||
case GPIO_NOPULL:
|
||||
LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum)
|
||||
{
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
|
||||
if (STM_PIN(pin) > 7)
|
||||
LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum);
|
||||
else
|
||||
LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
// GPIO mode look-up table
|
||||
// Warning: order must be the same as the one defined in PinNames.h !!!
|
||||
static const uint32_t gpio_mode[14] = {
|
||||
0x00000000, // 0 = GPIO_MODE_INPUT
|
||||
0x00000001, // 1 = GPIO_MODE_OUTPUT_PP
|
||||
0x00000011, // 2 = GPIO_MODE_OUTPUT_OD
|
||||
0x00000002, // 3 = GPIO_MODE_AF_PP
|
||||
0x00000012, // 4 = GPIO_MODE_AF_OD
|
||||
0x00000003, // 5 = GPIO_MODE_ANALOG
|
||||
0x10110000, // 6 = GPIO_MODE_IT_RISING
|
||||
0x10210000, // 7 = GPIO_MODE_IT_FALLING
|
||||
0x10310000, // 8 = GPIO_MODE_IT_RISING_FALLING
|
||||
0x10120000, // 9 = GPIO_MODE_EVT_RISING
|
||||
0x10220000, // 10 = GPIO_MODE_EVT_FALLING
|
||||
0x10320000, // 11 = GPIO_MODE_EVT_RISING_FALLING
|
||||
0x10000000, // 12 = Reset IT and EVT (not in STM32Cube HAL)
|
||||
0x0000000B //13 = GPIO_MODE_ANALOG_ADC_CONTROL
|
||||
};
|
||||
|
||||
// Enable GPIO clock and return GPIO base address
|
||||
uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
||||
{
|
||||
uint32_t gpio_add = 0;
|
||||
switch (port_idx) {
|
||||
case PortA:
|
||||
gpio_add = GPIOA_BASE;
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
break;
|
||||
case PortB:
|
||||
gpio_add = GPIOB_BASE;
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#if defined(GPIOD_BASE)
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOE_BASE)
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
break;
|
||||
default:
|
||||
error("Pinmap error: wrong port number\n");
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
|
||||
GPIO_InitStructure.Mode = gpio_mode[mode];
|
||||
GPIO_InitStructure.Pull = pupd;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStructure.Alternate = afnum;
|
||||
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
|
||||
// [TODO] Disconnect JTAG-DP + SW-DP signals.
|
||||
// Warning: Need to reconnect under reset
|
||||
//if ((pin == PA_13) || (pin == PA_14)) {
|
||||
//
|
||||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Enable GPIO clock
|
||||
uint32_t gpio_add = Set_GPIO_Clock(port_index);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) {
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
}
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
}
|
||||
|
||||
/* Internal function for setting the gpiomode/function
|
||||
* without changing Pull mode
|
||||
*/
|
||||
void pin_function_gpiomode(PinName pin, uint32_t gpiomode) {
|
||||
|
||||
/* Read current pull state from HW to avoid over-write*/
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *) Set_GPIO_Clock(port_index);
|
||||
uint32_t temp = gpio->PUPDR;
|
||||
uint32_t pull = (temp >> (pin_index * 2U)) & GPIO_PUPDR_PUPDR0;
|
||||
|
||||
/* Then re-use global function for updating the mode part*/
|
||||
pin_function(pin, STM_PIN_DATA(gpiomode, pull, 0));
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of STMicroelectronics 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 HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "mbed_error.h"
|
||||
#include "pin_device.h"
|
||||
|
||||
extern GPIO_TypeDef *Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
const uint32_t ll_pin_defines[16] =
|
||||
{
|
||||
LL_GPIO_PIN_0,
|
||||
LL_GPIO_PIN_1,
|
||||
LL_GPIO_PIN_2,
|
||||
LL_GPIO_PIN_3,
|
||||
LL_GPIO_PIN_4,
|
||||
LL_GPIO_PIN_5,
|
||||
LL_GPIO_PIN_6,
|
||||
LL_GPIO_PIN_7,
|
||||
LL_GPIO_PIN_8,
|
||||
LL_GPIO_PIN_9,
|
||||
LL_GPIO_PIN_10,
|
||||
LL_GPIO_PIN_11,
|
||||
LL_GPIO_PIN_12,
|
||||
LL_GPIO_PIN_13,
|
||||
LL_GPIO_PIN_14,
|
||||
LL_GPIO_PIN_15
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_FUNCTION(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
uint32_t port = STM_PORT(pin);
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
uint32_t ll_mode = 0;
|
||||
|
||||
// Enable GPIO clock
|
||||
GPIO_TypeDef *gpio = Set_GPIO_Clock(port);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case STM_PIN_INPUT:
|
||||
ll_mode = LL_GPIO_MODE_INPUT;
|
||||
break;
|
||||
case STM_PIN_OUTPUT:
|
||||
ll_mode = LL_GPIO_MODE_OUTPUT;
|
||||
break;
|
||||
case STM_PIN_ALTERNATE:
|
||||
ll_mode = LL_GPIO_MODE_ALTERNATE;
|
||||
// In case of ALT function, also set he afnum
|
||||
stm_pin_SetAFPin(gpio, pin, afnum);
|
||||
break;
|
||||
case STM_PIN_ANALOG:
|
||||
ll_mode = LL_GPIO_MODE_ANALOG;
|
||||
break;
|
||||
default:
|
||||
MBED_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
LL_GPIO_SetPinMode(gpio, ll_pin, ll_mode);
|
||||
|
||||
#if defined(GPIO_ASCR_ASC0)
|
||||
/* For families where Analog Control ASC0 register is present */
|
||||
if (STM_PIN_ANALOG_CONTROL(data))
|
||||
{
|
||||
LL_GPIO_EnablePinAnalogControl(gpio, ll_pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_GPIO_DisablePinAnalogControl(gpio, ll_pin);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For now by default use Speed HIGH for output or alt modes */
|
||||
if ((mode == STM_PIN_OUTPUT) ||(mode == STM_PIN_ALTERNATE)) {
|
||||
LL_GPIO_SetPinSpeed(gpio, ll_pin, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
if (STM_PIN_OD(data))
|
||||
LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_OPENDRAIN);
|
||||
else
|
||||
LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
}
|
||||
|
||||
stm_pin_PullConfig(gpio, ll_pin, STM_PIN_PUPD(data));
|
||||
|
||||
stm_pin_DisconnectDebug(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode)
|
||||
{
|
||||
MBED_ASSERT(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)];
|
||||
// Enable GPIO clock
|
||||
GPIO_TypeDef *gpio = Set_GPIO_Clock(port_index);
|
||||
uint32_t function = LL_GPIO_GetPinMode(gpio, ll_pin);
|
||||
|
||||
if ((function == LL_GPIO_MODE_OUTPUT) || (function == LL_GPIO_MODE_ALTERNATE))
|
||||
{
|
||||
if ((mode == OpenDrainNoPull) || (mode == OpenDrainPullUp) || (mode == OpenDrainPullDown))
|
||||
{
|
||||
LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_OPENDRAIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mode == OpenDrainPullUp) || (mode == PullUp))
|
||||
{
|
||||
stm_pin_PullConfig(gpio, ll_pin, GPIO_PULLUP);
|
||||
}
|
||||
else if ((mode == OpenDrainPullDown) || (mode == PullDown))
|
||||
{
|
||||
stm_pin_PullConfig(gpio, ll_pin, GPIO_PULLDOWN);
|
||||
}
|
||||
else
|
||||
{
|
||||
stm_pin_PullConfig(gpio, ll_pin, GPIO_NOPULL);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue