This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a1e413cc094c58cebf140eb3192a68efa001ad34 Author: raiden00pl <[email protected]> AuthorDate: Sun Nov 15 10:19:14 2026 +0100 arch/arm/stm32: Move the STM32H5 SPI driver to common. The FIFO SPI driver of STM32H5 becomes common/stm32/stm32_spi_v5.c behind STM32_HAVE_IP_SPI_V5, so that other families with the same SPI IP can use it. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: raiden00pl <[email protected]> --- Documentation/guides/chip-specific/stm32_ports.rst | 4 +- arch/arm/src/common/stm32/CMakeLists.txt | 4 + arch/arm/src/common/stm32/Kconfig.have | 11 +- arch/arm/src/common/stm32/Kconfig.spi | 32 ++-- arch/arm/src/common/stm32/Make.defs | 4 + arch/arm/src/common/stm32/hardware/stm32_spi.h | 8 +- .../stm32/hardware/stm32_spi_v5.h} | 17 +- arch/arm/src/common/stm32/stm32_spi.h | 3 +- .../stm32_spi.c => common/stm32/stm32_spi_v5.c} | 52 ++--- arch/arm/src/stm32h5/CMakeLists.txt | 4 - arch/arm/src/stm32h5/Kconfig | 1 + arch/arm/src/stm32h5/Make.defs | 4 - arch/arm/src/stm32h5/chip.h | 9 + arch/arm/src/stm32h5/stm32_spi.h | 210 --------------------- arch/arm/src/stm32h5/stm32h5xx_rcc.c | 26 +++ 15 files changed, 102 insertions(+), 287 deletions(-) diff --git a/Documentation/guides/chip-specific/stm32_ports.rst b/Documentation/guides/chip-specific/stm32_ports.rst index 472a62a4df1..2bbe11d9f99 100644 --- a/Documentation/guides/chip-specific/stm32_ports.rst +++ b/Documentation/guides/chip-specific/stm32_ports.rst @@ -623,7 +623,7 @@ OCTOSPI to be done arch/arm/src/stm32h5/stm32_qspi.c PWR to be done arch/arm/src/stm32h5/stm32_pwr.c RCC to be done arch/arm/src/stm32h5/stm32_rcc.c RTC M33M55 v1 arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c -SPI/I2S to be done arch/arm/src/stm32h5/stm32_spi.c +SPI/I2S v5 arch/arm/src/common/stm32/stm32_spi_v5.c TIM v3 arch/arm/src/common/stm32/stm32_tim.c USART/LPUART M33M55 v3 arch/arm/src/common/stm32/stm32_serial_m33m55_v3.c USB FS arch/arm/src/stm32h5/stm32_usbfs.c @@ -784,7 +784,7 @@ PWR n6 arch/arm/src/stm32n6/stm32_pwr.c RCC n6 arch/arm/src/stm32n6/stm32n6xx_rcc.c RNG v1 arch/arm/src/common/stm32/stm32_rng_v1.c RTC M33M55 v1 arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c -SPI/I2S to be done not supported +SPI/I2S v5 arch/arm/src/common/stm32/stm32_spi_v5.c TIM v3 arch/arm/src/common/stm32/stm32_tim.c USART/LPUART M33M55 v3 arch/arm/src/common/stm32/stm32_serial_m33m55_v3.c USB device not supported diff --git a/arch/arm/src/common/stm32/CMakeLists.txt b/arch/arm/src/common/stm32/CMakeLists.txt index 4f2225522df..2ce79704e10 100644 --- a/arch/arm/src/common/stm32/CMakeLists.txt +++ b/arch/arm/src/common/stm32/CMakeLists.txt @@ -91,6 +91,10 @@ if(CONFIG_STM32_I2C AND CONFIG_STM32_HAVE_IP_I2C_M33M55_V2) list(APPEND SRCS stm32_i2c_m33m55_v2.c) endif() +if(CONFIG_STM32_SPI AND CONFIG_STM32_HAVE_IP_SPI_V5) + list(APPEND SRCS stm32_spi_v5.c) +endif() + if(CONFIG_STM32_COMMON_M33) list(APPEND SRCS stm32_allocateheap_m33_v1.c stm32_irq_m33_v1.c stm32_start_m33_v1.c) diff --git a/arch/arm/src/common/stm32/Kconfig.have b/arch/arm/src/common/stm32/Kconfig.have index 326a6e4d858..586aa4b62c3 100644 --- a/arch/arm/src/common/stm32/Kconfig.have +++ b/arch/arm/src/common/stm32/Kconfig.have @@ -834,7 +834,7 @@ config STM32_HAVE_HASH config STM32_HAVE_SPI_CORE_DMA bool default y if STM32_COMMON_LEGACY || STM32_COMMON_F0_L0_G0_C0 - default y if STM32_COMMON_F7_H7_H5 + default y if STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5 default y if ARCH_CHIP_STM32WL5 default y if STM32_COMMON_L4_L5_U5 && STM32_SPI default y if ARCH_CHIP_STM32WB && (STM32_SPI1 || STM32_SPI2) && STM32_DMA @@ -842,12 +842,12 @@ config STM32_HAVE_SPI_CORE_DMA config STM32_HAVE_SPI_DMA_FAMILY_WL5 bool default y if STM32_COMMON_LEGACY || ARCH_CHIP_STM32F7 - default y if STM32_COMMON_H7_H5 || ARCH_CHIP_STM32WL5 + default y if STM32_COMMON_H7_H5 || ARCH_CHIP_STM32WL5 || STM32_HAVE_IP_SPI_V5 config STM32_HAVE_SPI_DMA_FAMILY bool default y if STM32_COMMON_LEGACY || ARCH_CHIP_STM32F7 - default y if STM32_COMMON_H7_H5 + default y if STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5 config STM32_HAVE_IP_SPI_V1 bool @@ -861,6 +861,11 @@ config STM32_HAVE_IP_SPI_V3 config STM32_HAVE_IP_SPI_V4 bool +config STM32_HAVE_IP_SPI_V5 + bool + ---help--- + SPI with FIFOs, TSIZE and a kernel clock (STM32H5, STM32N6). + config STM32_HAVE_SPI1 bool diff --git a/arch/arm/src/common/stm32/Kconfig.spi b/arch/arm/src/common/stm32/Kconfig.spi index cf360f805c9..ee3af3afa5e 100644 --- a/arch/arm/src/common/stm32/Kconfig.spi +++ b/arch/arm/src/common/stm32/Kconfig.spi @@ -25,14 +25,14 @@ config STM32_SPI1_DMA config STM32_SPI1_DMA_BUFFER int "SPI1 DMA buffer size" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || ARCH_CHIP_STM32WL5) && STM32_SPI1_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5 || ARCH_CHIP_STM32WL5) && STM32_SPI1_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI1. config STM32_SPI_DMATHRESHOLD int "SPI DMA threshold" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || ARCH_CHIP_STM32WL5) && STM32_SPI_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5 || ARCH_CHIP_STM32WL5) && STM32_SPI_DMA default 4 ---help--- When SPI DMA is enabled, small DMA transfers will still be performed @@ -49,7 +49,7 @@ config STM32_SPI2_DMA config STM32_SPI2_DMA_BUFFER int "SPI2 DMA buffer size" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI2_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI2_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI2. @@ -64,49 +64,49 @@ config STM32_SPI3_DMA config STM32_SPI3_DMA_BUFFER int "SPI3 DMA buffer size" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI3_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI3_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI3. config STM32_SPI4_DMA bool "SPI4 DMA" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI && STM32_SPI4 && !STM32_SPI_INTERRUPT + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI4 && !STM32_SPI_INTERRUPT select STM32_SPI_DMA ---help--- Use DMA to improve SPI4 transfer performance. Cannot be used with STM32_SPI_INTERRUPT. config STM32_SPI4_DMA_BUFFER int "SPI4 DMA buffer size" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI4_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI4_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI4. config STM32_SPI5_DMA bool "SPI5 DMA" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI && STM32_SPI5 && !STM32_SPI_INTERRUPT + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI5 && !STM32_SPI_INTERRUPT select STM32_SPI_DMA ---help--- Use DMA to improve SPI5 transfer performance. Cannot be used with STM32_SPI_INTERRUPT. config STM32_SPI5_DMA_BUFFER int "SPI5 DMA buffer size" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI5_DMA + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI5_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI5. config STM32_SPI6_DMA bool "SPI6 DMA" - depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5) && STM32_SPI && STM32_SPI6 && !STM32_SPI_INTERRUPT + depends on (STM32_COMMON_LEGACY || STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI6 && !STM32_SPI_INTERRUPT select STM32_SPI_DMA ---help--- Use DMA to improve SPI6 transfer performance. Cannot be used with STM32_SPI_INTERRUPT. config STM32_SPI1_COMMTYPE int "SPI1 Operation mode" - depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5) && STM32_SPI && STM32_SPI1 + depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI1 default 0 range 0 3 ---help--- @@ -114,7 +114,7 @@ config STM32_SPI1_COMMTYPE config STM32_SPI2_COMMTYPE int "SPI2 Operation mode" - depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5) && STM32_SPI && STM32_SPI2 + depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI2 default 0 range 0 3 ---help--- @@ -122,7 +122,7 @@ config STM32_SPI2_COMMTYPE config STM32_SPI3_COMMTYPE int "SPI3 Operation mode" - depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5) && STM32_SPI && STM32_SPI3 + depends on (STM32_COMMON_F0_L0_G0_C0 || STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI3 default 0 range 0 3 ---help--- @@ -130,14 +130,14 @@ config STM32_SPI3_COMMTYPE config STM32_SPI6_DMA_BUFFER int "SPI6 DMA buffer size" - depends on (STM32_COMMON_F7_H7_H5) && STM32_SPI6_DMA + depends on (STM32_COMMON_F7_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI6_DMA default 0 ---help--- Add a properly aligned DMA buffer for RX and TX DMA for SPI6. config STM32_SPI4_COMMTYPE int "SPI4 Operation mode" - depends on STM32_COMMON_H7_H5 && STM32_SPI && STM32_SPI4 + depends on (STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI4 default 0 range 0 3 ---help--- @@ -145,7 +145,7 @@ config STM32_SPI4_COMMTYPE config STM32_SPI5_COMMTYPE int "SPI5 Operation mode" - depends on STM32_COMMON_H7_H5 && STM32_SPI && STM32_SPI5 + depends on (STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI5 default 0 range 0 3 ---help--- @@ -153,7 +153,7 @@ config STM32_SPI5_COMMTYPE config STM32_SPI6_COMMTYPE int "SPI6 Operation mode" - depends on STM32_COMMON_H7_H5 && STM32_SPI && STM32_SPI6 + depends on (STM32_COMMON_H7_H5 || STM32_HAVE_IP_SPI_V5) && STM32_SPI && STM32_SPI6 default 0 range 0 3 ---help--- diff --git a/arch/arm/src/common/stm32/Make.defs b/arch/arm/src/common/stm32/Make.defs index a555c3bb226..48cd8e6a5b2 100644 --- a/arch/arm/src/common/stm32/Make.defs +++ b/arch/arm/src/common/stm32/Make.defs @@ -102,6 +102,10 @@ ifeq ($(CONFIG_STM32_I2C)$(CONFIG_STM32_HAVE_IP_I2C_M33M55_V2),yy) CHIP_CSRCS += stm32_i2c_m33m55_v2.c endif +ifeq ($(CONFIG_STM32_SPI)$(CONFIG_STM32_HAVE_IP_SPI_V5),yy) +CHIP_CSRCS += stm32_spi_v5.c +endif + ifeq ($(CONFIG_STM32_COMMON_M33),y) CHIP_CSRCS += stm32_allocateheap_m33_v1.c CHIP_CSRCS += stm32_irq_m33_v1.c diff --git a/arch/arm/src/common/stm32/hardware/stm32_spi.h b/arch/arm/src/common/stm32/hardware/stm32_spi.h index 2d9836336ef..a194ab5e6df 100644 --- a/arch/arm/src/common/stm32/hardware/stm32_spi.h +++ b/arch/arm/src/common/stm32/hardware/stm32_spi.h @@ -36,15 +36,19 @@ #if (defined(CONFIG_STM32_HAVE_IP_SPI_V1) + \ defined(CONFIG_STM32_HAVE_IP_SPI_V2) + \ defined(CONFIG_STM32_HAVE_IP_SPI_V3) + \ - defined(CONFIG_STM32_HAVE_IP_SPI_V4)) > 1 + defined(CONFIG_STM32_HAVE_IP_SPI_V4) + \ + defined(CONFIG_STM32_HAVE_IP_SPI_V5)) > 1 # error Only one STM32 SPI IP version must be selected #endif #if !(defined(CONFIG_STM32_HAVE_IP_SPI_V1) || \ defined(CONFIG_STM32_HAVE_IP_SPI_V2) || \ defined(CONFIG_STM32_HAVE_IP_SPI_V3) || \ - defined(CONFIG_STM32_HAVE_IP_SPI_V4)) + defined(CONFIG_STM32_HAVE_IP_SPI_V4) || \ + defined(CONFIG_STM32_HAVE_IP_SPI_V5)) # error "Unsupported STM32 SPI" +#elif defined(CONFIG_STM32_HAVE_IP_SPI_V5) +# include "hardware/stm32_spi_v5.h" #elif defined(CONFIG_ARCH_CORTEXM0) # include "hardware/stm32_spi_v1v2_m0.h" #else diff --git a/arch/arm/src/stm32h5/hardware/stm32h5xxx_spi.h b/arch/arm/src/common/stm32/hardware/stm32_spi_v5.h similarity index 98% rename from arch/arm/src/stm32h5/hardware/stm32h5xxx_spi.h rename to arch/arm/src/common/stm32/hardware/stm32_spi_v5.h index 14418be6737..c4006f0433a 100644 --- a/arch/arm/src/stm32h5/hardware/stm32h5xxx_spi.h +++ b/arch/arm/src/common/stm32/hardware/stm32_spi_v5.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/stm32h5/hardware/stm32h5xxx_spi.h + * arch/arm/src/common/stm32/hardware/stm32_spi_v5.h * * SPDX-License-Identifier: Apache-2.0 * @@ -20,8 +20,8 @@ * ****************************************************************************/ -#ifndef __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32H5XXX_SPI_H -#define __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32H5XXX_SPI_H +#ifndef __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_SPI_V5_H +#define __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_SPI_V5_H /**************************************************************************** * Included Files @@ -29,18 +29,10 @@ #include <nuttx/config.h> -#if defined(CONFIG_STM32_STM32H5XXXX) - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Maximum allowed speed as per data sheet for all SPIs - * See Table 115 in DS14258 Rev 3 - */ - -# define STM32_SPI_CLK_MAX 120000000UL - /* Register Offsets *********************************************************/ #define STM32_SPI_CR1_OFFSET 0x0000 /* SPI/I2S Control Register 1 */ @@ -489,5 +481,4 @@ #define SPI_I2SCFGR_ODD (1 << 24) /* Bit 24: Odd Factor for the Prescaler */ #define SPI_I2SCFGR_MCKOE (1 << 25) /* Bit 24: Master Clock Output Enable */ -#endif /* CONFIG_STM32_STM32H5XXX */ -#endif /* __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32H5XXX_SPI_H */ +#endif /* __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_SPI_V5_H */ diff --git a/arch/arm/src/common/stm32/stm32_spi.h b/arch/arm/src/common/stm32/stm32_spi.h index d68b3a2d1a3..6120f75fddd 100644 --- a/arch/arm/src/common/stm32/stm32_spi.h +++ b/arch/arm/src/common/stm32/stm32_spi.h @@ -32,7 +32,8 @@ #if !(defined(CONFIG_STM32_HAVE_IP_SPI_V1) || \ defined(CONFIG_STM32_HAVE_IP_SPI_V2) || \ defined(CONFIG_STM32_HAVE_IP_SPI_V3) || \ - defined(CONFIG_STM32_HAVE_IP_SPI_V4)) + defined(CONFIG_STM32_HAVE_IP_SPI_V4) || \ + defined(CONFIG_STM32_HAVE_IP_SPI_V5)) # error "Unsupported STM32 SPI" #endif diff --git a/arch/arm/src/stm32h5/stm32_spi.c b/arch/arm/src/common/stm32/stm32_spi_v5.c similarity index 98% rename from arch/arm/src/stm32h5/stm32_spi.c rename to arch/arm/src/common/stm32/stm32_spi_v5.c index ae0f4b01066..ab1e958f076 100644 --- a/arch/arm/src/stm32h5/stm32_spi.c +++ b/arch/arm/src/common/stm32/stm32_spi_v5.c @@ -1,5 +1,7 @@ /**************************************************************************** - * arch/arm/src/stm32h5/stm32_spi.c + * arch/arm/src/common/stm32/stm32_spi_v5.c + * + * SPDX-License-Identifier: Apache-2.0 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -67,19 +69,23 @@ #include <arch/board/board.h> #include "arm_internal.h" -#include "chip.h" -#include "stm32_rcc.h" -#include "stm32_gpio.h" +#include "stm32.h" #include "stm32_spi.h" #ifdef CONFIG_STM32_SPI_DMA #include "stm32_dma.h" #endif -#if defined(CONFIG_STM32_STM32H50XXX) -# define SPI_MAX_KER_CK 250000000 -#else -# define SPI_MAX_KER_CK 125000000 +/* The maximum SPI kernel clock and the maximum SPI clock come from the + * family chip.h. + */ + +#ifndef STM32_SPI_MAX_KER_CK +# error "STM32_SPI_MAX_KER_CK must be defined in chip.h" +#endif + +#ifndef STM32_SPI_CLK_MAX +# error "STM32_SPI_CLK_MAX must be defined in chip.h" #endif #if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \ @@ -185,78 +191,60 @@ # ifndef STM32_SPI1_FREQUENCY # error Must define STM32_SPI1_FREQUENCY in board.h # else -# if STM32_SPI1_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI1_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI1 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI1SEL -# error Must define STM32_RCC_CCIPR3_SPI1SEL in board.h -# endif #endif /* SPI1 */ #if defined(CONFIG_STM32_SPI2) # ifndef STM32_SPI2_FREQUENCY # error Must define STM32_SPI2_FREQUENCY in board.h # else -# if STM32_SPI2_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI2_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI2 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI2SEL -# error Must define STM32_RCC_CCIPR3_SPI2SEL in board.h -# endif #endif /* SPI2 */ #if defined(CONFIG_STM32_SPI3) # ifndef STM32_SPI3_FREQUENCY # error Must define STM32_SPI3_FREQUENCY in board.h # else -# if STM32_SPI3_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI3_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI3 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI3SEL -# error Must define STM32_RCC_CCIPR3_SPI3SEL in board.h -# endif #endif /* SPI3 */ #if defined(CONFIG_STM32_SPI4) # ifndef STM32_SPI4_FREQUENCY # error Must define STM32_SPI4_FREQUENCY in board.h # else -# if STM32_SPI4_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI4_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI4 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI4SEL -# error Must define STM32_RCC_CCIPR3_SPI4SEL in board.h -# endif #endif /* SPI4 */ #if defined(CONFIG_STM32_SPI5) # ifndef STM32_SPI5_FREQUENCY # error Must define STM32_SPI5_FREQUENCY in board.h # else -# if STM32_SPI5_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI5_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI5 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI5SEL -# error Must define STM32_RCC_CCIPR3_SPI5SEL in board.h -# endif #endif /* SPI5 */ #if defined(CONFIG_STM32_SPI6) # ifndef STM32_SPI6_FREQUENCY # error Must define STM32_SPI6_FREQUENCY in board.h # else -# if STM32_SPI6_FREQUENCY > SPI_MAX_KER_CK +# if STM32_SPI6_FREQUENCY > STM32_SPI_MAX_KER_CK # error Not supported SPI6 frequency # endif # endif -# ifndef STM32_RCC_CCIPR3_SPI6SEL -# error Must define STM32_RCC_CCIPR3_SPI6SEL in board.h -# endif #endif /* SPI6 */ /**************************************************************************** diff --git a/arch/arm/src/stm32h5/CMakeLists.txt b/arch/arm/src/stm32h5/CMakeLists.txt index 1c9d5b50f0f..9af853b320d 100644 --- a/arch/arm/src/stm32h5/CMakeLists.txt +++ b/arch/arm/src/stm32h5/CMakeLists.txt @@ -56,10 +56,6 @@ if(CONFIG_STM32H5_EFUSE) list(APPEND SRCS stm32_efuse.c) endif() -if(CONFIG_STM32_SPI) - list(APPEND SRCS stm32_spi.c) -endif() - if(CONFIG_STM32_QSPI1) list(APPEND SRCS stm32_qspi.c) endif() diff --git a/arch/arm/src/stm32h5/Kconfig b/arch/arm/src/stm32h5/Kconfig index d8fa984e089..59379972da6 100644 --- a/arch/arm/src/stm32h5/Kconfig +++ b/arch/arm/src/stm32h5/Kconfig @@ -42,6 +42,7 @@ config STM32_H5_PERIPHERALS select STM32_HAVE_USART_WUS select STM32_HAVE_I2C_H5 select STM32_HAVE_IP_I2C_M33M55_V2 + select STM32_HAVE_IP_SPI_V5 select STM32_HAVE_CRC select STM32_HAVE_IP_WDG_V3 diff --git a/arch/arm/src/stm32h5/Make.defs b/arch/arm/src/stm32h5/Make.defs index b38728796e3..2af48ae8600 100644 --- a/arch/arm/src/stm32h5/Make.defs +++ b/arch/arm/src/stm32h5/Make.defs @@ -64,10 +64,6 @@ ifeq ($(CONFIG_STM32H5_EFUSE),y) CHIP_CSRCS += stm32_efuse.c endif -ifeq ($(CONFIG_STM32_SPI),y) -CHIP_CSRCS += stm32_spi.c -endif - ifeq ($(CONFIG_STM32_QSPI1),y) CHIP_CSRCS += stm32_qspi.c endif diff --git a/arch/arm/src/stm32h5/chip.h b/arch/arm/src/stm32h5/chip.h index 099478bdb3d..cf0f9d796c5 100644 --- a/arch/arm/src/stm32h5/chip.h +++ b/arch/arm/src/stm32h5/chip.h @@ -62,6 +62,15 @@ * ICACHE implementation, pg 367, Table 85. */ +/* SPI kernel clock and SPI clock limits (DS14258) */ + +#if defined(CONFIG_STM32_STM32H50XXX) +# define STM32_SPI_MAX_KER_CK 250000000 +#else +# define STM32_SPI_MAX_KER_CK 125000000 +#endif +#define STM32_SPI_CLK_MAX 120000000UL + #define ARMV8M_ICACHE_LINESIZE 16 /* 16 bytes */ #define ARMV8M_DCACHE_LINESIZE 16 /* 16 bytes */ diff --git a/arch/arm/src/stm32h5/stm32_spi.h b/arch/arm/src/stm32h5/stm32_spi.h deleted file mode 100644 index b0ea71b7c35..00000000000 --- a/arch/arm/src/stm32h5/stm32_spi.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32h5/stm32_spi.h - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __ARCH_ARM_SRC_STM32H5_STM32_SPI_H -#define __ARCH_ARM_SRC_STM32H5_STM32_SPI_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> - -#include "chip.h" -#include "hardware/stm32h5xxx_spi.h" - -#ifndef __ASSEMBLY__ - -#if defined(__cplusplus) -extern "C" -{ -#endif - -struct spi_dev_s; /* Forward reference */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_spibus_initialize - * - * Description: - * Initialize the selected SPI bus - * - * Input Parameters: - * bus number (for hardware that has multiple SPI interfaces) - * - * Returned Value: - * Valid SPI device structure reference on success; a NULL on failure - * - ****************************************************************************/ - -struct spi_dev_s *stm32_spibus_initialize(int bus); - -/**************************************************************************** - * Name: stm32_spi_slave_initialize - * - * Description: - * Initialize the selected SPI bus for slave operation - * - * Input Parameters: - * bus number - * - * Returned Value: - * Valid SPI device structure reference on success; a NULL on failure - * - ****************************************************************************/ - -struct spi_slave_ctrlr_s *stm32_spi_slave_initialize(int bus); - -/**************************************************************************** - * Name: stm32_spi1/2/...select and stm32_spi1/2/...status - * - * Description: - * The external functions, stm32_spi1/2/...select, stm32_spi1/2/...status, - * and stm32_spi1/2/...cmddata must be provided by board-specific logic. - * These are implementations of the select, status, and cmddata methods of - * the SPI interface defined by struct spi_ops_s (see - * include/nuttx/spi/spi.h). - * All other methods (including stm32_spibus_initialize()) are provided by - * common STM32 logic. To use this common SPI logic on your board: - * - * 1. Provide logic in stm32_boardinitialize() to configure SPI chip select - * pins. - * 2. Provide stm32_spi1/2/...select() and stm32_spi1/2/...status() - * functions in your board-specific logic. These functions will perform - * chip selection and status operations using GPIOs in the way your - * board is configured. - * 3. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration file, - * then provide stm32_spi1/2/...cmddata() functions in your board- - * specific logic. These functions will perform cmd/data selection - * operations using GPIOs in the way your board is configured. - * 4. Add a call to stm32_spibus_initialize() in your low level - * application initialization logic - * 5. The handle returned by stm32_spibus_initialize() may then be used to - * bind the SPI driver to higher level logic (e.g., calling - * mmcsd_spislotinitialize(), for example, will bind the SPI driver to - * the SPI MMC/SD driver). - * - ****************************************************************************/ - -#ifdef CONFIG_STM32_SPI1 -void stm32_spi1select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -#ifdef CONFIG_STM32_SPI2 -void stm32_spi2select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi2status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi2cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -#ifdef CONFIG_STM32_SPI3 -void stm32_spi3select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi3status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi3cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -#ifdef CONFIG_STM32_SPI4 - void stm32_spi4select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi4status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi4cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -#ifdef CONFIG_STM32_SPI5 -void stm32_spi5select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi5status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi5cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -#ifdef CONFIG_STM32_SPI6 -void stm32_spi6select(struct spi_dev_s *dev, uint32_t devid, - bool selected); -uint8_t stm32_spi6status(struct spi_dev_s *dev, uint32_t devid); -int stm32_spi6cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd); -#endif - -/**************************************************************************** - * Name: stm32_spi1/2/...register - * - * Description: - * If the board supports a card detect callback to inform the SPI-based - * MMC/SD driver when an SD card is inserted or removed, then - * CONFIG_SPI_CALLBACK should be defined and the following function(s) must - * be implemented. These functions implement the registercallback method - * of the SPI interface (see include/nuttx/spi/spi.h for details) - * - * Input Parameters: - * dev - Device-specific state data - * callback - The function to call on the media change - * arg - A caller provided value to return with the callback - * - * Returned Value: - * 0 on success; negated errno on failure. - * - ****************************************************************************/ - -#ifdef CONFIG_SPI_CALLBACK -#ifdef CONFIG_STM32_SPI1 -int stm32_spi1register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif - -#ifdef CONFIG_STM32_SPI2 -int stm32_spi2register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif - -#ifdef CONFIG_STM32_SPI3 -int stm32_spi3register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif - -#ifdef CONFIG_STM32_SPI4 -int stm32_spi4register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif - -#ifdef CONFIG_STM32_SPI5 -int stm32_spi5register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif - -#ifdef CONFIG_STM32_SPI6 -int stm32_spi6register(struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); -#endif -#endif - -#if defined(__cplusplus) -} -#endif - -#endif /* __ASSEMBLY__ */ -#endif /* __ARCH_ARM_SRC_STM32H5_STM32_SPI_H */ diff --git a/arch/arm/src/stm32h5/stm32h5xx_rcc.c b/arch/arm/src/stm32h5/stm32h5xx_rcc.c index 324fdbba841..d80d0c565af 100644 --- a/arch/arm/src/stm32h5/stm32h5xx_rcc.c +++ b/arch/arm/src/stm32h5/stm32h5xx_rcc.c @@ -60,6 +60,32 @@ static_assert(CONFIG_BOARD_LOOPSPERMSEC != -1, #define HSE_DIVISOR (STM32_HSE_FREQUENCY + 500000) / 1000000 +/* The SPI kernel clocks are selected by board.h */ + +#if defined(CONFIG_STM32_SPI1) && !defined(STM32_RCC_CCIPR3_SPI1SEL) +# error Must define STM32_RCC_CCIPR3_SPI1SEL in board.h +#endif + +#if defined(CONFIG_STM32_SPI2) && !defined(STM32_RCC_CCIPR3_SPI2SEL) +# error Must define STM32_RCC_CCIPR3_SPI2SEL in board.h +#endif + +#if defined(CONFIG_STM32_SPI3) && !defined(STM32_RCC_CCIPR3_SPI3SEL) +# error Must define STM32_RCC_CCIPR3_SPI3SEL in board.h +#endif + +#if defined(CONFIG_STM32_SPI4) && !defined(STM32_RCC_CCIPR3_SPI4SEL) +# error Must define STM32_RCC_CCIPR3_SPI4SEL in board.h +#endif + +#if defined(CONFIG_STM32_SPI5) && !defined(STM32_RCC_CCIPR3_SPI5SEL) +# error Must define STM32_RCC_CCIPR3_SPI5SEL in board.h +#endif + +#if defined(CONFIG_STM32_SPI6) && !defined(STM32_RCC_CCIPR3_SPI6SEL) +# error Must define STM32_RCC_CCIPR3_SPI6SEL in board.h +#endif + /* Determine if board wants to use HSI48 as 48 MHz oscillator. */ #if defined(CONFIG_STM32_HAVE_HSI48) && defined(STM32_USE_CLK48)
