2017-06-23 05:04 AM
Hi!
Currently I'm using lwip + tinymDNS on a stm32f207.
The mDNS needs multicast packets. I activated IGMP in the lwip stack and it works.
mDNS messages were sent as mutlicast packets.
But the one thing that did not work was the reception of multicast packets.
After some digging I found the ETH configuration in the STM HAL drivers.
There the multicast frame filtering is set to 'PERFECT'. But no filter MACs are set up.
When I wrote the right MAC into the ETH_MACA1 register manually and activated it by setting the AE bit everything worked.
I would have expected that when I join a igmp group that the according MAC is set as a filter. Or that at least the multicast frame filtering would be disabled alltogether. But I could not find anything related to that in the code.
Is that functionality not implemented or am I just blind?
My stm32f2xx_hal_eth.c is v1.1.3 from June 2016. And lwip 1.4.1.
Thanks for any hints and best regards,
Sebastian
2017-06-23 06:58 AM
Hi,
You may check the last version of STM32CubeF2 firmware package with upgrade the version of LwIP v2.0.0
Regards
Imen
2017-06-26 01:30 AM
Hi Imen,
thanks for the tipp.
I looked into the new CubeF2 with lwip 2.0.0. The relevant stm32f2xx_hal_eth file is now verison 1.2.1 (was 1.1.3 for me). But there seem to be no changes regarding multicast filtering. Since this is a matter of changing settings in the hardware something should show up in the stm files.
The MAC filters are set with the function
static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
in stm32f2xx_hal_eth.c/.h.
That function is calles once:
ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
Here the own MAC address is set (
ETH_MAC_ADDRESS0). When looking for ETH_MAC_ADDRESS , so any other use of this constant for any of the four registers (including the three registers 1,2,3 used for filtering), nothing comes up.
So I still think that this functionality is not implemented. Right?
Best regards
Sebastian
2017-07-20 08:57 AM
Hi Sebastian,
I had a similar problem on the F7. I was able to receive multicast packages by enabling the promiscuous mode for the ETH controller, like so:
ETH_MACInitTypeDef conf = {0};
conf.PromiscuousMode = ETH_PROMISCUOUS_MODE_ENABLE; HAL_ETH_ConfigMAC(ð_handle, &conf);Using this after a call to 'HAL_ETH_Init' worked for me.
Thomas
2017-07-25 02:05 AM
Hi Thomas,
Thank you for the advice. So I guess it is a lack of functionality in the drivers.
I'm a bit hesitant to switch to promiscuous mode. In the past I had bad experience with device being overwhelmed by mcast traffic that wasn't even relevant for them.
My solution at the moment is a hack in the driver to set the MAC filter 1 for the mDNS mcast address.
What I did is:
in stm32f2xx_hal_eth.htypedef struct{ ... uint8_t *MACAddr; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */ uint8_t *MACFilter; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */ uint32_t RxMode; /*!< Selects the Ethernet Rx mode: Polling mode, Interrupt mode. This parameter can be a value of @ref ETH_Rx_Mode */ ...} ETH_InitTypeDef;in stm32f2xx_hal_eth.cstatic void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err){ ... /* Initialize MAC address in ethernet MAC */ ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr); ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS1, heth->Init.MACFilter);}static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr){ ... /* Load the selected MAC address high register */ // BIG BAD HACK TO ENABLE MAC FILTERS (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_HBASE + MacAddr))) = tmpreg1 | 0x80000000; // enable MAC as Filter, for MAC0 this bit is always 1 anyway ...}I will probably not take the time to properly build it into the driver.
But maybe above code is helpful for somebody.
Too bad STM did not implement it properly.
Best regards,
Sebastian
2018-04-25 08:13 AM
Hi,
I have the same issue, with an STM32F207, the latest version of lwip (2.0.3) and ST driver (1.7).
Would be great to get some feedback from ST team.
In the driver hack, how is the MACFilter set?
Best regards,
2018-05-22 05:53 AM
Hello,
I'm also stuck in the same problem and I tried to implement the solution provided by Thomas (enabling the Promiscuous Mode) but it didn't work as well and I need your help to tell me what did I do wrong please.I only added the suggested piece of code in the low_level_init function (modification in Bold:(static void low_level_init(struct netif *netif)
{ uint32_t regvalue = 0; HAL_StatusTypeDef hal_eth_init_status; /* Init ETH */uint8_t MACAddr[6] ;
heth.Instance = ETH; heth.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE; heth.Init.PhyAddress = LAN8742A_PHY_ADDRESS; MACAddr[0] = 0xDE; MACAddr[1] = 0xBE; MACAddr[2] = 0xAD; MACAddr[3] = 0xFC; MACAddr[4] = 0x34; MACAddr[5] = 0x12; heth.Init.MACAddr = &MACAddr[0]; heth.Init.RxMode = ETH_RXINTERRUPT_MODE; heth.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE; heth.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;hal_eth_init_status = HAL_ETH_Init(&heth);
if (hal_eth_init_status == HAL_OK)
{ ETH_MACInitTypeDef conf = {0}; conf.PromiscuousMode = ETH_PROMISCUOUS_MODE_ENABLE; HAL_ETH_ConfigMAC(&heth, &conf); /* Set netif link flag */ netif->flags |= NETIF_FLAG_LINK_UP; } /* Initialize Tx Descriptors list: Chain Mode */ HAL_ETH_DMATxDescListInit(&heth, DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB); /* Initialize Rx Descriptors list: Chain Mode */ HAL_ETH_DMARxDescListInit(&heth, DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB); ♯ if LWIP_ARP || LWIP_ETHERNET/* set MAC hardware address length */
netif->hwaddr_len = ETH_HWADDR_LEN; /* set MAC hardware address */ netif->hwaddr[0] = heth.Init.MACAddr[0]; netif->hwaddr[1] = heth.Init.MACAddr[1]; netif->hwaddr[2] = heth.Init.MACAddr[2]; netif->hwaddr[3] = heth.Init.MACAddr[3]; netif->hwaddr[4] = heth.Init.MACAddr[4]; netif->hwaddr[5] = heth.Init.MACAddr[5]; /* maximum transfer unit */ netif->mtu = 1500; /* Accept broadcast address and ARP traffic */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ ♯ if LWIP_ARP netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; ♯ else netif->flags |= NETIF_FLAG_BROADCAST; ♯ endif /* LWIP_ARP */ netif->flags |= NETIF_FLAG_IGMP; //ETH->MACFFR |= ETH_MACFFR_PAM;/* create a binary semaphore used for informing ethernetif of frame reception */
osSemaphoreDef(SEM); s_xSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1 );/* create the task that handles the ETH_MAC */
osThreadDef(EthIf, ethernetif_input, osPriorityRealtime, 0, INTERFACE_THREAD_STACK_SIZE); osThreadCreate (osThread(EthIf), netif); /* Enable MAC and DMA transmission and reception */ HAL_ETH_Start(&heth);/* Read Register Configuration */
HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR, ®value); regvalue |= (PHY_ISFR_INT4);/* Enable Interrupt on change of link status */
HAL_ETH_WritePHYRegister(&heth, PHY_ISFR , regvalue ); /* Read Register Configuration */ HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR , ®value);♯ endif /* LWIP_ARP || LWIP_ETHERNET */
}Multi-cast transmission is okay but the reception is still not working ... any advice would be appreciated since I'm new to this field and totally lost with this problem...
Thanks.2018-05-22 06:30 AM
Hi,
For me I changed the following in stm32f2xx_hal_eth.c
in function ETH_MACDMAConfig
// macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_NONE;I believe there should be a better way to set the filter based on the multicast address but this worked for me.
2018-05-22 06:52 AM
2018-08-14 11:51 PM
Hi,
I have similar problem of able to transmit but not receiving anything. I tried the various suggestions listed in this thread but all failed.
Kamil, do you have any luck in your development that can share?
Thanks.
Ang