@@ -851,6 +851,69 @@ static void RISAF_Config(void)
851
851
}
852
852
#endif
853
853
854
+ #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
855
+ static int eth_init_api_v2 (const struct device * dev )
856
+ {
857
+ HAL_StatusTypeDef hal_ret = HAL_OK ;
858
+ struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
859
+ ETH_HandleTypeDef * heth = & dev_data -> heth ;
860
+
861
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
862
+ for (int ch = 0 ; ch < ETH_DMA_CH_CNT ; ch ++ ) {
863
+ heth -> Init .TxDesc [ch ] = dma_tx_desc_tab [ch ];
864
+ heth -> Init .RxDesc [ch ] = dma_rx_desc_tab [ch ];
865
+ }
866
+ #else
867
+ heth -> Init .TxDesc = dma_tx_desc_tab ;
868
+ heth -> Init .RxDesc = dma_rx_desc_tab ;
869
+ #endif
870
+ heth -> Init .RxBuffLen = ETH_STM32_RX_BUF_SIZE ;
871
+
872
+ hal_ret = HAL_ETH_Init (heth );
873
+ if (hal_ret == HAL_TIMEOUT ) {
874
+ /* HAL Init time out. This could be linked to
875
+ * a recoverable error. Log the issue and continue
876
+ * driver initialization.
877
+ */
878
+ LOG_ERR ("HAL_ETH_Init Timed out" );
879
+ } else if (hal_ret != HAL_OK ) {
880
+ LOG_ERR ("HAL_ETH_Init failed: %d" , hal_ret );
881
+ return - EINVAL ;
882
+ }
883
+
884
+ #if defined(CONFIG_PTP_CLOCK_STM32_HAL )
885
+ /* Enable timestamping of RX packets. We enable all packets to be
886
+ * timestamped to cover both IEEE 1588 and gPTP.
887
+ */
888
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
889
+ heth -> Instance -> MACTSCR |= ETH_MACTSCR_TSENALL ;
890
+ #else
891
+ heth -> Instance -> PTPTSCR |= ETH_PTPTSCR_TSSARFE ;
892
+ #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
893
+ #endif /* CONFIG_PTP_CLOCK_STM32_HAL */
894
+
895
+ /* Initialize semaphores */
896
+ k_mutex_init (& dev_data -> tx_mutex );
897
+ k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
898
+ k_sem_init (& dev_data -> tx_int_sem , 0 , K_SEM_MAX_LIMIT );
899
+
900
+ /* Tx config init: */
901
+ memset (& tx_config , 0 , sizeof (ETH_TxPacketConfig ));
902
+ tx_config .Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD ;
903
+ tx_config .ChecksumCtrl = IS_ENABLED (CONFIG_ETH_STM32_HW_CHECKSUM )
904
+ ? ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC
905
+ : ETH_CHECKSUM_DISABLE ;
906
+ tx_config .CRCPadCtrl = ETH_CRC_PAD_INSERT ;
907
+
908
+ /* prepare tx buffer header */
909
+ for (uint16_t i = 0 ; i < ETH_TXBUFNB ; ++ i ) {
910
+ dma_tx_buffer_header [i ].tx_buff .buffer = dma_tx_buffer [i ];
911
+ }
912
+
913
+ return 0 ;
914
+ }
915
+ #endif /* CONFIG_ETH_STM32_HAL_API_V2 */
916
+
854
917
static int eth_initialize (const struct device * dev )
855
918
{
856
919
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
@@ -930,7 +993,13 @@ static int eth_initialize(const struct device *dev)
930
993
HAL_ETH_DMARxDescListInit (heth , dma_rx_desc_tab ,
931
994
& dma_rx_buffer [0 ][0 ], ETH_RXBUFNB );
932
995
933
- #endif /* !CONFIG_ETH_STM32_HAL_API_V1 */
996
+ #elif defined(CONFIG_ETH_STM32_HAL_API_V2 )
997
+ ret = eth_init_api_v2 (dev );
998
+
999
+ if (ret != 0 ) {
1000
+ return ret ;
1001
+ }
1002
+ #endif /* CONFIG_ETH_STM32_HAL_API_V1 */
934
1003
935
1004
LOG_DBG ("MAC %02x:%02x:%02x:%02x:%02x:%02x" ,
936
1005
dev_data -> mac_addr [0 ], dev_data -> mac_addr [1 ],
@@ -988,68 +1057,6 @@ static void eth_stm32_mcast_filter(const struct device *dev, const struct ethern
988
1057
989
1058
#endif /* CONFIG_ETH_STM32_MULTICAST_FILTER */
990
1059
991
- #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
992
- static int eth_init_api_v2 (const struct device * dev )
993
- {
994
- HAL_StatusTypeDef hal_ret = HAL_OK ;
995
- struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
996
- ETH_HandleTypeDef * heth = & dev_data -> heth ;
997
-
998
- #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
999
- for (int ch = 0 ; ch < ETH_DMA_CH_CNT ; ch ++ ) {
1000
- heth -> Init .TxDesc [ch ] = dma_tx_desc_tab [ch ];
1001
- heth -> Init .RxDesc [ch ] = dma_rx_desc_tab [ch ];
1002
- }
1003
- #else
1004
- heth -> Init .TxDesc = dma_tx_desc_tab ;
1005
- heth -> Init .RxDesc = dma_rx_desc_tab ;
1006
- #endif
1007
- heth -> Init .RxBuffLen = ETH_STM32_RX_BUF_SIZE ;
1008
-
1009
- hal_ret = HAL_ETH_Init (heth );
1010
- if (hal_ret == HAL_TIMEOUT ) {
1011
- /* HAL Init time out. This could be linked to */
1012
- /* a recoverable error. Log the issue and continue */
1013
- /* driver initialisation */
1014
- LOG_ERR ("HAL_ETH_Init Timed out" );
1015
- } else if (hal_ret != HAL_OK ) {
1016
- LOG_ERR ("HAL_ETH_Init failed: %d" , hal_ret );
1017
- return - EINVAL ;
1018
- }
1019
-
1020
- #if defined(CONFIG_PTP_CLOCK_STM32_HAL )
1021
- /* Enable timestamping of RX packets. We enable all packets to be
1022
- * timestamped to cover both IEEE 1588 and gPTP.
1023
- */
1024
- #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
1025
- heth -> Instance -> MACTSCR |= ETH_MACTSCR_TSENALL ;
1026
- #else
1027
- heth -> Instance -> PTPTSCR |= ETH_PTPTSCR_TSSARFE ;
1028
- #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
1029
- #endif /* CONFIG_PTP_CLOCK_STM32_HAL */
1030
-
1031
- /* Initialize semaphores */
1032
- k_mutex_init (& dev_data -> tx_mutex );
1033
- k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
1034
- k_sem_init (& dev_data -> tx_int_sem , 0 , K_SEM_MAX_LIMIT );
1035
-
1036
- /* Tx config init: */
1037
- memset (& tx_config , 0 , sizeof (ETH_TxPacketConfig ));
1038
- tx_config .Attributes = ETH_TX_PACKETS_FEATURES_CSUM |
1039
- ETH_TX_PACKETS_FEATURES_CRCPAD ;
1040
- tx_config .ChecksumCtrl = IS_ENABLED (CONFIG_ETH_STM32_HW_CHECKSUM ) ?
1041
- ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC : ETH_CHECKSUM_DISABLE ;
1042
- tx_config .CRCPadCtrl = ETH_CRC_PAD_INSERT ;
1043
-
1044
- /* prepare tx buffer header */
1045
- for (uint16_t i = 0 ; i < ETH_TXBUFNB ; ++ i ) {
1046
- dma_tx_buffer_header [i ].tx_buff .buffer = dma_tx_buffer [i ];
1047
- }
1048
-
1049
- return 0 ;
1050
- }
1051
- #endif /* CONFIG_ETH_STM32_HAL_API_V2 */
1052
-
1053
1060
static void set_mac_config (const struct device * dev , struct phy_link_state * state )
1054
1061
{
1055
1062
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
@@ -1170,14 +1177,6 @@ static void eth_iface_init(struct net_if *iface)
1170
1177
1171
1178
ethernet_init (iface );
1172
1179
1173
- #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
1174
- /* This function requires the Ethernet interface to be
1175
- * properly initialized. In auto-negotiation mode, it reads the speed
1176
- * and duplex settings to configure the driver accordingly.
1177
- */
1178
- eth_init_api_v2 (dev );
1179
- #endif
1180
-
1181
1180
setup_mac_filter (heth );
1182
1181
1183
1182
net_if_carrier_off (iface );
0 commit comments