Skip to content

Commit b6e330b

Browse files
committed
drivers: ethernet: eth_stm32_hal: Add stm32n6 ethernet support
-Update the ETH_STM32_HAL menu configuration to conditionally select USE_STM32_HAL_RIF if SOC_SERIES_STM32N6X is enabled. -Align Ethernet descriptors to 32 bytes for STM32N6 to ensure efficient DMA operations and improve cache line efficiency and overall performance -Add RISAF configuration in eth_initialize function for STM32N6 series to set up master and slave security attributes for the Ethernet peripheral. -Ensure RISAF configuration is done before enabling the Ethernet clock to maintain proper security attributes. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <[email protected]>
1 parent 5233d23 commit b6e330b

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

drivers/ethernet/Kconfig.stm32_hal

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ menuconfig ETH_STM32_HAL
99
default y
1010
depends on DT_HAS_ST_STM32_ETHERNET_ENABLED
1111
select USE_STM32_HAL_ETH
12-
select NOCACHE_MEMORY if SOC_SERIES_STM32H7X && CPU_CORTEX_M7
12+
select USE_STM32_HAL_RIF if SOC_SERIES_STM32N6X
13+
select NOCACHE_MEMORY if (SOC_SERIES_STM32H7X && CPU_CORTEX_M7) || SOC_SERIES_STM32N6X
1314
select HWINFO
1415
select ETH_DSA_SUPPORT
1516
select PINCTRL
16-
select MDIO if SOC_SERIES_STM32H5X || SOC_SERIES_STM32H7X
17+
select MDIO if DT_HAS_ST_STM32_MDIO_ENABLED
1718
imply CRC
1819
help
1920
Enable STM32 HAL based Ethernet driver. It is available for
@@ -26,7 +27,8 @@ choice ETH_STM32_HAL_API_VERSION
2627

2728
config ETH_STM32_HAL_API_V2
2829
bool "Use official STM32Cube HAL driver"
29-
depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X
30+
depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32N6X
31+
select USE_STM32_HAL_ETH_EX if SOC_SERIES_STM32N6X
3032
help
3133
Use the official STM32Cube HAL driver instead of the legacy one.
3234

drivers/ethernet/eth_stm32_hal.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,16 @@ static const struct device *eth_stm32_phy_dev = DEVICE_PHY_BY_NAME(0);
131131
#define __eth_stm32_buf __aligned(4)
132132
#endif
133133

134+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
135+
static ETH_DMADescTypeDef
136+
dma_rx_desc_tab[ETH_DMA_RX_CH_CNT][ETH_RXBUFNB] ALIGN_32BYTES(__eth_stm32_desc);
137+
static ETH_DMADescTypeDef
138+
dma_tx_desc_tab[ETH_DMA_TX_CH_CNT][ETH_TXBUFNB] ALIGN_32BYTES(__eth_stm32_desc);
139+
#else
134140
static ETH_DMADescTypeDef dma_rx_desc_tab[ETH_RXBUFNB] __eth_stm32_desc;
135141
static ETH_DMADescTypeDef dma_tx_desc_tab[ETH_TXBUFNB] __eth_stm32_desc;
142+
#endif
143+
136144
static uint8_t dma_rx_buffer[ETH_RXBUFNB][ETH_STM32_RX_BUF_SIZE] __eth_stm32_buf;
137145
static uint8_t dma_tx_buffer[ETH_TXBUFNB][ETH_STM32_TX_BUF_SIZE] __eth_stm32_buf;
138146

@@ -842,7 +850,12 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
842850
CONTAINER_OF(heth, struct eth_stm32_hal_dev_data, heth);
843851

844852
switch (error_code) {
853+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
854+
case HAL_ETH_ERROR_DMA_CH0:
855+
case HAL_ETH_ERROR_DMA_CH1:
856+
#else
845857
case HAL_ETH_ERROR_DMA:
858+
#endif
846859
dma_error = HAL_ETH_GetDMAError(heth);
847860

848861
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet)
@@ -939,6 +952,32 @@ static void generate_mac(uint8_t *mac_addr)
939952
#endif
940953
}
941954

955+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
956+
/**
957+
* Configures the RISAF (RIF Security Attribute Framework) for Ethernet on STM32N6.
958+
* This function sets up the master and slave security attributes for the Ethernet peripheral.
959+
*/
960+
961+
static void RISAF_Config(void)
962+
{
963+
/* Define and initialize the master configuration structure */
964+
RIMC_MasterConfig_t RIMC_master = {0};
965+
966+
/* Enable the clock for the RIFSC (RIF Security Controller) */
967+
__HAL_RCC_RIFSC_CLK_ENABLE();
968+
969+
RIMC_master.MasterCID = RIF_CID_1;
970+
RIMC_master.SecPriv = RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV;
971+
972+
/* Configure the master attributes for the Ethernet peripheral (ETH1) */
973+
HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_ETH1, &RIMC_master);
974+
975+
/* Set the secure and privileged attributes for the Ethernet peripheral (ETH1) as a slave */
976+
HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_ETH1,
977+
RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
978+
}
979+
#endif
980+
942981
static int eth_initialize(const struct device *dev)
943982
{
944983
struct eth_stm32_hal_dev_data *dev_data;
@@ -961,6 +1000,11 @@ static int eth_initialize(const struct device *dev)
9611000
return -ENODEV;
9621001
}
9631002

1003+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
1004+
/* RISAF Configuration */
1005+
RISAF_Config();
1006+
#endif
1007+
9641008
/* enable clock */
9651009
ret = clock_control_on(dev_data->clock,
9661010
(clock_control_subsys_t)&cfg->pclken);
@@ -1193,8 +1237,15 @@ static int eth_init_api_v2(const struct device *dev)
11931237
dev_data = dev->data;
11941238
heth = &dev_data->heth;
11951239

1240+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
1241+
for (int ch = 0; ch < ETH_DMA_CH_CNT; ch++) {
1242+
heth->Init.TxDesc[ch] = dma_tx_desc_tab[ch];
1243+
heth->Init.RxDesc[ch] = dma_rx_desc_tab[ch];
1244+
}
1245+
#else
11961246
heth->Init.TxDesc = dma_tx_desc_tab;
11971247
heth->Init.RxDesc = dma_rx_desc_tab;
1248+
#endif
11981249
heth->Init.RxBuffLen = ETH_STM32_RX_BUF_SIZE;
11991250

12001251
hal_ret = HAL_ETH_Init(heth);

0 commit comments

Comments
 (0)