@@ -851,6 +851,68 @@ 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 initialisation */
877
+ LOG_ERR ("HAL_ETH_Init Timed out" );
878
+ } else if (hal_ret != HAL_OK ) {
879
+ LOG_ERR ("HAL_ETH_Init failed: %d" , hal_ret );
880
+ return - EINVAL ;
881
+ }
882
+
883
+ #if defined(CONFIG_PTP_CLOCK_STM32_HAL )
884
+ /* Enable timestamping of RX packets. We enable all packets to be
885
+ * timestamped to cover both IEEE 1588 and gPTP.
886
+ */
887
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
888
+ heth -> Instance -> MACTSCR |= ETH_MACTSCR_TSENALL ;
889
+ #else
890
+ heth -> Instance -> PTPTSCR |= ETH_PTPTSCR_TSSARFE ;
891
+ #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
892
+ #endif /* CONFIG_PTP_CLOCK_STM32_HAL */
893
+
894
+ /* Initialize semaphores */
895
+ k_mutex_init (& dev_data -> tx_mutex );
896
+ k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
897
+ k_sem_init (& dev_data -> tx_int_sem , 0 , K_SEM_MAX_LIMIT );
898
+
899
+ /* Tx config init: */
900
+ memset (& tx_config , 0 , sizeof (ETH_TxPacketConfig ));
901
+ tx_config .Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD ;
902
+ tx_config .ChecksumCtrl = IS_ENABLED (CONFIG_ETH_STM32_HW_CHECKSUM )
903
+ ? ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC
904
+ : ETH_CHECKSUM_DISABLE ;
905
+ tx_config .CRCPadCtrl = ETH_CRC_PAD_INSERT ;
906
+
907
+ /* prepare tx buffer header */
908
+ for (uint16_t i = 0 ; i < ETH_TXBUFNB ; ++ i ) {
909
+ dma_tx_buffer_header [i ].tx_buff .buffer = dma_tx_buffer [i ];
910
+ }
911
+
912
+ return 0 ;
913
+ }
914
+ #endif /* CONFIG_ETH_STM32_HAL_API_V2 */
915
+
854
916
static int eth_initialize (const struct device * dev )
855
917
{
856
918
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
@@ -930,7 +992,13 @@ static int eth_initialize(const struct device *dev)
930
992
HAL_ETH_DMARxDescListInit (heth , dma_rx_desc_tab ,
931
993
& dma_rx_buffer [0 ][0 ], ETH_RXBUFNB );
932
994
933
- #endif /* !CONFIG_ETH_STM32_HAL_API_V1 */
995
+ #elif defined(CONFIG_ETH_STM32_HAL_API_V2 )
996
+ int ret = eth_init_api_v2 (dev );
997
+
998
+ if (ret != 0 ) {
999
+ return ret ;
1000
+ }
1001
+ #endif /* CONFIG_ETH_STM32_HAL_API_V1 */
934
1002
935
1003
LOG_DBG ("MAC %02x:%02x:%02x:%02x:%02x:%02x" ,
936
1004
dev_data -> mac_addr [0 ], dev_data -> mac_addr [1 ],
@@ -988,68 +1056,6 @@ static void eth_stm32_mcast_filter(const struct device *dev, const struct ethern
988
1056
989
1057
#endif /* CONFIG_ETH_STM32_MULTICAST_FILTER */
990
1058
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
1059
static void set_mac_config (const struct device * dev , struct phy_link_state * state )
1054
1060
{
1055
1061
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
@@ -1170,14 +1176,6 @@ static void eth_iface_init(struct net_if *iface)
1170
1176
1171
1177
ethernet_init (iface );
1172
1178
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
1179
setup_mac_filter (heth );
1182
1180
1183
1181
net_if_carrier_off (iface );
0 commit comments