From f09f1863756a2ee351f60145b50bc4b2d3eeaca0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Jul 2018 17:46:58 -0600 Subject: [PATCH] arch/arm/src/stm32f7: Port Bob Feritich's change (2c699d781279d899cffd0446d4073a9a6ea3fa48) to STM32 F2 and F4 which appear to have identical SD support and I/O compensation requirements. --- arch/arm/src/stm32/Kconfig | 19 ++++++++ arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h | 9 +++- arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h | 13 ++++-- arch/arm/src/stm32/stm32_gpio.c | 3 -- arch/arm/src/stm32/stm32_gpio.h | 45 +++++++++++++++++++ arch/arm/src/stm32/stm32_rcc.c | 7 +++ .../src/stm32f7/chip/stm32f72xx73xx_pinmap.h | 4 +- .../src/stm32f7/chip/stm32f74xx75xx_pinmap.h | 4 +- .../src/stm32f7/chip/stm32f76xx77xx_pinmap.h | 4 +- 9 files changed, 93 insertions(+), 15 deletions(-) diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index 8be41ab2da4..6cb2b2c0c70 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -1422,6 +1422,7 @@ config STM32_LOWDENSITY config STM32_STM32F20XX bool default n + select STM32_HAVE_IOCOMPENSATION config STM32_STM32F205 bool @@ -1570,6 +1571,7 @@ config STM32_STM32F4XXX default n select STM32_HAVE_SPI2 select STM32_HAVE_I2C2 + select STM32_HAVE_IOCOMPENSATION config STM32_STM32F401xBC bool @@ -1899,6 +1901,10 @@ config STM32_HAVE_FSMC bool default n +config STM32_HAVE_IOCOMPENSATION + bool + default n + config STM32_HAVE_HRTIM1 bool default n @@ -2752,6 +2758,19 @@ config STM32_NOEXT_VECTORS Sometimes you may not need any Vector support beyond SysTick and wish to save memory. This applies only to ARMv7-M architectures. +config STM32_SYSCFG_IOCOMPENSATION + bool "SYSCFG I/O Compensation" + default n + depends on STM32_HAVE_IOCOMPENSATION + ---help--- + By default the I/O compensation cell is not used. However when the I/O + output buffer speed is configured in 50 MHz or 100 MHz mode, it is + recommended to use the compensation cell for slew rate control on I/O + tf(IO)out)/tr(IO)out commutation to reduce the I/O noise on power supply. + + The I/O compensation cell can be used only when the supply voltage ranges + from 2.4 to 3.6 V. + menu "Alternate Pin Mapping" choice diff --git a/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h b/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h index 70193263b1d..7804792a847 100644 --- a/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h +++ b/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h @@ -400,9 +400,14 @@ #define GPIO_RTC_50HZ (GPIO_ALT|GPIO_AF0|GPIO_PORTC|GPIO_PIN15) -/* SDIO */ +/* SDIO + * + * Note that the below configures GPIO_SPEED_50MHz I/O, that means for using + * the SDIO that you must enable I/O Compensation via the configuration option + * CONFIG_STM32_SYSCFG_IOCOMPENSATION=y. + */ -#define GPIO_SDIO_CK (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN12) +#define GPIO_SDIO_CK (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12) #define GPIO_SDIO_CMD (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN2) #define GPIO_SDIO_D0 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN8) #define GPIO_SDIO_D1 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9) diff --git a/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h b/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h index c5a4c4d5d30..5fbcb8a8566 100644 --- a/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h +++ b/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h @@ -554,7 +554,12 @@ #define GPIO_RTC_50HZ (GPIO_ALT|GPIO_AF0|GPIO_PORTC|GPIO_PIN15) -/* SDIO */ +/* SDIO + * + * Note that the below configures GPIO_SPEED_50MHz I/O, that means for using + * the SDIO that you must enable I/O Compensation via the configuration option + * CONFIG_STM32_SYSCFG_IOCOMPENSATION=y. + */ #define GPIO_SDIO_CMD (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN2) #define GPIO_SDIO_D0 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN8) @@ -565,14 +570,14 @@ #define GPIO_SDIO_D7 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN7) #if defined(CONFIG_STM32_STM32F446) -# define GPIO_SDIO_CK_1 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN12) -# define GPIO_SDIO_CK_2 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN2) +# define GPIO_SDIO_CK_1 (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12) +# define GPIO_SDIO_CK_2 (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTB|GPIO_PIN2) # define GPIO_SDIO_D1_1 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9) # define GPIO_SDIO_D1_2 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN0) # define GPIO_SDIO_D2_1 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN10) # define GPIO_SDIO_D2_2 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN1) #else -# define GPIO_SDIO_CK (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN12) +# define GPIO_SDIO_CK (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12) # define GPIO_SDIO_D1 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9) # define GPIO_SDIO_D2 (GPIO_ALT|GPIO_AF12|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN10) #endif diff --git a/arch/arm/src/stm32/stm32_gpio.c b/arch/arm/src/stm32/stm32_gpio.c index 7a1d7800c4d..16d77950c4c 100644 --- a/arch/arm/src/stm32/stm32_gpio.c +++ b/arch/arm/src/stm32/stm32_gpio.c @@ -49,9 +49,6 @@ #include -#include "up_arch.h" - -#include "chip.h" #include "stm32_gpio.h" #if defined(CONFIG_STM32_STM32L15XX) || defined(CONFIG_STM32_STM32F20XX) || \ diff --git a/arch/arm/src/stm32/stm32_gpio.h b/arch/arm/src/stm32/stm32_gpio.h index c08b9a92987..a0dbc1b91a9 100644 --- a/arch/arm/src/stm32/stm32_gpio.h +++ b/arch/arm/src/stm32/stm32_gpio.h @@ -51,7 +51,9 @@ #include +#include "up_arch.h" #include "chip.h" +#include "chip/stm32_syscfg.h" #if defined(CONFIG_STM32_STM32L15XX) # include "chip/stm32l15xxx_gpio.h" @@ -419,6 +421,49 @@ extern "C" EXTERN const uint32_t g_gpiobase[STM32_NGPIO_PORTS]; +/************************************************************************************ + * Inline Functions + ************************************************************************************/ + +/**************************************************************************** + * Name: syscfg_iocompensation + * + * Description: + * Enable I/O compensation. + * + * By default the I/O compensation cell is not used. However when the I/O + * output buffer speed is configured in 50 MHz or 100 MHz mode, it is + * recommended to use the compensation cell for slew rate control on I/O + * tf(IO)out)/tr(IO)out commutation to reduce the I/O noise on power supply. + * + * The I/O compensation cell can be used only when the supply voltage ranges + * from 2.4 to 3.6 V. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline void syscfg_iocompensation(void) +{ +#ifdef STM32_SYSCFG_CMPCR + /* Enable I/O Compensation. Writing '1' to the CMPCR power-down bit + * enables the I/O compensation cell. + */ + + putreg32(SYSCFG_CMPCR_CMPPD, STM32_SYSCFG_CMPCR); + + /* Wait for compensation cell to become ready */ + + while ((getreg32(STM32_SYSCFG_CMPCR) & SYSCFG_CMPCR_READY) == 0) + { + } +#endif +} + /************************************************************************************ * Public Function Prototypes ************************************************************************************/ diff --git a/arch/arm/src/stm32/stm32_rcc.c b/arch/arm/src/stm32/stm32_rcc.c index 2ed39f9a5ea..9debfa9bad5 100644 --- a/arch/arm/src/stm32/stm32_rcc.c +++ b/arch/arm/src/stm32/stm32_rcc.c @@ -51,6 +51,7 @@ #include "up_arch.h" #include "chip.h" +#include "stm32_gpio.h" #include "stm32_rcc.h" #include "stm32_rtc.h" #include "stm32_flash.h" @@ -198,6 +199,12 @@ void stm32_clockconfig(void) #endif +#ifdef CONFIG_STM32_SYSCFG_IOCOMPENSATION + /* Enable I/O Compensation */ + + syscfg_iocompensation(); +#endif + /* Enable peripheral clocking */ rcc_enableperipherals(); diff --git a/arch/arm/src/stm32f7/chip/stm32f72xx73xx_pinmap.h b/arch/arm/src/stm32f7/chip/stm32f72xx73xx_pinmap.h index a24d951f996..be428b4e3b4 100644 --- a/arch/arm/src/stm32f7/chip/stm32f72xx73xx_pinmap.h +++ b/arch/arm/src/stm32f7/chip/stm32f72xx73xx_pinmap.h @@ -579,8 +579,8 @@ /* SD/MMC * * Note that the below configures GPIO_SPEED_50MHz I/O, that means for using - * the SDMMC, the board's boot code must enable I/O Compensation via the - * configuration option CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. + * the SDIO that you must enable I/O Compensation via the configuration option + * CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. */ #define GPIO_SDMMC1_CK (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12) diff --git a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_pinmap.h b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_pinmap.h index 74ee0cd98b3..252e4b0f811 100644 --- a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_pinmap.h +++ b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_pinmap.h @@ -819,8 +819,8 @@ /* SD/MMC * * Note that the below configures GPIO_SPEED_50MHz I/O, that means for using - * the SDMMC, the board's boot code must enable I/O Compensation via the - * configuration option CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. + * the SDIO that you must enable I/O Compensation via the configuration option + * CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. */ #define GPIO_SDMMC1_CK (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12) diff --git a/arch/arm/src/stm32f7/chip/stm32f76xx77xx_pinmap.h b/arch/arm/src/stm32f7/chip/stm32f76xx77xx_pinmap.h index 8e1e70d7a12..8ad8cdb9640 100644 --- a/arch/arm/src/stm32f7/chip/stm32f76xx77xx_pinmap.h +++ b/arch/arm/src/stm32f7/chip/stm32f76xx77xx_pinmap.h @@ -930,8 +930,8 @@ /* SD/MMC * * Note that the below configures GPIO_SPEED_50MHz I/O, that means for using - * the SDMMC, the board's boot code must enable I/O Compensation via the - * configuration option CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. + * the SDIO that you must enable I/O Compensation via the configuration option + * CONFIG_STM32F7_SYSCFG_IOCOMPENSATION=y. */ #define GPIO_SDMMC1_CK (GPIO_ALT|GPIO_AF12|GPIO_SPEED_50MHz|GPIO_PORTC|GPIO_PIN12)