@@ -814,6 +814,9 @@ static void generate_mac(uint8_t *mac_addr)
814
814
815
815
#endif /* NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))) */
816
816
#endif
817
+
818
+ LOG_DBG ("MAC %02x:%02x:%02x:%02x:%02x:%02x" , mac_addr [0 ], mac_addr [1 ], mac_addr [2 ],
819
+ mac_addr [3 ], mac_addr [4 ], mac_addr [5 ]);
817
820
}
818
821
819
822
#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
@@ -945,28 +948,70 @@ static int eth_initialize(const struct device *dev)
945
948
946
949
heth -> Init .MACAddr = dev_data -> mac_addr ;
947
950
948
- #if defined(CONFIG_ETH_STM32_HAL_API_V1 )
951
+ #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
952
+ HAL_StatusTypeDef hal_ret = HAL_OK ;
953
+
954
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
955
+ for (int ch = 0 ; ch < ETH_DMA_CH_CNT ; ch ++ ) {
956
+ heth -> Init .TxDesc [ch ] = dma_tx_desc_tab [ch ];
957
+ heth -> Init .RxDesc [ch ] = dma_rx_desc_tab [ch ];
958
+ }
959
+ #else
960
+ heth -> Init .TxDesc = dma_tx_desc_tab ;
961
+ heth -> Init .RxDesc = dma_rx_desc_tab ;
962
+ #endif
963
+ heth -> Init .RxBuffLen = ETH_STM32_RX_BUF_SIZE ;
964
+
965
+ hal_ret = HAL_ETH_Init (heth );
966
+ if (hal_ret != HAL_OK ) {
967
+ LOG_ERR ("HAL_ETH_Init failed: %d" , hal_ret );
968
+ return - EIO ;
969
+ }
970
+
971
+ #if defined(CONFIG_PTP_CLOCK_STM32_HAL )
972
+ /* Enable timestamping of RX packets. We enable all packets to be
973
+ * timestamped to cover both IEEE 1588 and gPTP.
974
+ */
975
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
976
+ heth -> Instance -> MACTSCR |= ETH_MACTSCR_TSENALL ;
977
+ #else
978
+ heth -> Instance -> PTPTSCR |= ETH_PTPTSCR_TSSARFE ;
979
+ #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
980
+ #endif /* CONFIG_PTP_CLOCK_STM32_HAL */
981
+
982
+ /* Tx config init: */
983
+ memset (& tx_config , 0 , sizeof (ETH_TxPacketConfig ));
984
+ tx_config .Attributes = ETH_TX_PACKETS_FEATURES_CSUM |
985
+ ETH_TX_PACKETS_FEATURES_CRCPAD ;
986
+ tx_config .ChecksumCtrl = IS_ENABLED (CONFIG_ETH_STM32_HW_CHECKSUM ) ?
987
+ ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC : ETH_CHECKSUM_DISABLE ;
988
+ tx_config .CRCPadCtrl = ETH_CRC_PAD_INSERT ;
989
+
990
+ /* prepare tx buffer header */
991
+ for (uint16_t i = 0 ; i < ETH_TXBUFNB ; ++ i ) {
992
+ dma_tx_buffer_header [i ].tx_buff .buffer = dma_tx_buffer [i ];
993
+ }
994
+
995
+ /* Initialize semaphores */
996
+ k_sem_init (& dev_data -> tx_int_sem , 0 , K_SEM_MAX_LIMIT );
997
+ #else /* CONFIG_ETH_STM32_HAL_API_V2 */
949
998
ret = eth_stm32_init_v1_api (dev );
950
999
if (ret < 0 ) {
951
1000
LOG_ERR ("eth_init_v1_api failed: %d" , ret );
952
1001
return - EIO ;
953
1002
}
954
1003
955
- /* Initialize semaphores */
956
- k_mutex_init (& dev_data -> tx_mutex );
957
- k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
958
-
959
1004
HAL_ETH_DMATxDescListInit (heth , dma_tx_desc_tab ,
960
1005
& dma_tx_buffer [0 ][0 ], ETH_TXBUFNB );
961
1006
HAL_ETH_DMARxDescListInit (heth , dma_rx_desc_tab ,
962
1007
& dma_rx_buffer [0 ][0 ], ETH_RXBUFNB );
1008
+ #endif /* CONFIG_ETH_STM32_HAL_API_V2 */
963
1009
964
- #endif /* !CONFIG_ETH_STM32_HAL_API_V1 */
1010
+ /* Initialize semaphores */
1011
+ k_mutex_init (& dev_data -> tx_mutex );
1012
+ k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
965
1013
966
- LOG_DBG ("MAC %02x:%02x:%02x:%02x:%02x:%02x" ,
967
- dev_data -> mac_addr [0 ], dev_data -> mac_addr [1 ],
968
- dev_data -> mac_addr [2 ], dev_data -> mac_addr [3 ],
969
- dev_data -> mac_addr [4 ], dev_data -> mac_addr [5 ]);
1014
+ setup_mac_filter (heth );
970
1015
971
1016
return 0 ;
972
1017
}
@@ -1019,68 +1064,6 @@ static void eth_stm32_mcast_filter(const struct device *dev, const struct ethern
1019
1064
1020
1065
#endif /* CONFIG_ETH_STM32_MULTICAST_FILTER */
1021
1066
1022
- #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
1023
- static int eth_init_api_v2 (const struct device * dev )
1024
- {
1025
- HAL_StatusTypeDef hal_ret = HAL_OK ;
1026
- struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
1027
- ETH_HandleTypeDef * heth = & dev_data -> heth ;
1028
-
1029
- #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
1030
- for (int ch = 0 ; ch < ETH_DMA_CH_CNT ; ch ++ ) {
1031
- heth -> Init .TxDesc [ch ] = dma_tx_desc_tab [ch ];
1032
- heth -> Init .RxDesc [ch ] = dma_rx_desc_tab [ch ];
1033
- }
1034
- #else
1035
- heth -> Init .TxDesc = dma_tx_desc_tab ;
1036
- heth -> Init .RxDesc = dma_rx_desc_tab ;
1037
- #endif
1038
- heth -> Init .RxBuffLen = ETH_STM32_RX_BUF_SIZE ;
1039
-
1040
- hal_ret = HAL_ETH_Init (heth );
1041
- if (hal_ret == HAL_TIMEOUT ) {
1042
- /* HAL Init time out. This could be linked to */
1043
- /* a recoverable error. Log the issue and continue */
1044
- /* driver initialisation */
1045
- LOG_ERR ("HAL_ETH_Init Timed out" );
1046
- } else if (hal_ret != HAL_OK ) {
1047
- LOG_ERR ("HAL_ETH_Init failed: %d" , hal_ret );
1048
- return - EINVAL ;
1049
- }
1050
-
1051
- #if defined(CONFIG_PTP_CLOCK_STM32_HAL )
1052
- /* Enable timestamping of RX packets. We enable all packets to be
1053
- * timestamped to cover both IEEE 1588 and gPTP.
1054
- */
1055
- #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
1056
- heth -> Instance -> MACTSCR |= ETH_MACTSCR_TSENALL ;
1057
- #else
1058
- heth -> Instance -> PTPTSCR |= ETH_PTPTSCR_TSSARFE ;
1059
- #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
1060
- #endif /* CONFIG_PTP_CLOCK_STM32_HAL */
1061
-
1062
- /* Initialize semaphores */
1063
- k_mutex_init (& dev_data -> tx_mutex );
1064
- k_sem_init (& dev_data -> rx_int_sem , 0 , K_SEM_MAX_LIMIT );
1065
- k_sem_init (& dev_data -> tx_int_sem , 0 , K_SEM_MAX_LIMIT );
1066
-
1067
- /* Tx config init: */
1068
- memset (& tx_config , 0 , sizeof (ETH_TxPacketConfig ));
1069
- tx_config .Attributes = ETH_TX_PACKETS_FEATURES_CSUM |
1070
- ETH_TX_PACKETS_FEATURES_CRCPAD ;
1071
- tx_config .ChecksumCtrl = IS_ENABLED (CONFIG_ETH_STM32_HW_CHECKSUM ) ?
1072
- ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC : ETH_CHECKSUM_DISABLE ;
1073
- tx_config .CRCPadCtrl = ETH_CRC_PAD_INSERT ;
1074
-
1075
- /* prepare tx buffer header */
1076
- for (uint16_t i = 0 ; i < ETH_TXBUFNB ; ++ i ) {
1077
- dma_tx_buffer_header [i ].tx_buff .buffer = dma_tx_buffer [i ];
1078
- }
1079
-
1080
- return 0 ;
1081
- }
1082
- #endif /* CONFIG_ETH_STM32_HAL_API_V2 */
1083
-
1084
1067
static void set_mac_config (const struct device * dev , struct phy_link_state * state )
1085
1068
{
1086
1069
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
@@ -1179,7 +1162,6 @@ static void eth_iface_init(struct net_if *iface)
1179
1162
{
1180
1163
const struct device * dev = net_if_get_device (iface );
1181
1164
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
1182
- ETH_HandleTypeDef * heth = & dev_data -> heth ;
1183
1165
bool is_first_init = false;
1184
1166
1185
1167
if (dev_data -> iface == NULL ) {
@@ -1198,16 +1180,6 @@ static void eth_iface_init(struct net_if *iface)
1198
1180
1199
1181
ethernet_init (iface );
1200
1182
1201
- #if defined(CONFIG_ETH_STM32_HAL_API_V2 )
1202
- /* This function requires the Ethernet interface to be
1203
- * properly initialized. In auto-negotiation mode, it reads the speed
1204
- * and duplex settings to configure the driver accordingly.
1205
- */
1206
- eth_init_api_v2 (dev );
1207
- #endif
1208
-
1209
- setup_mac_filter (heth );
1210
-
1211
1183
net_if_carrier_off (iface );
1212
1184
1213
1185
net_lldp_set_lldpdu (iface );
0 commit comments