From 2c3b61a248dc74a3802dcac5bfb8b62d72333a24 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 2 Nov 2018 15:00:19 +0100 Subject: [PATCH 01/22] Move pin configured functions as macro Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/PinConfigured.c | 46 ----------------------------- cores/arduino/stm32/PinConfigured.h | 10 ++++--- 2 files changed, 6 insertions(+), 50 deletions(-) delete mode 100644 cores/arduino/stm32/PinConfigured.c diff --git a/cores/arduino/stm32/PinConfigured.c b/cores/arduino/stm32/PinConfigured.c deleted file mode 100644 index 024219c512..0000000000 --- a/cores/arduino/stm32/PinConfigured.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - ******************************************************************************* - * Copyright (c) 2017, 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 "PinConfigured.h" - -bool is_pin_configured(PinName pin, uint32_t* map) { - uint32_t index = PINCONF_INDEX(pin); - return PINCONF_VAL(pin, map[index]); -} - -void set_pin_configured(PinName pin, uint32_t* map) { - uint32_t index = PINCONF_INDEX(pin); - map[index] = map[index] | PINCONF_BIT(pin); -} - -void reset_pin_configured(PinName pin, uint32_t* map) { - uint32_t index = PINCONF_INDEX(pin); - map[index] = map[index] & (~PINCONF_BIT(pin)); -} - diff --git a/cores/arduino/stm32/PinConfigured.h b/cores/arduino/stm32/PinConfigured.h index 7b7d393049..5675a86486 100644 --- a/cores/arduino/stm32/PinConfigured.h +++ b/cores/arduino/stm32/PinConfigured.h @@ -44,10 +44,12 @@ extern "C" { #define PINCONF_VAL(X, Y) ((Y >> PINCONF_SHIFT(X)) & PINCONF_MASK) - -bool is_pin_configured(PinName pin, uint32_t* map); -void set_pin_configured(PinName pin, uint32_t* map); -void reset_pin_configured(PinName pin, uint32_t* map); +#define is_pin_configured(pin, map) \ + (PINCONF_VAL(pin, map[PINCONF_INDEX(pin)])) +#define set_pin_configured(pin, map) \ + (map[PINCONF_INDEX(pin)] = map[PINCONF_INDEX(pin)] | PINCONF_BIT(pin)) +#define reset_pin_configured(pin, map) \ + (map[PINCONF_INDEX(pin)] = map[PINCONF_INDEX(pin)] & (~PINCONF_BIT(pin))) #ifdef __cplusplus } From 4fc4add04e8881ebcb5cabd9c1eef03e039d3ad5 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 2 Nov 2018 15:04:31 +0100 Subject: [PATCH 02/22] Remove useless check User have to ensure the pin is configured. Signed-off-by: Frederic.Pillon --- cores/arduino/wiring_digital.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 6619299d2b..448c9064eb 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -72,9 +72,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) { PinName p = digitalPinToPinName(ulPin); if(p != NC) { - if(is_pin_configured(p, g_digPinConfigured)) { - digital_io_write(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p), ulVal); - } + digital_io_write(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p), ulVal); } } @@ -83,9 +81,7 @@ int digitalRead( uint32_t ulPin ) uint8_t level = 0; PinName p = digitalPinToPinName(ulPin); if(p != NC) { - if(is_pin_configured(p, g_digPinConfigured)) { - level = digital_io_read(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p)); - } + level = digital_io_read(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p)); } return (level)? HIGH : LOW; } From b4119c74eebe215893d346974aba22365ef90232 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 2 Nov 2018 17:26:15 +0100 Subject: [PATCH 03/22] Enhance get_GPIO_Port speed Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/PortNames.c | 62 ++++++++------------------------- cores/arduino/stm32/PortNames.h | 6 +++- 2 files changed, 19 insertions(+), 49 deletions(-) diff --git a/cores/arduino/stm32/PortNames.c b/cores/arduino/stm32/PortNames.c index ef193e3c64..87c5378982 100644 --- a/cores/arduino/stm32/PortNames.c +++ b/cores/arduino/stm32/PortNames.c @@ -28,73 +28,40 @@ ******************************************************************************* */ #include "PortNames.h" -#include "stm32_def.h" -// Return GPIO base address -GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) { - GPIO_TypeDef* gpioPort = 0; - switch (port_idx) { - case PortA: - gpioPort = (GPIO_TypeDef *)GPIOA_BASE; - break; - case PortB: - gpioPort = (GPIO_TypeDef *)GPIOB_BASE; - break; +GPIO_TypeDef * GPIOPort[MAX_NB_PORT] = { + (GPIO_TypeDef *)GPIOA_BASE, + (GPIO_TypeDef *)GPIOB_BASE #if defined GPIOC_BASE - case PortC: - gpioPort = (GPIO_TypeDef *)GPIOC_BASE; - break; + ,(GPIO_TypeDef *)GPIOC_BASE #endif #if defined GPIOD_BASE - case PortD: - gpioPort = (GPIO_TypeDef *)GPIOD_BASE; - break; + ,(GPIO_TypeDef *)GPIOD_BASE #endif #if defined GPIOE_BASE - case PortE: - gpioPort = (GPIO_TypeDef *)GPIOE_BASE; - break; + ,(GPIO_TypeDef *)GPIOE_BASE #endif #if defined GPIOF_BASE - case PortF: - gpioPort = (GPIO_TypeDef *)GPIOF_BASE; - break; + ,(GPIO_TypeDef *)GPIOF_BASE #endif #if defined GPIOG_BASE - case PortG: - gpioPort = (GPIO_TypeDef *)GPIOG_BASE; - break; + ,(GPIO_TypeDef *)GPIOG_BASE #endif #if defined GPIOH_BASE - case PortH: - gpioPort = (GPIO_TypeDef *)GPIOH_BASE; - break; + ,(GPIO_TypeDef *)GPIOH_BASE #endif #if defined GPIOI_BASE - case PortI: - gpioPort = (GPIO_TypeDef *)GPIOI_BASE; - break; + ,(GPIO_TypeDef *)GPIOI_BASE #endif #if defined GPIOJ_BASE - case PortJ: - gpioPort = (GPIO_TypeDef *)GPIOJ_BASE; - break; + ,(GPIO_TypeDef *)GPIOJ_BASE #endif #if defined GPIOK_BASE - case PortK: - gpioPort = (GPIO_TypeDef *)GPIOK_BASE; - break; + ,(GPIO_TypeDef *)GPIOK_BASE #endif - default: - // wrong port number - //TBD: error management - gpioPort = 0; - break; - } - return gpioPort; -} +}; -// Enable GPIO clock and return GPIO base address +/* Enable GPIO clock and return GPIO base address */ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) { GPIO_TypeDef* gpioPort = 0; switch (port_idx) { @@ -173,4 +140,3 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) { } return gpioPort; } - diff --git a/cores/arduino/stm32/PortNames.h b/cores/arduino/stm32/PortNames.h index a14d5b7233..d970bd76ad 100644 --- a/cores/arduino/stm32/PortNames.h +++ b/cores/arduino/stm32/PortNames.h @@ -36,6 +36,8 @@ extern "C" { #endif +extern GPIO_TypeDef *GPIOPort[]; + typedef enum { FirstPort = 0x00, PortA = FirstPort, @@ -73,7 +75,9 @@ typedef enum { #define MAX_NB_PORT (LastPort-FirstPort+1) -GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx); +/* Return GPIO base address */ +#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)GPIOA_BASE) +/* Enable GPIO clock and return GPIO base address */ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx); #ifdef __cplusplus From 107ba0baabfcacfd95ca83a6d60902070c62c938 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 2 Nov 2018 17:26:27 +0100 Subject: [PATCH 04/22] Use LL for GPIO access Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.c | 32 ++++---------------------------- cores/arduino/stm32/digital_io.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/cores/arduino/stm32/digital_io.c b/cores/arduino/stm32/digital_io.c index 3824947999..5b5025b4b9 100644 --- a/cores/arduino/stm32/digital_io.c +++ b/cores/arduino/stm32/digital_io.c @@ -57,7 +57,11 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull) GPIO_InitTypeDef GPIO_InitStructure; GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin)); GPIO_InitStructure.Pin = STM_GPIO_PIN(pin); +#ifdef GPIO_SPEED_FREQ_VERY_HIGH + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; +#else GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; +#endif GPIO_InitStructure.Mode = mode; GPIO_InitStructure.Pull = pull; #ifdef STM32F1xx @@ -66,34 +70,6 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull) HAL_GPIO_Init(port, &GPIO_InitStructure); } -/** - * @brief This function set a value to an IO - * @param port : one of the gpio port - * @param pin : one of the gpio pin - * @param val : 0 to set to low, any other value to set to high - * @retval None - */ -void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val) -{ - if(val) { - HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); - } else { - HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); - } -} - - -/** - * @brief This function set a value to an IO - * @param port : one of the gpio port - * @param pin : one of the gpio pin - * @retval The pin state (LOW or HIGH) - */ -uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin) -{ - return (uint32_t)HAL_GPIO_ReadPin(port, pin); -} - #ifdef __cplusplus } #endif diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index 941f3c7c73..8165b6baa0 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -42,6 +42,7 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_def.h" #include "PeripheralPins.h" +#include "stm32yyxx_ll_gpio.h" #ifdef __cplusplus extern "C" { @@ -52,8 +53,34 @@ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull); -void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val); -uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin); + +/** + * @brief This function set a value to an IO + * @param port : one of the gpio port + * @param pin : one of the gpio pin + * @param val : 0 to set to low, any other value to set to high + * @retval None + */ +static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val) +{ + if(val) { + LL_GPIO_SetOutputPin(port, pin); + } else { + LL_GPIO_ResetOutputPin(port, pin); + } +} + + +/** + * @brief This function set a value to an IO + * @param port : one of the gpio port + * @param pin : one of the gpio pin + * @retval The pin state (LOW or HIGH) + */ +static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin) +{ + return LL_GPIO_IsInputPinSet(port, pin); +} #ifdef __cplusplus } From 945093bc81ced1393b3649276e4e4a5ef7cadd1f Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 5 Nov 2018 14:41:32 +0100 Subject: [PATCH 05/22] Add digitalRead/WriteFast API Use the PinName (PY_n) instead of the pin number (Pyn) Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.c | 2 -- cores/arduino/stm32/digital_io.h | 32 +++++++++++++++++++++++++++++--- cores/arduino/wiring_digital.c | 12 ++---------- keywords.txt | 2 ++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/cores/arduino/stm32/digital_io.c b/cores/arduino/stm32/digital_io.c index 5b5025b4b9..6705d59489 100644 --- a/cores/arduino/stm32/digital_io.c +++ b/cores/arduino/stm32/digital_io.c @@ -36,8 +36,6 @@ ****************************************************************************** */ #include "digital_io.h" -#include "stm32_def.h" -#include "hw_config.h" #include "PinAF_STM32F1.h" #ifdef __cplusplus diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index 8165b6baa0..a4ee8fb792 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -40,8 +40,8 @@ #define __DIGITAL_IO_H /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "PeripheralPins.h" +#include "wiring_constants.h" +#include "PinNames.h" #include "stm32yyxx_ll_gpio.h" #ifdef __cplusplus @@ -70,7 +70,6 @@ static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t v } } - /** * @brief This function set a value to an IO * @param port : one of the gpio port @@ -82,6 +81,33 @@ static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin) return LL_GPIO_IsInputPinSet(port, pin); } +/** + * @brief This function set a value to an IO + * @param pn : Pin name + * @param val : 0 to set to low, any other value to set to high + * @retval None + */ +static inline void digitalWriteFast( PinName pn, uint32_t ulVal ) +{ + if(pn != NC) { + digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal); + } +} + +/** + * @brief This function read the value of an IO + * @param pn : Pin name + * @retval The pin state (LOW or HIGH) + */ +static inline int digitalReadFast( PinName pn ) +{ + uint8_t level = 0; + if(pn != NC) { + level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); + } + return (level)? HIGH : LOW; +} + #ifdef __cplusplus } #endif diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 448c9064eb..661acdee83 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -70,20 +70,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) void digitalWrite( uint32_t ulPin, uint32_t ulVal ) { - PinName p = digitalPinToPinName(ulPin); - if(p != NC) { - digital_io_write(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p), ulVal); - } + digitalWriteFast(digitalPinToPinName(ulPin), ulVal); } int digitalRead( uint32_t ulPin ) { - uint8_t level = 0; - PinName p = digitalPinToPinName(ulPin); - if(p != NC) { - level = digital_io_read(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p)); - } - return (level)? HIGH : LOW; + return digitalReadFast(digitalPinToPinName(ulPin)); } #ifdef __cplusplus diff --git a/keywords.txt b/keywords.txt index 13b979ebea..700bdbb123 100644 --- a/keywords.txt +++ b/keywords.txt @@ -350,6 +350,8 @@ portConfigRegister KEYWORD2 digitalPinIsValid KEYWORD2 digitalPinFirstOccurence KEYWORD2 pinIsSerial KEYWORD2 +digitalReadFast KEYWORD2 +digitalWriteFast KEYWORD2 # Pin number PA0 LITERAL1 From b735591f02532fb77516c8dae8f504166bd1d8aa Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 5 Nov 2018 14:41:49 +0100 Subject: [PATCH 06/22] Add missing include Signed-off-by: Frederic.Pillon --- cores/arduino/wiring_constants.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h index 312cabde28..ec4cff2b91 100644 --- a/cores/arduino/wiring_constants.h +++ b/cores/arduino/wiring_constants.h @@ -20,12 +20,14 @@ #define _WIRING_CONSTANTS_ #include +#include #ifdef __cplusplus #include using std::min; using std::max; #else // C +#include #ifndef abs #define abs(x) ((x)>0?(x):-(x)) #endif // abs From 62fd2762cc87540445cb88382a6fa4715cb8ccd4 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 5 Nov 2018 14:42:09 +0100 Subject: [PATCH 07/22] Fix analogInPinToBit macro Signed-off-by: Frederic.Pillon --- cores/arduino/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index b13b9c36e0..de0d05965e 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -232,7 +232,7 @@ uint32_t pinNametoDigitalPin(PinName p); #define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p)))) #define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p))) -#define analogInPinToBit(p) (STM_PIN(digitalPinToPinName(p))) +#define analogInPinToBit(p) (STM_GPIO_PIN(digitalPinToPinName(p))) #define portOutputRegister(P) (&(P->ODR)) #define portInputRegister(P) (&(P->IDR)) From 4aff9b756b7f85df9eb94356463e086ba3bfcf8f Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 5 Nov 2018 15:02:08 +0100 Subject: [PATCH 08/22] Add digitalToggle APIs Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.h | 24 ++++++++++++++++++++++++ cores/arduino/wiring_digital.c | 5 +++++ cores/arduino/wiring_digital.h | 7 +++++++ keywords.txt | 2 ++ 4 files changed, 38 insertions(+) diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index a4ee8fb792..c987315fde 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -81,6 +81,17 @@ static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin) return LL_GPIO_IsInputPinSet(port, pin); } +/** + * @brief This function toggle value of an IO + * @param port : one of the gpio port + * @param pin : one of the gpio pin + * @retval None + */ +static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin) +{ + LL_GPIO_TogglePin(port, pin); +} + /** * @brief This function set a value to an IO * @param pn : Pin name @@ -108,6 +119,19 @@ static inline int digitalReadFast( PinName pn ) return (level)? HIGH : LOW; } +/** + * @brief This function toggle value of an IO + * @param port : one of the gpio port + * @param pin : one of the gpio pin + * @retval None + */ +static inline void digitalToggleFast(PinName pn) +{ + if(pn != NC) { + digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); + } +} + #ifdef __cplusplus } #endif diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 661acdee83..0122c26579 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -78,6 +78,11 @@ int digitalRead( uint32_t ulPin ) return digitalReadFast(digitalPinToPinName(ulPin)); } +void digitalToggle( uint32_t ulPin ) +{ + digitalToggleFast(digitalPinToPinName(ulPin)); +} + #ifdef __cplusplus } #endif diff --git a/cores/arduino/wiring_digital.h b/cores/arduino/wiring_digital.h index 3b69cf834d..fa26f511f3 100644 --- a/cores/arduino/wiring_digital.h +++ b/cores/arduino/wiring_digital.h @@ -62,6 +62,13 @@ extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ; */ extern int digitalRead( uint32_t ulPin ) ; +/** + * \brief Toggle the value from a specified digital pin. + * + * \param ulPin The number of the digital pin you want to toggle (int) + */ +extern void digitalToggle( uint32_t ulPin ) ; + #ifdef __cplusplus } #endif diff --git a/keywords.txt b/keywords.txt index 700bdbb123..2a71fbcebe 100644 --- a/keywords.txt +++ b/keywords.txt @@ -352,6 +352,8 @@ digitalPinFirstOccurence KEYWORD2 pinIsSerial KEYWORD2 digitalReadFast KEYWORD2 digitalWriteFast KEYWORD2 +digitalToggle KEYWORD2 +digitalToggleFast KEYWORD2 # Pin number PA0 LITERAL1 From cd7979d2068d497c2c296826449051fefb725472 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 5 Nov 2018 14:47:19 +0100 Subject: [PATCH 09/22] Clean up digital code after update Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.c | 5 +---- cores/arduino/stm32/digital_io.h | 24 ++++++++-------------- cores/arduino/wiring_digital.c | 35 ++++++++++++++++---------------- cores/arduino/wiring_digital.h | 29 ++++++++------------------ 4 files changed, 36 insertions(+), 57 deletions(-) diff --git a/cores/arduino/stm32/digital_io.c b/cores/arduino/stm32/digital_io.c index 6705d59489..167e3ec50a 100644 --- a/cores/arduino/stm32/digital_io.c +++ b/cores/arduino/stm32/digital_io.c @@ -1,9 +1,6 @@ /** ****************************************************************************** * @file digital_io.c - * @author WI6LABS - * @version V1.0.0 - * @date 01-August-2016 * @brief Provide an interface to configure hw ios * ****************************************************************************** @@ -39,7 +36,7 @@ #include "PinAF_STM32F1.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif /** diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index c987315fde..1e8c259352 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -1,9 +1,6 @@ /** ****************************************************************************** * @file digital_io.h - * @author WI6LABS - * @version V1.0.0 - * @date 01-August-2016 * @brief Header for digital_io module ****************************************************************************** * @attention @@ -45,12 +42,9 @@ #include "stm32yyxx_ll_gpio.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull); @@ -63,7 +57,7 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull); */ static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val) { - if(val) { + if (val) { LL_GPIO_SetOutputPin(port, pin); } else { LL_GPIO_ResetOutputPin(port, pin); @@ -71,7 +65,7 @@ static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t v } /** - * @brief This function set a value to an IO + * @brief This function read the value of an IO * @param port : one of the gpio port * @param pin : one of the gpio pin * @retval The pin state (LOW or HIGH) @@ -98,9 +92,9 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin) * @param val : 0 to set to low, any other value to set to high * @retval None */ -static inline void digitalWriteFast( PinName pn, uint32_t ulVal ) +static inline void digitalWriteFast(PinName pn, uint32_t ulVal) { - if(pn != NC) { + if (pn != NC) { digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal); } } @@ -110,13 +104,13 @@ static inline void digitalWriteFast( PinName pn, uint32_t ulVal ) * @param pn : Pin name * @retval The pin state (LOW or HIGH) */ -static inline int digitalReadFast( PinName pn ) +static inline int digitalReadFast(PinName pn) { uint8_t level = 0; - if(pn != NC) { + if (pn != NC) { level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); } - return (level)? HIGH : LOW; + return (level) ? HIGH : LOW; } /** @@ -127,7 +121,7 @@ static inline int digitalReadFast( PinName pn ) */ static inline void digitalToggleFast(PinName pn) { - if(pn != NC) { + if (pn != NC) { digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); } } diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 0122c26579..35ff180de1 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -20,7 +20,7 @@ #include "PinConfigured.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif @@ -29,56 +29,55 @@ uint32_t g_digPinConfigured[MAX_NB_PORT] = {0}; extern uint32_t g_anOutputPinConfigured[MAX_NB_PORT]; -void pinMode( uint32_t ulPin, uint32_t ulMode ) +void pinMode(uint32_t ulPin, uint32_t ulMode) { PinName p = digitalPinToPinName(ulPin); - if(p != NC) { + if (p != NC) { // If the pin that support PWM or DAC output, we need to turn it off - if(is_pin_configured(p, g_anOutputPinConfigured)) { + if (is_pin_configured(p, g_anOutputPinConfigured)) { #ifdef HAL_DAC_MODULE_ENABLED - if(pin_in_pinmap(p, PinMap_DAC)) { + if (pin_in_pinmap(p, PinMap_DAC)) { dac_stop(p); } else #endif //HAL_DAC_MODULE_ENABLED - if(pin_in_pinmap(p, PinMap_PWM)) { - pwm_stop(p); - } + if (pin_in_pinmap(p, PinMap_PWM)) { + pwm_stop(p); + } reset_pin_configured(p, g_anOutputPinConfigured); } - switch ( ulMode ) - { + switch (ulMode) { case INPUT: digital_io_init(p, GPIO_MODE_INPUT, GPIO_NOPULL); - break; + break; case INPUT_PULLUP: digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLUP); - break; + break; case INPUT_PULLDOWN: digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLDOWN); - break; + break; case OUTPUT: digital_io_init(p, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL); - break; + break; default: - break; + break; } set_pin_configured(p, g_digPinConfigured); } } -void digitalWrite( uint32_t ulPin, uint32_t ulVal ) +void digitalWrite(uint32_t ulPin, uint32_t ulVal) { digitalWriteFast(digitalPinToPinName(ulPin), ulVal); } -int digitalRead( uint32_t ulPin ) +int digitalRead(uint32_t ulPin) { return digitalReadFast(digitalPinToPinName(ulPin)); } -void digitalToggle( uint32_t ulPin ) +void digitalToggle(uint32_t ulPin) { digitalToggleFast(digitalPinToPinName(ulPin)); } diff --git a/cores/arduino/wiring_digital.h b/cores/arduino/wiring_digital.h index fa26f511f3..a8f4a0a6de 100644 --- a/cores/arduino/wiring_digital.h +++ b/cores/arduino/wiring_digital.h @@ -20,38 +20,27 @@ #define _WIRING_DIGITAL_ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /** - * \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details. + * \brief Configures the specified pin to behave either as an input or an output. * - * \param ulPin The number of the pin whose mode you wish to set - * \param ulMode Either INPUT or OUTPUT + * \param dwPin The number of the pin whose mode you wish to set + * \param dwMode Either INPUT, INPUT_PULLUP, INPUT_PULLDOWN or OUTPUT */ -extern void pinMode( uint32_t dwPin, uint32_t dwMode ) ; +extern void pinMode(uint32_t dwPin, uint32_t dwMode) ; /** * \brief Write a HIGH or a LOW value to a digital pin. * * If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the - * corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. - * - * If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal - * 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup - * resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely - * cause. The remedy is to set the pin to an output with the pinMode() function. - * - * \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED - * and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up - * resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor - * pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an - * external pull down resistor. + * corresponding value: 3.3V for HIGH, 0V (ground) for LOW. * * \param dwPin the pin number * \param dwVal HIGH or LOW */ -extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ; +extern void digitalWrite(uint32_t dwPin, uint32_t dwVal) ; /** * \brief Reads the value from a specified digital pin, either HIGH or LOW. @@ -60,14 +49,14 @@ extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ; * * \return HIGH or LOW */ -extern int digitalRead( uint32_t ulPin ) ; +extern int digitalRead(uint32_t ulPin) ; /** * \brief Toggle the value from a specified digital pin. * * \param ulPin The number of the digital pin you want to toggle (int) */ -extern void digitalToggle( uint32_t ulPin ) ; +extern void digitalToggle(uint32_t ulPin) ; #ifdef __cplusplus } From 7eeb73141ef35c2e696ab414dabcb5cd573eb450 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Tue, 6 Nov 2018 08:57:52 +0100 Subject: [PATCH 10/22] get_GPIO_Port return NULL if wrong PortName This will cause hard fault if used so check if NC can be removed Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/PortNames.h | 2 +- cores/arduino/stm32/digital_io.h | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cores/arduino/stm32/PortNames.h b/cores/arduino/stm32/PortNames.h index d970bd76ad..610429018a 100644 --- a/cores/arduino/stm32/PortNames.h +++ b/cores/arduino/stm32/PortNames.h @@ -76,7 +76,7 @@ typedef enum { #define MAX_NB_PORT (LastPort-FirstPort+1) /* Return GPIO base address */ -#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)GPIOA_BASE) +#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)NULL) /* Enable GPIO clock and return GPIO base address */ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx); diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index 1e8c259352..c2b05e4487 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -94,9 +94,7 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin) */ static inline void digitalWriteFast(PinName pn, uint32_t ulVal) { - if (pn != NC) { - digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal); - } + digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal); } /** @@ -107,9 +105,7 @@ static inline void digitalWriteFast(PinName pn, uint32_t ulVal) static inline int digitalReadFast(PinName pn) { uint8_t level = 0; - if (pn != NC) { - level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); - } + level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); return (level) ? HIGH : LOW; } @@ -121,9 +117,7 @@ static inline int digitalReadFast(PinName pn) */ static inline void digitalToggleFast(PinName pn) { - if (pn != NC) { - digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); - } + digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); } #ifdef __cplusplus From a97e0db24e0b34e9ecfe6d01509741174752334c Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Thu, 8 Nov 2018 10:14:57 +0100 Subject: [PATCH 11/22] Map LL GPIO pin definition to STM_PIN For F1 LL_GPIO_PIN_X is not the same than GPIO_PIN_X Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.h | 7 ++++--- cores/arduino/stm32/pinmap.c | 21 +++++++++++++++++++++ cores/arduino/stm32/pinmap.h | 4 ++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index c2b05e4487..0f8f4d1921 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -39,6 +39,7 @@ /* Includes ------------------------------------------------------------------*/ #include "wiring_constants.h" #include "PinNames.h" +#include "pinmap.h" #include "stm32yyxx_ll_gpio.h" #ifdef __cplusplus @@ -94,7 +95,7 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin) */ static inline void digitalWriteFast(PinName pn, uint32_t ulVal) { - digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal); + digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn), ulVal); } /** @@ -105,7 +106,7 @@ static inline void digitalWriteFast(PinName pn, uint32_t ulVal) static inline int digitalReadFast(PinName pn) { uint8_t level = 0; - level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); + level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn)); return (level) ? HIGH : LOW; } @@ -117,7 +118,7 @@ static inline int digitalReadFast(PinName pn) */ static inline void digitalToggleFast(PinName pn) { - digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn)); + digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn)); } #ifdef __cplusplus diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index abcd381ef9..7436df87f3 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -16,6 +16,27 @@ //Based on mbed-os/hal/mbed_pinmap_common.c #include "pinmap.h" +#include "stm32yyxx_ll_gpio.h" + +/* Map STM_PIN to LL */ +const uint32_t pin_map_ll[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 +}; void* pinmap_find_peripheral(PinName pin, const PinMap* map) { while (map->pin != NC) { diff --git a/cores/arduino/stm32/pinmap.h b/cores/arduino/stm32/pinmap.h index 857b9c3461..12e739b937 100644 --- a/cores/arduino/stm32/pinmap.h +++ b/cores/arduino/stm32/pinmap.h @@ -27,6 +27,10 @@ extern "C" { #endif +extern const uint32_t pin_map_ll[16]; + +#define STM_LL_GPIO_PIN(X) (pin_map_ll[STM_PIN(X)]) + // No peripheral #define NP 0U From bd00170caaa29d2686ffde7a7d86689b1da8ce1a Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 10:40:55 +0100 Subject: [PATCH 12/22] [pinmap] Reformatting code using astyle Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/pinmap.c | 72 ++++++++++++++++++++++-------------- cores/arduino/stm32/pinmap.h | 24 ++++++------ 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index 7436df87f3..b432c70548 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -38,17 +38,20 @@ const uint32_t pin_map_ll[16] = { LL_GPIO_PIN_15 }; -void* pinmap_find_peripheral(PinName pin, const PinMap* map) { +void *pinmap_find_peripheral(PinName pin, const PinMap *map) +{ while (map->pin != NC) { - if (map->pin == pin) + if (map->pin == pin) { return map->peripheral; + } map++; } return NP; } -void* pinmap_peripheral(PinName pin, const PinMap* map) { - void* peripheral = NP; +void *pinmap_peripheral(PinName pin, const PinMap *map) +{ + void *peripheral = NP; if (pin != (PinName)NC) { peripheral = pinmap_find_peripheral(pin, map); @@ -57,16 +60,19 @@ void* pinmap_peripheral(PinName pin, const PinMap* map) { return peripheral; } -PinName pinmap_find_pin(void* peripheral, const PinMap* map) { +PinName pinmap_find_pin(void *peripheral, const PinMap *map) +{ while (map->peripheral != NP) { - if (map->peripheral == peripheral) + if (map->peripheral == peripheral) { return map->pin; + } map++; } return NC; } -PinName pinmap_pin(void* peripheral, const PinMap* map) { +PinName pinmap_pin(void *peripheral, const PinMap *map) +{ PinName pin = NC; if (peripheral != NP) { @@ -76,16 +82,19 @@ PinName pinmap_pin(void* peripheral, const PinMap* map) { return pin; } -uint32_t pinmap_find_function(PinName pin, const PinMap* map) { +uint32_t pinmap_find_function(PinName pin, const PinMap *map) +{ while (map->pin != NC) { - if (map->pin == pin) + if (map->pin == pin) { return map->function; + } map++; } return (uint32_t)NC; } -uint32_t pinmap_function(PinName pin, const PinMap* map) { +uint32_t pinmap_function(PinName pin, const PinMap *map) +{ uint32_t function = (uint32_t)NC; if (pin != (PinName)NC) { @@ -95,11 +104,13 @@ uint32_t pinmap_function(PinName pin, const PinMap* map) { return function; } -bool pin_in_pinmap(PinName pin, const PinMap* map) { +bool pin_in_pinmap(PinName pin, const PinMap *map) +{ if (pin != (PinName)NC) { while (map->pin != NC) { - if (map->pin == pin) + if (map->pin == pin) { return true; + } map++; } } @@ -107,24 +118,29 @@ bool pin_in_pinmap(PinName pin, const PinMap* map) { } // Merge peripherals -void* pinmap_merge_peripheral(void* a, void* b) { - // both are the same (inc both NP) - if (a == b) - return a; - - // one (or both) is not set - if (a == NP) - return b; - if (b == NP) - return a; - - // mis-match error case - // error("pinmap mis-match"); - return NP; +void *pinmap_merge_peripheral(void *a, void *b) +{ + // both are the same (inc both NP) + if (a == b) { + return a; + } + + // one (or both) is not set + if (a == NP) { + return b; + } + if (b == NP) { + return a; + } + + // mis-match error case + // error("pinmap mis-match"); + return NP; } -PinName pin_pinName(const PinMap* map) { - if(map->pin != (PinName)NC) { +PinName pin_pinName(const PinMap *map) +{ + if (map->pin != (PinName)NC) { return map->pin; } else { return (PinName)NC; diff --git a/cores/arduino/stm32/pinmap.h b/cores/arduino/stm32/pinmap.h index 12e739b937..10a7ca9272 100644 --- a/cores/arduino/stm32/pinmap.h +++ b/cores/arduino/stm32/pinmap.h @@ -35,23 +35,23 @@ extern const uint32_t pin_map_ll[16]; #define NP 0U typedef struct { - PinName pin; - void* peripheral; - int function; + PinName pin; + void *peripheral; + int function; } PinMap; -bool pin_in_pinmap(PinName pin, const PinMap* map); +bool pin_in_pinmap(PinName pin, const PinMap *map); void pin_function(PinName pin, int function); -PinName pin_pinName(const PinMap* map); +PinName pin_pinName(const PinMap *map); -void* pinmap_find_peripheral(PinName pin, const PinMap* map); -void* pinmap_peripheral(PinName pin, const PinMap* map); -PinName pinmap_find_pin(void* peripheral, const PinMap* map); -PinName pinmap_pin(void* peripheral, const PinMap* map); -uint32_t pinmap_find_function(PinName pin, const PinMap* map); -uint32_t pinmap_function(PinName pin, const PinMap* map); -void* pinmap_merge_peripheral(void* a, void* b); +void *pinmap_find_peripheral(PinName pin, const PinMap *map); +void *pinmap_peripheral(PinName pin, const PinMap *map); +PinName pinmap_find_pin(void *peripheral, const PinMap *map); +PinName pinmap_pin(void *peripheral, const PinMap *map); +uint32_t pinmap_find_function(PinName pin, const PinMap *map); +uint32_t pinmap_function(PinName pin, const PinMap *map); +void *pinmap_merge_peripheral(void *a, void *b); #ifdef __cplusplus } From 595c1392ae9b54c8836135f4d7a357732f6d830c Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 10:49:45 +0100 Subject: [PATCH 13/22] [pinmap] Remove useless comment Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/pinmap.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index b432c70548..efe2177f5c 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -56,7 +56,6 @@ void *pinmap_peripheral(PinName pin, const PinMap *map) if (pin != (PinName)NC) { peripheral = pinmap_find_peripheral(pin, map); } - // else error("pinmap not found for peripheral"); return peripheral; } @@ -78,7 +77,6 @@ PinName pinmap_pin(void *peripheral, const PinMap *map) if (peripheral != NP) { pin = pinmap_find_pin(peripheral, map); } - // else error("pinmap not found for pin"); return pin; } @@ -100,7 +98,6 @@ uint32_t pinmap_function(PinName pin, const PinMap *map) if (pin != (PinName)NC) { function = pinmap_find_function(pin, map); } - // else error("pinmap not found for function"); return function; } @@ -134,7 +131,6 @@ void *pinmap_merge_peripheral(void *a, void *b) } // mis-match error case - // error("pinmap mis-match"); return NP; } From f01162ee62f80d1311109fac474a3ad800444917 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 10:52:44 +0100 Subject: [PATCH 14/22] [pinmap] Move pin_pinName() as static Function always return map->pin Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/pinmap.c | 35 +++++++++++++---------------------- cores/arduino/stm32/pinmap.h | 5 ++++- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index efe2177f5c..0cc0d3a45c 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -38,6 +38,19 @@ const uint32_t pin_map_ll[16] = { LL_GPIO_PIN_15 }; +bool pin_in_pinmap(PinName pin, const PinMap *map) +{ + if (pin != (PinName)NC) { + while (map->pin != NC) { + if (map->pin == pin) { + return true; + } + map++; + } + } + return false; +} + void *pinmap_find_peripheral(PinName pin, const PinMap *map) { while (map->pin != NC) { @@ -101,19 +114,6 @@ uint32_t pinmap_function(PinName pin, const PinMap *map) return function; } -bool pin_in_pinmap(PinName pin, const PinMap *map) -{ - if (pin != (PinName)NC) { - while (map->pin != NC) { - if (map->pin == pin) { - return true; - } - map++; - } - } - return false; -} - // Merge peripherals void *pinmap_merge_peripheral(void *a, void *b) { @@ -133,12 +133,3 @@ void *pinmap_merge_peripheral(void *a, void *b) // mis-match error case return NP; } - -PinName pin_pinName(const PinMap *map) -{ - if (map->pin != (PinName)NC) { - return map->pin; - } else { - return (PinName)NC; - } -} diff --git a/cores/arduino/stm32/pinmap.h b/cores/arduino/stm32/pinmap.h index 10a7ca9272..e7eba35e14 100644 --- a/cores/arduino/stm32/pinmap.h +++ b/cores/arduino/stm32/pinmap.h @@ -43,7 +43,10 @@ typedef struct { bool pin_in_pinmap(PinName pin, const PinMap *map); void pin_function(PinName pin, int function); -PinName pin_pinName(const PinMap *map); +static inline PinName pin_pinName(const PinMap *map) +{ + return map->pin; +} void *pinmap_find_peripheral(PinName pin, const PinMap *map); void *pinmap_peripheral(PinName pin, const PinMap *map); From 537c89adb904b02a3768ed84946bc4c189b74ce2 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 11:18:54 +0100 Subject: [PATCH 15/22] [PinName] Remove useless definition Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/PinNamesTypes.h | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/cores/arduino/stm32/PinNamesTypes.h b/cores/arduino/stm32/PinNamesTypes.h index 6095cb3014..2f3672e02c 100644 --- a/cores/arduino/stm32/PinNamesTypes.h +++ b/cores/arduino/stm32/PinNamesTypes.h @@ -36,7 +36,7 @@ extern "C" { /* 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 + * [5:4] as in PUPDR reg: No Pull, Pull-up, Pull-Down * [7:6] Reserved for speed config (as in OSPEEDR), but not used yet * [14:8] Alternate Num (as in AFRL/AFRG reg) * [19:15] Channel (Analog/Timer specific) @@ -135,25 +135,6 @@ typedef enum { #define STM_VALID_PINNAME(X) (STM_PORT(X) <= LastPort) #define STM_GPIO_PIN(X) ((uint16_t)(1< Date: Fri, 9 Nov 2018 16:48:13 +0100 Subject: [PATCH 16/22] Use LL for pin config Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/pinconfig.h | 97 +++++++++++++++++++++++++++++++++ cores/arduino/stm32/pinmap.c | 81 ++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 cores/arduino/stm32/pinconfig.h diff --git a/cores/arduino/stm32/pinconfig.h b/cores/arduino/stm32/pinconfig.h new file mode 100644 index 0000000000..344133858b --- /dev/null +++ b/cores/arduino/stm32/pinconfig.h @@ -0,0 +1,97 @@ +/* + ******************************************************************************* + * Copyright (c) 2018, 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. + ******************************************************************************* + * Based on mbed-os/target/TARGET_STM/TARGET_STMYY/pin_device.h + */ +#ifndef _PINCONFIG_H +#define _PINCONFIG_H + +#include "PinAF_STM32F1.h" +#include "stm32yyxx_ll_gpio.h" + +static inline void pin_DisconnectDebug(PinName pin) +{ +#ifdef STM32F1xx + pinF1_DisconnectDebug(pin); +#endif /* STM32F1xx */ +} + +static inline void pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config) +{ +#ifdef STM32F1xx + uint32_t function = LL_GPIO_GetPinMode(gpio, ll_pin); +#endif + + switch (pull_config) { + case GPIO_PULLUP: +#ifdef STM32F1xx + if (function == LL_GPIO_MODE_FLOATING) { + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT); + } +#endif + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP); + break; + case GPIO_PULLDOWN: +#ifdef STM32F1xx + if (function == LL_GPIO_MODE_FLOATING) { + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT); + } +#endif + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN); + break; + default: +#ifdef STM32F1xx + /* Input+NoPull = Floating for F1 family */ + if (function == LL_GPIO_MODE_INPUT) { + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_FLOATING); + } +#else + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO); +#endif + break; + } +} + +static inline void pin_SetAFPin(GPIO_TypeDef *gpio, PinName pin, uint32_t afnum) +{ +#ifdef STM32F1xx + UNUSED(gpio); + UNUSED(pin); + pin_SetF1AFPin(afnum); +#else + uint32_t ll_pin = STM_LL_GPIO_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 +} + +#endif diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index 0cc0d3a45c..bf4f01f859 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -14,8 +14,8 @@ * limitations under the License. */ //Based on mbed-os/hal/mbed_pinmap_common.c - #include "pinmap.h" +#include "pinconfig.h" #include "stm32yyxx_ll_gpio.h" /* Map STM_PIN to LL */ @@ -51,6 +51,85 @@ bool pin_in_pinmap(PinName pin, const PinMap *map) return false; } +/** + * Configure pin (mode, speed, output type and pull-up/pull-down) + */ +void pin_function(PinName pin, int function) +{ + /* Get the pin informations */ + uint32_t mode = STM_PIN_FUNCTION(function); + uint32_t afnum = STM_PIN_AFNUM(function); + uint32_t port = STM_PORT(pin); + uint32_t ll_pin = STM_LL_GPIO_PIN(pin); + uint32_t ll_mode = 0; + + if (pin == (PinName)NC) { + Error_Handler(); + } + + /* Enable GPIO clock */ + GPIO_TypeDef *gpio = set_GPIO_Port_Clock(port); + + /* Set default speed to high. + * For most families there are dedicated registers so it is + * not so important, register can be set at any time. + * But for families like F1, speed only applies to output. + */ +#if defined (STM32F1xx) + if (mode == STM_PIN_OUTPUT) { +#endif +#ifdef LL_GPIO_SPEED_FREQ_VERY_HIGH + LL_GPIO_SetPinSpeed(gpio, ll_pin, LL_GPIO_SPEED_FREQ_VERY_HIGH); +#else + LL_GPIO_SetPinSpeed(gpio, ll_pin, LL_GPIO_SPEED_FREQ_HIGH); +#endif +#if defined (STM32F1xx) + } +#endif + + 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 the afnum */ + pin_SetAFPin(gpio, pin, afnum); + break; + case STM_PIN_ANALOG: + ll_mode = LL_GPIO_MODE_ANALOG; + break; + default: + Error_Handler(); + 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(function)) { + LL_GPIO_EnablePinAnalogControl(gpio, ll_pin); + } else { + LL_GPIO_DisablePinAnalogControl(gpio, ll_pin); + } +#endif + + if ((mode == STM_PIN_OUTPUT) || (mode == STM_PIN_ALTERNATE)) { + if (STM_PIN_OD(function)) { + LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_OPENDRAIN); + } else { + LL_GPIO_SetPinOutputType(gpio, ll_pin, LL_GPIO_OUTPUT_PUSHPULL); + } + } + + pin_PullConfig(gpio, ll_pin, STM_PIN_PUPD(function)); + + pin_DisconnectDebug(pin); +} + void *pinmap_find_peripheral(PinName pin, const PinMap *map) { while (map->pin != NC) { From 2c6959afe1571c03908afc7c9fbce49f08567b38 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 15:52:51 +0100 Subject: [PATCH 17/22] pinMode using LL Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/digital_io.c | 72 -------------------------------- cores/arduino/stm32/digital_io.h | 2 - cores/arduino/stm32/pinconfig.h | 2 + cores/arduino/stm32/timer.c | 4 +- cores/arduino/wiring_digital.c | 8 ++-- 5 files changed, 8 insertions(+), 80 deletions(-) delete mode 100644 cores/arduino/stm32/digital_io.c diff --git a/cores/arduino/stm32/digital_io.c b/cores/arduino/stm32/digital_io.c deleted file mode 100644 index 167e3ec50a..0000000000 --- a/cores/arduino/stm32/digital_io.c +++ /dev/null @@ -1,72 +0,0 @@ -/** - ****************************************************************************** - * @file digital_io.c - * @brief Provide an interface to configure hw ios - * - ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2016 STMicroelectronics

- * - * 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 "digital_io.h" -#include "PinAF_STM32F1.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief This function initialize the IO - * @param port : one of the gpio port - * @param pin : one of the gpio pin - * @param mode : one of the gpio mode (cf hal_gpio.h) - * @param pull : one of the pullup/down mode (cf hal_gpio.h) - * @retval None - */ -void digital_io_init(PinName pin, uint32_t mode, uint32_t pull) -{ - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin)); - GPIO_InitStructure.Pin = STM_GPIO_PIN(pin); -#ifdef GPIO_SPEED_FREQ_VERY_HIGH - GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; -#else - GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; -#endif - GPIO_InitStructure.Mode = mode; - GPIO_InitStructure.Pull = pull; -#ifdef STM32F1xx - pinF1_DisconnectDebug(pin); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStructure); -} - -#ifdef __cplusplus -} -#endif - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/digital_io.h b/cores/arduino/stm32/digital_io.h index 0f8f4d1921..b5d8dd347e 100644 --- a/cores/arduino/stm32/digital_io.h +++ b/cores/arduino/stm32/digital_io.h @@ -47,8 +47,6 @@ extern "C" { #endif /* Exported functions ------------------------------------------------------- */ -void digital_io_init(PinName pin, uint32_t mode, uint32_t pull); - /** * @brief This function set a value to an IO * @param port : one of the gpio port diff --git a/cores/arduino/stm32/pinconfig.h b/cores/arduino/stm32/pinconfig.h index 344133858b..4db6bf971e 100644 --- a/cores/arduino/stm32/pinconfig.h +++ b/cores/arduino/stm32/pinconfig.h @@ -38,6 +38,8 @@ static inline void pin_DisconnectDebug(PinName pin) { #ifdef STM32F1xx pinF1_DisconnectDebug(pin); +#else + UNUSED(pin); #endif /* STM32F1xx */ } diff --git a/cores/arduino/stm32/timer.c b/cores/arduino/stm32/timer.c index 6905b5846a..76e9e3b5f1 100644 --- a/cores/arduino/stm32/timer.c +++ b/cores/arduino/stm32/timer.c @@ -924,7 +924,7 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration) obj->pinInfo.count = -1; } - digital_io_init(obj->pin, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL); + pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); timClkFreq = getTimerClkFreq(obj->timer); // Do this once @@ -957,7 +957,7 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration) void TimerPinDeinit(stimer_t *obj) { TimerHandleDeinit(obj); - digital_io_init(obj->pin, GPIO_MODE_INPUT, GPIO_NOPULL); + pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); } /** diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 35ff180de1..90eae12c4f 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -49,16 +49,16 @@ void pinMode(uint32_t ulPin, uint32_t ulMode) switch (ulMode) { case INPUT: - digital_io_init(p, GPIO_MODE_INPUT, GPIO_NOPULL); + pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); break; case INPUT_PULLUP: - digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLUP); + pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, 0)); break; case INPUT_PULLDOWN: - digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLDOWN); + pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, 0)); break; case OUTPUT: - digital_io_init(p, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL); + pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); break; default: break; From a544cb29c6f2ffa558ffffbbf4c5d0c341018155 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 16:55:13 +0100 Subject: [PATCH 18/22] [pinmap] Add pinmap_pinout() API Allow to configure a pin as describe in a pinmap Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/pinmap.c | 16 ++++++++++++++++ cores/arduino/stm32/pinmap.h | 1 + 2 files changed, 17 insertions(+) diff --git a/cores/arduino/stm32/pinmap.c b/cores/arduino/stm32/pinmap.c index bf4f01f859..499fa9a5b1 100644 --- a/cores/arduino/stm32/pinmap.c +++ b/cores/arduino/stm32/pinmap.c @@ -130,6 +130,22 @@ void pin_function(PinName pin, int function) pin_DisconnectDebug(pin); } +void pinmap_pinout(PinName pin, const PinMap *map) +{ + if (pin == NC) { + return; + } + + while (map->pin != NC) { + if (map->pin == pin) { + pin_function(pin, map->function); + return; + } + map++; + } + Error_Handler(); +} + void *pinmap_find_peripheral(PinName pin, const PinMap *map) { while (map->pin != NC) { diff --git a/cores/arduino/stm32/pinmap.h b/cores/arduino/stm32/pinmap.h index e7eba35e14..ed464ee277 100644 --- a/cores/arduino/stm32/pinmap.h +++ b/cores/arduino/stm32/pinmap.h @@ -48,6 +48,7 @@ static inline PinName pin_pinName(const PinMap *map) return map->pin; } +void pinmap_pinout(PinName pin, const PinMap *map); void *pinmap_find_peripheral(PinName pin, const PinMap *map); void *pinmap_peripheral(PinName pin, const PinMap *map); PinName pinmap_find_pin(void *peripheral, const PinMap *map); From 7ccbccb5ce1568c00d8bf55cb633c666807697ec Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 9 Nov 2018 17:21:20 +0100 Subject: [PATCH 19/22] Replace HAL_GPIO_Init by pinmap_pinout Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/analog.c | 52 +++-------------------- cores/arduino/stm32/spi_com.c | 78 ++++++----------------------------- cores/arduino/stm32/twi.c | 30 ++------------ cores/arduino/stm32/uart.c | 37 ++--------------- 4 files changed, 25 insertions(+), 172 deletions(-) diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c index 3fc76384ca..6668ca2790 100644 --- a/cores/arduino/stm32/analog.c +++ b/cores/arduino/stm32/analog.c @@ -257,14 +257,8 @@ static uint32_t get_dac_channel(PinName pin) */ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) { - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; UNUSED(hdac); - /*##-1- Enable peripherals and GPIO Clocks #################################*/ - /* Enable GPIO clock ****************************************/ - port = set_GPIO_Port_Clock(STM_PORT(g_current_pin)); - /* DAC Periph clock enable */ #ifdef __HAL_RCC_DAC1_CLK_ENABLE __HAL_RCC_DAC1_CLK_ENABLE(); @@ -272,12 +266,8 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) #ifdef __HAL_RCC_DAC_CLK_ENABLE __HAL_RCC_DAC_CLK_ENABLE(); #endif - /*##-2- Configure peripheral GPIO ##########################################*/ - /* DAC Channel1 GPIO pin configuration */ - GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin); - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(port, &GPIO_InitStruct); + /* Configure DAC GPIO pins */ + pinmap_pinout(g_current_pin, PinMap_DAC); } @@ -393,8 +383,6 @@ void dac_stop(PinName pin) */ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* ADC Periph clock enable */ if(hadc->Instance == ADC1) { @@ -440,19 +428,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) __HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK); #endif - /* Enable GPIO clock ****************************************/ - port = set_GPIO_Port_Clock(STM_PORT(g_current_pin)); - - /*##-2- Configure peripheral GPIO ##########################################*/ - /* ADC Channel GPIO pin configuration */ - GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin); -#ifdef GPIO_MODE_ANALOG_ADC_CONTROL - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; -#else - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; -#endif - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(port, &GPIO_InitStruct); + /* Configure ADC GPIO pin */ + pinmap_pinout(g_current_pin, PinMap_ADC); } /** @@ -682,29 +659,12 @@ uint16_t adc_read_value(PinName pin) */ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) { - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; - uint32_t function = pinmap_function(g_current_pin, PinMap_PWM); /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* TIMx Peripheral clock enable */ timer_enable_clock(htim); - /* Enable GPIO Channels Clock */ - /* Enable GPIO clock ****************************************/ - port = set_GPIO_Port_Clock(STM_PORT(g_current_pin)); - - /* Common configuration for all channels */ - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(function)); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function); -#endif /* STM32F1xx */ - GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin); - - HAL_GPIO_Init(port, &GPIO_InitStruct); + /* Configure PWM GPIO pins */ + pinmap_pinout(g_current_pin, PinMap_PWM); } /** diff --git a/cores/arduino/stm32/spi_com.c b/cores/arduino/stm32/spi_com.c index 9a5f41521f..d37e8458b9 100644 --- a/cores/arduino/stm32/spi_com.c +++ b/cores/arduino/stm32/spi_com.c @@ -50,6 +50,7 @@ #include "stm32_def.h" #include "spi_com.h" #include "PinAF_STM32F1.h" +#include "pinconfig.h" #ifdef __cplusplus extern "C" { @@ -192,9 +193,8 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) return; SPI_HandleTypeDef *handle = &(obj->handle); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; uint32_t spi_freq = 0; + uint32_t pull = 0; // Determine the SPI to use SPI_TypeDef *spi_mosi = pinmap_peripheral(obj->pin_mosi, PinMap_SPI_MOSI); @@ -280,69 +280,17 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) handle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE; #endif - if(obj->pin_mosi != NC) { - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_mosi)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_mosi); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); - GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - } - - if(obj->pin_miso != NC) { - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_miso)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_miso); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); - GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - } - - if(obj->pin_sclk != NC) { - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_sclk)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_sclk); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK)); - /* - * According the STM32 Datasheet for SPI peripheral we need to PULLDOWN - * or PULLUP the SCK pin according the polarity used. - */ - if(handle->Init.CLKPolarity == SPI_POLARITY_LOW) { - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - } else { - GPIO_InitStruct.Pull = GPIO_PULLUP; - } - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - } - - if(obj->pin_ssel != NC) { - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_ssel)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_ssel); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); - GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - } + /* Configure SPI GPIO pins */ + pinmap_pinout(obj->pin_mosi, PinMap_SPI_MOSI); + pinmap_pinout(obj->pin_miso, PinMap_SPI_MISO); + pinmap_pinout(obj->pin_sclk, PinMap_SPI_SCLK); + /* + * According the STM32 Datasheet for SPI peripheral we need to PULLDOWN + * or PULLUP the SCK pin according the polarity used. + */ + pull = (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? GPIO_PULLDOWN: GPIO_PULLUP; + pin_PullConfig(get_GPIO_Port(STM_PORT(obj->pin_sclk)), STM_LL_GPIO_PIN(obj->pin_sclk), pull); + pinmap_pinout(obj->pin_ssel, PinMap_SPI_SSEL); #if defined SPI1_BASE // Enable SPI clock diff --git a/cores/arduino/stm32/twi.c b/cores/arduino/stm32/twi.c index 44c8e9fc34..8061ce2c3e 100644 --- a/cores/arduino/stm32/twi.c +++ b/cores/arduino/stm32/twi.c @@ -157,8 +157,6 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u if(obj == NULL) return; - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; I2C_HandleTypeDef *handle = &(obj->handle); // Determine the I2C to use @@ -232,31 +230,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u } #endif // I2C4_BASE - //SCL - port = set_GPIO_Port_Clock(STM_PORT(obj->scl)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->scl); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->scl,PinMap_I2C_SCL)); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->scl,PinMap_I2C_SCL)); -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->scl,PinMap_I2C_SCL))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->scl,PinMap_I2C_SCL)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - - //SDA - port = set_GPIO_Port_Clock(STM_PORT(obj->sda)); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->sda); - GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->sda,PinMap_I2C_SDA)); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->sda,PinMap_I2C_SDA)); -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->sda,PinMap_I2C_SDA))); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->sda,PinMap_I2C_SDA)); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); + /* Configure I2C GPIO pins */ + pinmap_pinout(obj->scl, PinMap_I2C_SCL); + pinmap_pinout(obj->sda, PinMap_I2C_SDA); handle->Instance = obj->i2c; #if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\ diff --git a/cores/arduino/stm32/uart.c b/cores/arduino/stm32/uart.c index 81401788f7..ef74671161 100644 --- a/cores/arduino/stm32/uart.c +++ b/cores/arduino/stm32/uart.c @@ -92,9 +92,6 @@ void uart_init(serial_t *obj) } UART_HandleTypeDef *huart = &(obj->handle); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_TypeDef *port; - uint32_t function = (uint32_t)NC; /* Determine the U(S)ART peripheral to use (USART1, USART2, ...) */ USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX); @@ -260,37 +257,9 @@ void uart_init(serial_t *obj) __HAL_RCC_SYSCFG_CLK_ENABLE(); #endif - /* Configure GPIOs */ - /* RX */ - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_rx)); - function = pinmap_function(obj->pin_rx, PinMap_UART_RX); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_rx); - GPIO_InitStruct.Mode = STM_PIN_MODE(function); - GPIO_InitStruct.Pull = STM_PIN_PUPD(function); - /* Common */ -#ifdef STM32F1xx - pin_SetF1AFPin(STM_PIN_AFNUM(function)); -#else - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function); -#endif /* STM32F1xx */ -#ifdef GPIO_SPEED_FREQ_VERY_HIGH - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; -#else - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; -#endif - HAL_GPIO_Init(port, &GPIO_InitStruct); - - /* TX */ - port = set_GPIO_Port_Clock(STM_PORT(obj->pin_tx)); - function = pinmap_function(obj->pin_tx, PinMap_UART_TX); - GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_tx); - GPIO_InitStruct.Mode = STM_PIN_MODE(function); - GPIO_InitStruct.Pull = STM_PIN_PUPD(function); -#ifndef STM32F1xx - GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function); -#endif /* STM32F1xx */ - HAL_GPIO_Init(port, &GPIO_InitStruct); - + /* Configure UART GPIO pins */ + pinmap_pinout(obj->pin_tx, PinMap_UART_TX); + pinmap_pinout(obj->pin_rx, PinMap_UART_RX); /* Configure uart */ uart_handlers[obj->index] = huart; From 65554c11add93aee11a940294292b2351a02995f Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Tue, 13 Nov 2018 11:25:41 +0100 Subject: [PATCH 20/22] Extend GPIO mode Fix #275 Signed-off-by: Frederic.Pillon --- cores/arduino/wiring_constants.h | 26 ++++++++++++++------------ cores/arduino/wiring_digital.c | 9 ++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h index ec4cff2b91..98d6484bb1 100644 --- a/cores/arduino/wiring_constants.h +++ b/cores/arduino/wiring_constants.h @@ -42,13 +42,15 @@ using std::max; #endif // __cplusplus -#define HIGH 0x1 -#define LOW 0x0 - -#define INPUT 0x0 -#define OUTPUT 0x1 -#define INPUT_PULLUP 0x2 -#define INPUT_PULLDOWN 0x3 +/* Official Arduino */ +#define INPUT 0x0 +#define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 +/* STM32 extension */ +#define INPUT_FLOATING INPUT +#define INPUT_PULLDOWN 0x3 +#define INPUT_ANALOG 0x4 +#define OUTPUT_OPEN_DRAIN 0x5 #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 @@ -65,11 +67,11 @@ enum BitOrder { MSBFIRST = 1 }; -// LOW 0 -// HIGH 1 -#define CHANGE 2 -#define FALLING 3 -#define RISING 4 +#define LOW 0x0 +#define HIGH 0x1 +#define CHANGE 0x2 +#define FALLING 0x3 +#define RISING 0x4 #define DEFAULT 1 #define EXTERNAL 0 diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 90eae12c4f..6af48eef5a 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -48,7 +48,7 @@ void pinMode(uint32_t ulPin, uint32_t ulMode) } switch (ulMode) { - case INPUT: + case INPUT: /* INPUT_FLOATING */ pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); break; case INPUT_PULLUP: @@ -57,10 +57,17 @@ void pinMode(uint32_t ulPin, uint32_t ulMode) case INPUT_PULLDOWN: pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, 0)); break; + case INPUT_ANALOG: + pin_function(p, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)); + break; case OUTPUT: pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); break; + case OUTPUT_OPEN_DRAIN: + pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_OD, GPIO_NOPULL, 0)); + break; default: + Error_Handler(); break; } set_pin_configured(p, g_digPinConfigured); From e3924c0be0d09fe58df0317342f9a5a50cb3f443 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Thu, 15 Nov 2018 14:35:51 +0100 Subject: [PATCH 21/22] Fix pinNametoDigitalPin default value Signed-off-by: Frederic.Pillon --- cores/arduino/pins_arduino.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c index cebc377375..47e4dfa42f 100644 --- a/cores/arduino/pins_arduino.c +++ b/cores/arduino/pins_arduino.c @@ -24,7 +24,7 @@ extern "C" { WEAK uint32_t pinNametoDigitalPin(PinName p) { - uint32_t i = NC; + uint32_t i = NUM_DIGITAL_PINS; if(STM_VALID_PINNAME(p)) { for(i = 0; i < NUM_DIGITAL_PINS; i++) { if (digitalPin[i] == p) From 49d1df8ad3c58dce7be1760d686ac4a6c86d61a5 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 16 Nov 2018 09:39:26 +0100 Subject: [PATCH 22/22] Update ADC Pin mode for STM32L47x This is required to handle properly ADC control Signed-off-by: Frederic.Pillon --- variants/DISCO_L475VG_IOT/PeripheralPins.c | 72 +++++++++++----------- variants/NUCLEO_L476RG/PeripheralPins.c | 72 +++++++++++----------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/variants/DISCO_L475VG_IOT/PeripheralPins.c b/variants/DISCO_L475VG_IOT/PeripheralPins.c index 79f36fbee1..528956c189 100644 --- a/variants/DISCO_L475VG_IOT/PeripheralPins.c +++ b/variants/DISCO_L475VG_IOT/PeripheralPins.c @@ -40,42 +40,42 @@ #ifdef HAL_ADC_MODULE_ENABLED const PinMap PinMap_ADC[] = { - {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 - D1/UART4_TX -// {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 - D1/UART4_TX - {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 - D0/UART4_RX -// {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 - D0/UART4_RX - {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - D10/PWM -// {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - D10/PWM - {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 - D4 -// {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 - D4 - {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 - D7 -// {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - D7 - {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - D13/SPI1_SCK/LED1 -// {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 - D13/SPI1_SCK/LED1 - {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 - D12/SPI_MISO -// {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 - D12/SPI_MISO - {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 - D11/SPI1_MOSI/PWM -// {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - D11/SPI1_MOSI/PWM - {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 - D3/PWM -// {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 - D3/PWM - {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC1_IN16 - D6/PWM -// {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC2_IN16 - D6/PWM - {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 - A5 -// {PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 - A5 -// {PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 - A5 - {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 - A2 -// {PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 - A2 -// {PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 - A2 - {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - A3 -// {PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 - A3 -// {PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 - A3 - {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 - A2 -// {PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 - A2 -// {PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 - A2 - {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 - A1 -// {PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 - A1 - {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 - A0 -// {PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 - A0 + {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 - D1/UART4_TX +// {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 - D1/UART4_TX + {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 - D0/UART4_RX +// {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 - D0/UART4_RX + {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - D10/PWM +// {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - D10/PWM + {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 - D4 +// {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 - D4 + {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 - D7 +// {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - D7 + {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - D13/SPI1_SCK/LED1 +// {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 - D13/SPI1_SCK/LED1 + {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 - D12/SPI_MISO +// {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 - D12/SPI_MISO + {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 - D11/SPI1_MOSI/PWM +// {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - D11/SPI1_MOSI/PWM + {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 - D3/PWM +// {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 - D3/PWM + {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 16, 0)}, // ADC1_IN16 - D6/PWM +// {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 16, 0)}, // ADC2_IN16 - D6/PWM + {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 - A5 +// {PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 - A5 +// {PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 - A5 + {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 - A2 +// {PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 - A2 +// {PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 - A2 + {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - A3 +// {PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 - A3 +// {PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 - A3 + {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 - A2 +// {PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 - A2 +// {PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 - A2 + {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 - A1 +// {PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 - A1 + {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 - A0 +// {PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 - A0 {NC, NP, 0} }; #endif diff --git a/variants/NUCLEO_L476RG/PeripheralPins.c b/variants/NUCLEO_L476RG/PeripheralPins.c index 4a65ada245..9c8a760a50 100644 --- a/variants/NUCLEO_L476RG/PeripheralPins.c +++ b/variants/NUCLEO_L476RG/PeripheralPins.c @@ -40,42 +40,42 @@ #ifdef HAL_ADC_MODULE_ENABLED const PinMap PinMap_ADC[] = { - {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 -// {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 - {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 -// {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 -// {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - STLink Tx -// {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - STLink Tx -// {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 - STLink Rx -// {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 - STLink Rx - {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 -// {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 -// {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - LED -// {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 - {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 -// {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 - {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 -// {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 -// {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 -// {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC1_IN16 -// {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC2_IN16 - {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 -// {PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 -// {PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 - {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 -// {PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 -// {PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 - {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 -// {PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 -// {PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 - {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 -// {PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 -// {PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 - {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 -// {PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 - {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 -// {PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 + {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 +// {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 +// {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 +// {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - STLink Tx +// {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 - STLink Tx +// {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 - STLink Rx +// {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 - STLink Rx + {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 +// {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 +// {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - LED +// {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 + {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 +// {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 + {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 +// {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 + {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 +// {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 +// {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 16, 0)}, // ADC1_IN16 +// {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 16, 0)}, // ADC2_IN16 + {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 +// {PC_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 +// {PC_0, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 + {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 +// {PC_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 +// {PC_1, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 + {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 +// {PC_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 +// {PC_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 + {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 +// {PC_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 +// {PC_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 + {PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 +// {PC_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 + {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 +// {PC_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG_ADC_CONTROL, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 {NC, NP, 0} }; #endif