Skip to content

Commit 558de73

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 558de73

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,45 @@ 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+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
859+
ETH_HandleTypeDef *heth = &dev_data->heth;
860+
861+
if (!ETH_STM32_AUTO_NEGOTIATION_ENABLE) {
862+
struct phy_link_state state;
863+
864+
phy_get_link_state(eth_stm32_phy_dev, &state);
865+
866+
heth->Init.DuplexMode = PHY_LINK_IS_FULL_DUPLEX(state.speed) ? ETH_MODE_FULLDUPLEX
867+
: ETH_MODE_HALFDUPLEX;
868+
heth->Init.Speed =
869+
PHY_LINK_IS_SPEED_100M(state.speed) ? ETH_SPEED_100M : ETH_SPEED_10M;
870+
}
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_WRN("HAL_ETH_Init timed out (cable not connected?)");
878+
} else if (hal_ret != HAL_OK) {
879+
LOG_ERR("HAL_ETH_Init failed: %d", hal_ret);
880+
return -EINVAL;
881+
}
882+
883+
/* Initialize semaphores */
884+
k_mutex_init(&dev_data->tx_mutex);
885+
k_sem_init(&dev_data->rx_int_sem, 0, K_SEM_MAX_LIMIT);
886+
887+
HAL_ETH_DMATxDescListInit(heth, dma_tx_desc_tab, &dma_tx_buffer[0][0], ETH_TXBUFNB);
888+
HAL_ETH_DMARxDescListInit(heth, dma_rx_desc_tab, &dma_rx_buffer[0][0], ETH_RXBUFNB);
889+
890+
return 0;
891+
}
892+
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
855893
static int eth_init_api_v2(const struct device *dev)
856894
{
857895
HAL_StatusTypeDef hal_ret = HAL_OK;
@@ -958,47 +996,17 @@ static int eth_initialize(const struct device *dev)
958996

959997
heth->Init.MACAddr = dev_data->mac_addr;
960998

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);
999+
ret = 0;
9941000

1001+
#if defined(CONFIG_ETH_STM32_HAL_API_V1)
1002+
ret = eth_init_api_v1(dev);
9951003
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
996-
int ret = eth_init_api_v2(dev);
1004+
ret = eth_init_api_v2(dev);
1005+
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */
9971006

9981007
if (ret != 0) {
9991008
return ret;
10001009
}
1001-
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */
10021010

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

0 commit comments

Comments
 (0)