Skip to content

Commit aa5353a

Browse files
Bjarne von Horncarlescufi
authored andcommitted
drivers: ethernet: stm32: Enable receiving with new driver
Use the new API in the receive method Signed-off-by: Bjarne von Horn <[email protected]>
1 parent 202abc9 commit aa5353a

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,23 @@ static struct net_pkt *eth_rx(const struct device *dev, uint16_t *vlan_tag)
590590
{
591591
struct eth_stm32_hal_dev_data *dev_data;
592592
ETH_HandleTypeDef *heth;
593+
struct net_pkt *pkt;
594+
size_t total_len = 0;
595+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
596+
void *appbuf = NULL;
597+
struct eth_stm32_rx_buffer_header *rx_header;
598+
#else
593599
#if !defined(CONFIG_SOC_SERIES_STM32H7X)
594600
__IO ETH_DMADescTypeDef *dma_rx_desc;
595601
#endif /* !CONFIG_SOC_SERIES_STM32H7X */
596-
struct net_pkt *pkt;
597-
size_t total_len;
598602
uint8_t *dma_buffer;
599603
HAL_StatusTypeDef hal_ret = HAL_OK;
604+
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
600605
#if defined(CONFIG_PTP_CLOCK_STM32_HAL)
601606
struct net_ptp_time timestamp;
607+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
608+
ETH_TimeStampTypeDef ts_registers;
609+
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
602610
/* Default to invalid value. */
603611
timestamp.second = UINT64_MAX;
604612
timestamp.nanosecond = UINT32_MAX;
@@ -612,7 +620,18 @@ static struct net_pkt *eth_rx(const struct device *dev, uint16_t *vlan_tag)
612620

613621
heth = &dev_data->heth;
614622

615-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
623+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
624+
if (HAL_ETH_ReadData(heth, &appbuf) != HAL_OK) {
625+
/* no frame available */
626+
return NULL;
627+
}
628+
629+
/* computing total length */
630+
for (rx_header = (struct eth_stm32_rx_buffer_header *)appbuf;
631+
rx_header; rx_header = rx_header->next) {
632+
total_len += rx_header->size;
633+
}
634+
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
616635
if (HAL_ETH_IsRxDataAvailable(heth) != true) {
617636
/* no frame available */
618637
return NULL;
@@ -649,7 +668,14 @@ static struct net_pkt *eth_rx(const struct device *dev, uint16_t *vlan_tag)
649668
#endif /* CONFIG_SOC_SERIES_STM32H7X */
650669

651670
#if defined(CONFIG_PTP_CLOCK_STM32_HAL)
652-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
671+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
672+
673+
if (HAL_ETH_PTP_GetRxTimestamp(heth, &ts_registers) == HAL_OK) {
674+
timestamp.second = ts_registers.TimeStampHigh;
675+
timestamp.nanosecond = ts_registers.TimeStampLow;
676+
}
677+
678+
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
653679
ETH_RxDescListTypeDef * dma_rx_desc_list;
654680

655681
dma_rx_desc_list = &heth->RxDescList;
@@ -698,15 +724,36 @@ static struct net_pkt *eth_rx(const struct device *dev, uint16_t *vlan_tag)
698724
goto release_desc;
699725
}
700726

727+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
728+
for (rx_header = (struct eth_stm32_rx_buffer_header *)appbuf;
729+
rx_header; rx_header = rx_header->next) {
730+
const size_t index = rx_header - &dma_rx_buffer_header[0];
731+
732+
__ASSERT_NO_MSG(index < ETH_RXBUFNB);
733+
if (net_pkt_write(pkt, dma_rx_buffer[index], rx_header->size)) {
734+
LOG_ERR("Failed to append RX buffer to context buffer");
735+
net_pkt_unref(pkt);
736+
pkt = NULL;
737+
goto release_desc;
738+
}
739+
}
740+
#else
701741
if (net_pkt_write(pkt, dma_buffer, total_len)) {
702742
LOG_ERR("Failed to append RX buffer to context buffer");
703743
net_pkt_unref(pkt);
704744
pkt = NULL;
705745
goto release_desc;
706746
}
747+
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
707748

708749
release_desc:
709-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
750+
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
751+
for (rx_header = (struct eth_stm32_rx_buffer_header *)appbuf;
752+
rx_header; rx_header = rx_header->next) {
753+
rx_header->used = false;
754+
}
755+
756+
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
710757
hal_ret = HAL_ETH_BuildRxDescriptors(heth);
711758
if (hal_ret != HAL_OK) {
712759
LOG_ERR("HAL_ETH_BuildRxDescriptors: failed: %d", hal_ret);
@@ -734,7 +781,7 @@ static struct net_pkt *eth_rx(const struct device *dev, uint16_t *vlan_tag)
734781
/* Resume DMA reception */
735782
heth->Instance->DMARPDR = 0;
736783
}
737-
#endif /* CONFIG_SOC_SERIES_STM32H7X */
784+
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
738785

739786
if (!pkt) {
740787
goto out;

0 commit comments

Comments
 (0)