2026-02-19 6:33 AM
Not sure that I have the latest version of the HAL but I used two ip address for the ETH MAC and tried to enable both in the L3 filter.
But I could not get any data to the second interface. with the filter turned on-
Looking more closely on the HAL_ETHEx_SetL3FilterConfig I found what can only be a copy paste mistake.
Writing the destination address for IPv4 was mede to the MACL3A0R1R register instead of the expected: MACL3A1R1R
Might be fixed in newer version but using two IP-address perhaps is a bit unusual.
Solved! Go to Solution.
2026-02-19 7:54 AM
Original code:
HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
const ETH_L3FilterConfigTypeDef *pL3FilterConfig)
{
if (pL3FilterConfig == NULL)
{
return HAL_ERROR;
}
if (Filter == ETH_L3_FILTER_0)
{
/* Write configuration to MACL3L4C0R register */
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Write configuration to MACL3L4C1R register */
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
if (Filter == ETH_L3_FILTER_0)
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A2R0R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A3R0R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip4DestAddr);
}
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4DestAddr);
}
}
/* Enable L3 filter */
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
return HAL_OK;
}
Updated:
HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
const ETH_L3FilterConfigTypeDef *pL3FilterConfig)
{
if (pL3FilterConfig == NULL)
{
return HAL_ERROR;
}
if (Filter == ETH_L3_FILTER_0)
{
/* Write configuration to MACL3L4C0R register */
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Write configuration to MACL3L4C1R register */
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
if (Filter == ETH_L3_FILTER_0)
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A2R0R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A3R0R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip4DestAddr);
}
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip4DestAddr);
}
}
/* Enable L3 filter */
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
return HAL_OK;
}So almost the same and the code works when using filter 0 or source mode.
Only difference is the last write of the IPv4 destination address that needed an update.
2026-02-19 7:35 AM
Did you had a look at errata of your device ?
2026-02-19 7:43 AM
I did now.
Correcting the HAL to write the destination to the correct register fixed the problem.
So the system is working now that I have fixed the HAL code.
2026-02-19 7:46 AM
It would be helpful to show the changes that you made to the HAL code.
If your issue is now resolved, please mark the solution on the post which provided the answer - not this one!
2026-02-19 7:54 AM
Original code:
HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
const ETH_L3FilterConfigTypeDef *pL3FilterConfig)
{
if (pL3FilterConfig == NULL)
{
return HAL_ERROR;
}
if (Filter == ETH_L3_FILTER_0)
{
/* Write configuration to MACL3L4C0R register */
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Write configuration to MACL3L4C1R register */
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
if (Filter == ETH_L3_FILTER_0)
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A2R0R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A3R0R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip4DestAddr);
}
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4DestAddr);
}
}
/* Enable L3 filter */
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
return HAL_OK;
}
Updated:
HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
const ETH_L3FilterConfigTypeDef *pL3FilterConfig)
{
if (pL3FilterConfig == NULL)
{
return HAL_ERROR;
}
if (Filter == ETH_L3_FILTER_0)
{
/* Write configuration to MACL3L4C0R register */
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Write configuration to MACL3L4C1R register */
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
pL3FilterConfig->SrcAddrFilterMatch |
pL3FilterConfig->DestAddrFilterMatch |
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
}
if (Filter == ETH_L3_FILTER_0)
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A2R0R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A3R0R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip4DestAddr);
}
}
else /* Filter == ETH_L3_FILTER_1 */
{
/* Check if IPv6 protocol is selected */
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
{
/* Set the IPv6 address match */
/* Set Bits[31:0] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip6Addr[0]);
/* Set Bits[63:32] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[1]);
/* update Bits[95:64] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
}
else /* IPv4 protocol is selected */
{
/* Set the IPv4 source address match */
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4SrcAddr);
/* Set the IPv4 destination address match */
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip4DestAddr);
}
}
/* Enable L3 filter */
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
return HAL_OK;
}So almost the same and the code works when using filter 0 or source mode.
Only difference is the last write of the IPv4 destination address that needed an update.