Skip to content

Commit 6da1cbc

Browse files
juickardanieldegrasse
authored andcommitted
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 1e5f5af commit 6da1cbc

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,46 @@ 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 initialization.
877+
*/
878+
LOG_WRN("HAL_ETH_Init timed out (cable not connected?)");
879+
} else if (hal_ret != HAL_OK) {
880+
LOG_ERR("HAL_ETH_Init failed: %d", hal_ret);
881+
return -EINVAL;
882+
}
883+
884+
/* Initialize semaphores */
885+
k_mutex_init(&dev_data->tx_mutex);
886+
k_sem_init(&dev_data->rx_int_sem, 0, K_SEM_MAX_LIMIT);
887+
888+
HAL_ETH_DMATxDescListInit(heth, dma_tx_desc_tab, &dma_tx_buffer[0][0], ETH_TXBUFNB);
889+
HAL_ETH_DMARxDescListInit(heth, dma_rx_desc_tab, &dma_rx_buffer[0][0], ETH_RXBUFNB);
890+
891+
return 0;
892+
}
893+
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
855894
static int eth_init_api_v2(const struct device *dev)
856895
{
857896
HAL_StatusTypeDef hal_ret = HAL_OK;
@@ -960,46 +999,16 @@ static int eth_initialize(const struct device *dev)
960999
heth->Init.MACAddr = dev_data->mac_addr;
9611000

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

9991009
if (ret != 0) {
10001010
return ret;
10011011
}
1002-
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */
10031012

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

0 commit comments

Comments
 (0)