Skip to content

Commit 60c59d4

Browse files
committed
drivers: ethernet: stm32: Move the Ethernet API V1 init
Move the Ethernet API v1 Initialization in eth_init_api_v1() helper function to match the V2 implementation Signed-off-by: Julien Racki <[email protected]>
1 parent ac05f83 commit 60c59d4

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,43 @@ static void RISAF_Config(void)
851851
}
852852
#endif
853853

854-
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
854+
#if defined(CONFIG_ETH_STM32_HAL_API_V1)
855+
static int eth_init_api_v1(const struct device *dev)
856+
{
857+
HAL_StatusTypeDef hal_ret = HAL_OK;
858+
859+
if (!ETH_STM32_AUTO_NEGOTIATION_ENABLE) {
860+
struct phy_link_state state;
861+
862+
phy_get_link_state(eth_stm32_phy_dev, &state);
863+
864+
heth->Init.DuplexMode = PHY_LINK_IS_FULL_DUPLEX(state.speed) ? ETH_MODE_FULLDUPLEX
865+
: ETH_MODE_HALFDUPLEX;
866+
heth->Init.Speed =
867+
PHY_LINK_IS_SPEED_100M(state.speed) ? ETH_SPEED_100M : ETH_SPEED_10M;
868+
}
869+
870+
hal_ret = HAL_ETH_Init(heth);
871+
if (hal_ret == HAL_TIMEOUT) {
872+
/* HAL Init time out. This could be linked to */
873+
/* a recoverable error. Log the issue and continue */
874+
/* driver initialisation */
875+
LOG_WRN("HAL_ETH_Init timed out (cable not connected?)");
876+
} else if (hal_ret != HAL_OK) {
877+
LOG_ERR("HAL_ETH_Init failed: %d", hal_ret);
878+
return -EINVAL;
879+
}
880+
881+
/* Initialize semaphores */
882+
k_mutex_init(&dev_data->tx_mutex);
883+
k_sem_init(&dev_data->rx_int_sem, 0, K_SEM_MAX_LIMIT);
884+
885+
HAL_ETH_DMATxDescListInit(heth, dma_tx_desc_tab, &dma_tx_buffer[0][0], ETH_TXBUFNB);
886+
HAL_ETH_DMARxDescListInit(heth, dma_rx_desc_tab, &dma_rx_buffer[0][0], ETH_RXBUFNB);
887+
888+
return 0;
889+
}
890+
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
855891
static int eth_init_api_v2(const struct device *dev)
856892
{
857893
HAL_StatusTypeDef hal_ret = HAL_OK;
@@ -958,47 +994,17 @@ static int eth_initialize(const struct device *dev)
958994

959995
heth->Init.MACAddr = dev_data->mac_addr;
960996

961-
#if defined(CONFIG_ETH_STM32_HAL_API_V1)
962-
HAL_StatusTypeDef hal_ret = HAL_OK;
963-
964-
if (!ETH_STM32_AUTO_NEGOTIATION_ENABLE) {
965-
struct phy_link_state state;
966-
967-
phy_get_link_state(eth_stm32_phy_dev, &state);
968-
969-
heth->Init.DuplexMode = PHY_LINK_IS_FULL_DUPLEX(state.speed) ? ETH_MODE_FULLDUPLEX
970-
: ETH_MODE_HALFDUPLEX;
971-
heth->Init.Speed =
972-
PHY_LINK_IS_SPEED_100M(state.speed) ? ETH_SPEED_100M : ETH_SPEED_10M;
973-
}
974-
975-
hal_ret = HAL_ETH_Init(heth);
976-
if (hal_ret == HAL_TIMEOUT) {
977-
/* HAL Init time out. This could be linked to */
978-
/* a recoverable error. Log the issue and continue */
979-
/* driver initialisation */
980-
LOG_WRN("HAL_ETH_Init timed out (cable not connected?)");
981-
} else if (hal_ret != HAL_OK) {
982-
LOG_ERR("HAL_ETH_Init failed: %d", hal_ret);
983-
return -EINVAL;
984-
}
985-
986-
/* Initialize semaphores */
987-
k_mutex_init(&dev_data->tx_mutex);
988-
k_sem_init(&dev_data->rx_int_sem, 0, K_SEM_MAX_LIMIT);
989-
990-
HAL_ETH_DMATxDescListInit(heth, dma_tx_desc_tab,
991-
&dma_tx_buffer[0][0], ETH_TXBUFNB);
992-
HAL_ETH_DMARxDescListInit(heth, dma_rx_desc_tab,
993-
&dma_rx_buffer[0][0], ETH_RXBUFNB);
997+
ret = 0;
994998

999+
#if defined(CONFIG_ETH_STM32_HAL_API_V1)
1000+
ret = eth_init_api_v1(dev);
9951001
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
996-
int ret = eth_init_api_v2(dev);
1002+
ret = eth_init_api_v2(dev);
1003+
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */
9971004

9981005
if (ret != 0) {
9991006
return ret;
10001007
}
1001-
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */
10021008

10031009
LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
10041010
dev_data->mac_addr[0], dev_data->mac_addr[1],

0 commit comments

Comments
 (0)