cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ETHEx_SetL3FilterConfig Copy paste error.

Bebbelin
Associate II

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

4 REPLIES 4
mbarg.1
Lead

Did you had a look at errata of your device ?

Bebbelin
Associate II

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.

 

It would be helpful to show the changes that you made to the HAL code.

How to insert source code

 

If your issue is now resolved, please mark the solution on the post which provided the answer - not this one!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

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.