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 87d3d41d7523e8466ef541484532c8b5025ca70a Author: raiden00pl <[email protected]> AuthorDate: Tue Nov 17 10:52:46 2026 +0100 arch/arm/stm32n6: Add Ethernet support. Select the common Ethernet v2 driver for ETH1 and add its pins, clocks and RGMII interface selection. ETH1 gets RIF access to Secure memory. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: raiden00pl <[email protected]> --- Documentation/guides/chip-specific/stm32_ports.rst | 2 +- Documentation/platforms/arm/stm32n6/index.rst | 3 +- arch/arm/include/stm32n6/chip.h | 1 + arch/arm/src/stm32n6/CMakeLists.txt | 9 ++- arch/arm/src/stm32n6/Kconfig | 4 + arch/arm/src/stm32n6/Make.defs | 2 +- .../src/stm32n6/hardware/stm32n6xxx_memorymap.h | 2 + arch/arm/src/stm32n6/hardware/stm32n6xxx_pinmap.h | 52 ++++++++++++ arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h | 93 ++++++++++++++++++++++ arch/arm/src/stm32n6/stm32_eth_phyif.h | 50 ++++++++++++ arch/arm/src/stm32n6/stm32_rif.c | 93 ++++++++++++++++++++++ arch/arm/src/stm32n6/stm32_rif.h | 52 ++++++++++++ arch/arm/src/stm32n6/stm32_start.c | 5 ++ arch/arm/src/stm32n6/stm32n6xx_rcc.c | 7 ++ 14 files changed, 371 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/chip-specific/stm32_ports.rst b/Documentation/guides/chip-specific/stm32_ports.rst index f6bc50b113b..712e86f9ec2 100644 --- a/Documentation/guides/chip-specific/stm32_ports.rst +++ b/Documentation/guides/chip-specific/stm32_ports.rst @@ -773,7 +773,7 @@ Peripheral Core version Driver ADC to be done not supported CAN/FDCAN to be done not supported DAC to be done not supported -ETH to be done not supported +ETH v2 arch/arm/src/common/stm32/stm32_eth_v2.c EXTI M33M55 v1 arch/arm/src/common/stm32/stm32_exti_gpio_m33m55_v1.c GPIO M33M55 v1 arch/arm/src/common/stm32/stm32_gpio_m33m55_v1.c GPDMA v1 arch/arm/src/common/stm32/stm32_dma_gpdma.c diff --git a/Documentation/platforms/arm/stm32n6/index.rst b/Documentation/platforms/arm/stm32n6/index.rst index 2146e4e3352..c590c95220c 100644 --- a/Documentation/platforms/arm/stm32n6/index.rst +++ b/Documentation/platforms/arm/stm32n6/index.rst @@ -28,6 +28,8 @@ Peripheral Support Notes GPIO Yes I2C Yes I2C1-4 through the common I2C v2 driver. EXTI Yes GPIO interrupts through the common driver. +ETH Yes ETH1 through the common Ethernet v2 driver, MII, RMII + or RGMII up to 1000 Mbps. DMA Yes GPDMA1 and HPDMA1 through the common GPDMA driver. PWR Yes Supply configuration, VOS, I/O supply validity. RCC Yes HSI/HSE, PLL1-4, IC1-20, bus prescalers and kernel @@ -43,7 +45,6 @@ USART Yes USART1-3, UART4-5, USART6, UART7-9, USART10 and ADC No DCACHE No DCMIPP No -ETH No ICACHE No IWDG No LPTIM No diff --git a/arch/arm/include/stm32n6/chip.h b/arch/arm/include/stm32n6/chip.h index 52ad2f9e110..e2ee26b1901 100644 --- a/arch/arm/include/stm32n6/chip.h +++ b/arch/arm/include/stm32n6/chip.h @@ -62,6 +62,7 @@ #define STM32_NBTIM (2) /* TIM6 and TIM7 */ #define STM32_NI2C (4) /* I2C1-4 */ #define STM32_NSPI (6) /* SPI1-6 */ +#define STM32_NETHERNET (1) /* ETH1 */ /* NVIC priority levels *****************************************************/ diff --git a/arch/arm/src/stm32n6/CMakeLists.txt b/arch/arm/src/stm32n6/CMakeLists.txt index 2d5daca1b71..5f6a7adb7a9 100644 --- a/arch/arm/src/stm32n6/CMakeLists.txt +++ b/arch/arm/src/stm32n6/CMakeLists.txt @@ -26,7 +26,14 @@ set(SRCS) # Required STM32N6 files -list(APPEND SRCS stm32_irq.c stm32_rcc.c stm32_start.c stm32_pwr.c) +list( + APPEND + SRCS + stm32_irq.c + stm32_rcc.c + stm32_start.c + stm32_pwr.c + stm32_rif.c) if(NOT CONFIG_ARCH_IDLE_CUSTOM) list(APPEND SRCS stm32_idle.c) diff --git a/arch/arm/src/stm32n6/Kconfig b/arch/arm/src/stm32n6/Kconfig index 58fe02030bb..cd2c3981b9d 100644 --- a/arch/arm/src/stm32n6/Kconfig +++ b/arch/arm/src/stm32n6/Kconfig @@ -46,6 +46,10 @@ config STM32_N6_PERIPHERALS select STM32_HAVE_IP_WDG_V3 select STM32_HAVE_DMA1 select STM32_HAVE_DMA2 + select STM32_HAVE_ETHERNET + select STM32_HAVE_ETH_AXI + select STM32_HAVE_ETH_RGMII + select STM32_HAVE_IP_ETHMAC_V2 select STM32_HAVE_GPDMA_SECURE select STM32_HAVE_I2C1 select STM32_HAVE_I2C2 diff --git a/arch/arm/src/stm32n6/Make.defs b/arch/arm/src/stm32n6/Make.defs index c8593b3c775..dcbbc7b90df 100644 --- a/arch/arm/src/stm32n6/Make.defs +++ b/arch/arm/src/stm32n6/Make.defs @@ -33,7 +33,7 @@ include common/stm32/Make.defs # Required STM32N6 files CHIP_CSRCS += stm32_irq.c stm32_rcc.c -CHIP_CSRCS += stm32_start.c stm32_pwr.c +CHIP_CSRCS += stm32_start.c stm32_pwr.c stm32_rif.c ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) CHIP_CSRCS += stm32_idle.c diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h b/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h index 16629a1c77c..f81f9ccfba4 100644 --- a/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h +++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h @@ -135,6 +135,7 @@ #define STM32_TAMP_BASE 0x56004400 #define STM32_IWDG_BASE 0x56004800 #define STM32_BSEC_BASE 0x56009000 +#define STM32_SYSMEM_UID 0x56009014 /* 96-bit unique ID (BSEC OTP 5-7) */ #define STM32_DTS_BASE 0x5600a000 /* AHB4 peripherals *********************************************************/ @@ -184,6 +185,7 @@ #define STM32_DMA2_BASE STM32_HPDMA1_BASE #define STM32_XSPI2_BASE 0x5802A000 /* XSPI2 controller (AHB5, Secure) */ #define STM32_XSPIM_BASE 0x5802B400 /* XSPIM IO Manager (AHB5, Secure) */ +#define STM32_EMAC_BASE 0x58036000 /* ETH1 MAC (AHB5, Secure) */ #define STM32_USB1_HS_PHYC_BASE 0x5803FC00 /* USB1 HS PHY controller (Secure) */ #define STM32_USB1_OTG_HS_BASE 0x58040000 /* USB1 OTG HS (Secure) */ #define STM32_USB2_OTG_HS_BASE 0x58080000 /* USB2 OTG HS (Secure) */ diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_pinmap.h b/arch/arm/src/stm32n6/hardware/stm32n6xxx_pinmap.h index d9ad5f2215f..7e6b0d3ec18 100644 --- a/arch/arm/src/stm32n6/hardware/stm32n6xxx_pinmap.h +++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_pinmap.h @@ -46,6 +46,58 @@ * The driver will then automatically configure PE5 as the USART1 TX pin. */ +/* ETH1 */ + +#define GPIO_ETH_CLK_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN5) +#define GPIO_ETH_MDC_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN1) +#define GPIO_ETH_MDC_2 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTG | GPIO_PIN11) +#define GPIO_ETH_MDC_3 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTH | GPIO_PIN5) +#define GPIO_ETH_MDC_4 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTP | GPIO_PIN10) +#define GPIO_ETH_MDIO_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN12) +#define GPIO_ETH_MDIO_2 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN4) +#define GPIO_ETH_MII_COL_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN6) +#define GPIO_ETH_MII_CRS_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN6) +#define GPIO_ETH_MII_RXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN14) +#define GPIO_ETH_MII_RXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN15) +#define GPIO_ETH_MII_RXD2_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN8) +#define GPIO_ETH_MII_RXD3_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN9) +#define GPIO_ETH_MII_RX_CLK_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN7) +#define GPIO_ETH_MII_RX_CLK_2 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN15) +#define GPIO_ETH_MII_RX_DV_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN10) +#define GPIO_ETH_MII_RX_ER_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN5) +#define GPIO_ETH_MII_TXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN12) +#define GPIO_ETH_MII_TXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN13) +#define GPIO_ETH_MII_TXD2_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTG | GPIO_PIN3) +#define GPIO_ETH_MII_TXD3_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTG | GPIO_PIN4) +#define GPIO_ETH_MII_TX_CLK_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN0) +#define GPIO_ETH_MII_TX_EN_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN11) +#define GPIO_ETH_PHY_INTN_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTD | GPIO_PIN3) +#define GPIO_ETH_PHY_INTN_2 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN0) +#define GPIO_ETH_PHY_INTN_3 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN7) +#define GPIO_ETH_PPS_OUT_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN3) +#define GPIO_ETH_RGMII_CLK125_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN2) +#define GPIO_ETH_RGMII_GTX_CLK_1 (GPIO_ALT | GPIO_AF12 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN0) +#define GPIO_ETH_RGMII_RXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN14) +#define GPIO_ETH_RGMII_RXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN15) +#define GPIO_ETH_RGMII_RXD2_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN8) +#define GPIO_ETH_RGMII_RXD3_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN9) +#define GPIO_ETH_RGMII_RX_CLK_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN7) +#define GPIO_ETH_RGMII_RX_CTL_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN10) +#define GPIO_ETH_RGMII_TXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN12) +#define GPIO_ETH_RGMII_TXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN13) +#define GPIO_ETH_RGMII_TXD2_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTG | GPIO_PIN3) +#define GPIO_ETH_RGMII_TXD3_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTG | GPIO_PIN4) +#define GPIO_ETH_RGMII_TX_CTL_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN11) +#define GPIO_ETH_RMII_CRS_DV_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN10) +#define GPIO_ETH_RMII_REF_CLK_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN7) +#define GPIO_ETH_RMII_REF_CLK_2 (GPIO_ALT | GPIO_AF11 | GPIO_PORTG | GPIO_PIN15) +#define GPIO_ETH_RMII_RXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN14) +#define GPIO_ETH_RMII_RXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PORTF | GPIO_PIN15) +#define GPIO_ETH_RMII_TXD0_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN12) +#define GPIO_ETH_RMII_TXD1_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN13) +#define GPIO_ETH_RMII_TX_EN_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN11) +#define GPIO_ETH_TX_ER_1 (GPIO_ALT | GPIO_AF11 | GPIO_PUSHPULL | GPIO_PORTF | GPIO_PIN1) + /* I2C1 */ #define GPIO_I2C1_SCL_1 (GPIO_ALT | GPIO_AF4 | GPIO_OPENDRAIN | GPIO_PORTE | GPIO_PIN5) diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h b/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h new file mode 100644 index 00000000000..6ce8ca67d92 --- /dev/null +++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h @@ -0,0 +1,93 @@ +/**************************************************************************** + * arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h + * + * 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 + * 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_STM32N6_HARDWARE_STM32N6XXX_RIFSC_H +#define __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_RIFSC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include "hardware/stm32_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Offsets *********************************************************/ + +/* SECCFGR/PRIVCFGR: n = 0..5, RIMC_ATTR: n = 0..12 */ + +#define STM32_RIFSC_RISC_CR_OFFSET 0x0000 +#define STM32_RIFSC_RISC_SECCFGR_OFFSET(n) (0x0010 + ((n) << 2)) +#define STM32_RIFSC_RISC_PRIVCFGR_OFFSET(n) (0x0030 + ((n) << 2)) +#define STM32_RIFSC_RIMC_CR_OFFSET 0x0c00 +#define STM32_RIFSC_RIMC_ATTR_OFFSET(n) (0x0c10 + ((n) << 2)) + +/* Register Addresses *******************************************************/ + +#define STM32_RIFSC_RISC_CR (STM32_RIFSC_BASE + \ + STM32_RIFSC_RISC_CR_OFFSET) +#define STM32_RIFSC_RISC_SECCFGR(n) (STM32_RIFSC_BASE + \ + STM32_RIFSC_RISC_SECCFGR_OFFSET(n)) +#define STM32_RIFSC_RISC_PRIVCFGR(n) (STM32_RIFSC_BASE + \ + STM32_RIFSC_RISC_PRIVCFGR_OFFSET(n)) +#define STM32_RIFSC_RIMC_CR (STM32_RIFSC_BASE + \ + STM32_RIFSC_RIMC_CR_OFFSET) +#define STM32_RIFSC_RIMC_ATTR(n) (STM32_RIFSC_BASE + \ + STM32_RIFSC_RIMC_ATTR_OFFSET(n)) + +/* Register Bitfield Definitions ********************************************/ + +/* RIMC master attribute register */ + +#define RIFSC_RIMC_ATTR_MCID_SHIFT (4) /* Bits 4-6: Master compartment ID */ +#define RIFSC_RIMC_ATTR_MCID_MASK (0x7 << RIFSC_RIMC_ATTR_MCID_SHIFT) +# define RIFSC_RIMC_ATTR_MCID(n) ((uint32_t)(n) << RIFSC_RIMC_ATTR_MCID_SHIFT) +#define RIFSC_RIMC_ATTR_MSEC (1 << 8) /* Bit 8: Master secure */ +#define RIFSC_RIMC_ATTR_MPRIV (1 << 9) /* Bit 9: Master privileged */ + +/* RIMC bus master indexes (RIMC_ATTRx) */ + +#define RIFSC_MASTER_ETR 0 +#define RIFSC_MASTER_NPU 1 +#define RIFSC_MASTER_SDMMC1 2 +#define RIFSC_MASTER_SDMMC2 3 +#define RIFSC_MASTER_OTG1 4 +#define RIFSC_MASTER_OTG2 5 +#define RIFSC_MASTER_ETH1 6 +#define RIFSC_MASTER_GPU2D 7 +#define RIFSC_MASTER_DMA2D 8 +#define RIFSC_MASTER_DCMIPP 9 +#define RIFSC_MASTER_LTDC1 10 +#define RIFSC_MASTER_LTDC2 11 +#define RIFSC_MASTER_VENC 12 + +/* RISC peripheral indexes: register number * 32 + bit */ + +#define RIFSC_PERIPH_REG(p) ((p) >> 5) +#define RIFSC_PERIPH_BIT(p) (1 << ((p) & 31)) + +#define RIFSC_PERIPH_ETH1 (1 * 32 + 28) + +#endif /* __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_RIFSC_H */ diff --git a/arch/arm/src/stm32n6/stm32_eth_phyif.h b/arch/arm/src/stm32n6/stm32_eth_phyif.h new file mode 100644 index 00000000000..3ffed5d9787 --- /dev/null +++ b/arch/arm/src/stm32n6/stm32_eth_phyif.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * arch/arm/src/stm32n6/stm32_eth_phyif.h + * + * 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 + * 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_STM32N6_STM32_ETH_PHYIF_H +#define __ARCH_ARM_SRC_STM32N6_STM32_ETH_PHYIF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include "hardware/stm32_rcc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The PHY interface of ETH1 is selected in RCC CCIPR2. + * The common Ethernet MAC driver writes one of the STM32_ETH_PHYIF_<mode> + * values to the STM32_ETH_PHYIF_MASK field of STM32_ETH_PHYIF_REG before it + * resets the MAC. + */ + +#define STM32_ETH_PHYIF_REG STM32_RCC_CCIPR2 +#define STM32_ETH_PHYIF_MASK RCC_CCIPR2_ETH1SEL_MASK +#define STM32_ETH_PHYIF_MII RCC_CCIPR2_ETH1SEL_MII +#define STM32_ETH_PHYIF_RMII RCC_CCIPR2_ETH1SEL_RMII +#define STM32_ETH_PHYIF_RGMII RCC_CCIPR2_ETH1SEL_RGMII + +#endif /* __ARCH_ARM_SRC_STM32N6_STM32_ETH_PHYIF_H */ diff --git a/arch/arm/src/stm32n6/stm32_rif.c b/arch/arm/src/stm32n6/stm32_rif.c new file mode 100644 index 00000000000..51142349efe --- /dev/null +++ b/arch/arm/src/stm32n6/stm32_rif.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * arch/arm/src/stm32n6/stm32_rif.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 + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> + +#include "arm_internal.h" +#include "chip.h" +#include "hardware/stm32n6xxx_rcc.h" +#include "stm32_rif.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Master attributes: compartment 1 (the Cortex-M55), Secure, privileged */ + +#define RIF_MASTER_CID1_SEC_PRIV (RIFSC_RIMC_ATTR_MCID(1) | \ + RIFSC_RIMC_ATTR_MSEC | \ + RIFSC_RIMC_ATTR_MPRIV) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rif_setmaster + ****************************************************************************/ + +static inline void rif_setmaster(unsigned int master, uint32_t attr) +{ + modifyreg32(STM32_RIFSC_RIMC_ATTR(master), + RIFSC_RIMC_ATTR_MCID_MASK | RIFSC_RIMC_ATTR_MSEC | + RIFSC_RIMC_ATTR_MPRIV, attr); +} + +/**************************************************************************** + * Name: rif_setslave_secpriv + ****************************************************************************/ + +static inline void rif_setslave_secpriv(unsigned int periph) +{ + modifyreg32(STM32_RIFSC_RISC_SECCFGR(RIFSC_PERIPH_REG(periph)), 0, + RIFSC_PERIPH_BIT(periph)); + modifyreg32(STM32_RIFSC_RISC_PRIVCFGR(RIFSC_PERIPH_REG(periph)), 0, + RIFSC_PERIPH_BIT(periph)); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_rifconfig + ****************************************************************************/ + +void stm32_rifconfig(void) +{ + putreg32(RCC_AHB3ENR_RIFSCEN, STM32_RCC_AHB3ENSR); + +#ifdef CONFIG_STM32_ETHMAC + /* The ETH1 DMA reads and writes descriptors and buffers in Secure + * AXISRAM + */ + + rif_setmaster(RIFSC_MASTER_ETH1, RIF_MASTER_CID1_SEC_PRIV); + rif_setslave_secpriv(RIFSC_PERIPH_ETH1); +#endif +} diff --git a/arch/arm/src/stm32n6/stm32_rif.h b/arch/arm/src/stm32n6/stm32_rif.h new file mode 100644 index 00000000000..76163cd8b49 --- /dev/null +++ b/arch/arm/src/stm32n6/stm32_rif.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * arch/arm/src/stm32n6/stm32_rif.h + * + * 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 + * 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_STM32N6_STM32_RIF_H +#define __ARCH_ARM_SRC_STM32N6_STM32_RIF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include "hardware/stm32n6xxx_rifsc.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_rifconfig + * + * Description: + * Configure the resource isolation framework for the enabled bus master + * peripherals. NuttX runs in the Secure privileged state, so each + * master that accesses Secure memory must be given the Secure and + * privileged attributes, and its configuration port must be made Secure + * and privileged too. + * + ****************************************************************************/ + +void stm32_rifconfig(void); + +#endif /* __ARCH_ARM_SRC_STM32N6_STM32_RIF_H */ diff --git a/arch/arm/src/stm32n6/stm32_start.c b/arch/arm/src/stm32n6/stm32_start.c index fcd0f7b549a..8b768c3408b 100644 --- a/arch/arm/src/stm32n6/stm32_start.c +++ b/arch/arm/src/stm32n6/stm32_start.c @@ -41,6 +41,7 @@ #include "stm32.h" #include "stm32_gpio.h" #include "stm32_pwr.h" +#include "stm32_rif.h" #include "stm32_start.h" #include "hardware/stm32n6xxx_bsec.h" #include "hardware/stm32n6xxx_ramcfg.h" @@ -249,6 +250,10 @@ void __start_c(void) stm32_clockconfig(); + /* Give the enabled bus masters access to Secure memory */ + + stm32_rifconfig(); + /* Per ES0620, BSECEN must remain set or WFI/sleep fails. Set it via * the atomic SET register, together with SYSCFGEN which we need below. */ diff --git a/arch/arm/src/stm32n6/stm32n6xx_rcc.c b/arch/arm/src/stm32n6/stm32n6xx_rcc.c index 4ea364292af..0550312ef27 100644 --- a/arch/arm/src/stm32n6/stm32n6xx_rcc.c +++ b/arch/arm/src/stm32n6/stm32n6xx_rcc.c @@ -318,6 +318,13 @@ static inline void rcc_enableahb5(void) regval |= RCC_AHB5ENR_HPDMA1EN; #endif +#ifdef CONFIG_STM32_ETHMAC + /* ETH1 bus, MAC, TX and RX clocks */ + + regval |= RCC_AHB5ENR_ETH1EN | RCC_AHB5ENR_ETH1MACEN | + RCC_AHB5ENR_ETH1TXEN | RCC_AHB5ENR_ETH1RXEN; +#endif + if (regval != 0) { putreg32(regval, STM32_RCC_AHB5ENSR);
