Skip to content

Feature emac lpc546xx #6810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mmahadevan108
Copy link
Contributor

ENET support for LPC546XX boards

[ ] Fix
[X] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

@mmahadevan108
Copy link
Contributor Author

cc @maclobdell @0xc0170 @kjbracey-arm

@TuomoHautamaki
Copy link

Hi @mmahadevan108 , great to see this PR coming. Did you run netsocket and emac greentea tests already?

Regards,
Tuomo

@mmahadevan108 mmahadevan108 force-pushed the feature-emac-lpc546xx branch from 7821aaa to 86d4f33 Compare May 7, 2018 20:09
@mmahadevan108
Copy link
Contributor Author

I have rebased this PR. Yes, I ran the netsocket and network-emac tests.

@cmonr
Copy link
Contributor

cmonr commented May 7, 2018

@mmahadevan108 Would you mind posting those logs?

/morph build

@mbed-ci
Copy link

mbed-ci commented May 8, 2018

Build : SUCCESS

Build number : 1939
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6810/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented May 8, 2018

@mbed-ci
Copy link

mbed-ci commented May 8, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented May 8, 2018

@mmahadevan108 Please review the failures, related to the changes

@mmahadevan108
Copy link
Contributor Author

I am unclear why the failures are seen. All tests pass with ARM tool chain. One test failure seen with GCC_ARM and more with IAR.

Is there a toolchain specific configuration I need to pay attention to in the new ENET frameowork?

@mmahadevan108
Copy link
Contributor Author

I was debugging the failure with IAR and see the it is failing to get the below semaphore during bringup
https://github.com/ARMmbed/mbed-os/blob/feature-emac/features/FEATURE_LWIP/lwip-interface/LWIPInterface.cpp#L522

Any idea why?

@maclobdell
Copy link
Contributor

@mmahadevan108 did you run the tests with an echo server on the network? I just noticed that the tests might pass if an echo server is not running, but will fail otherwise.

@mmahadevan108
Copy link
Contributor Author

I was debugging the gethostbyname test under netsocket. This is failing in the mbed-ci for IAR and GCC_ARM but passes for ARM. All tests pass in mbed-ci for the ARM toolchain.

@maclobdell
Copy link
Contributor

@mmahadevan108

I rebased your LPC546XX commits on top of Mika’s branch referenced in #6851. I had to add an additional commit to add “EMAC” and “ETHERNET” to the device_has list in targets.json.

I ran the tests and the broadcast test is failing.

At your earliest convenience, please test it out.

If you have any questions or comments please contact me.

Initial results:

+------------------+---------------+--------------------+-----------------+--------+--------+--------+--------------------+
| target           | platform_name | test suite         | test case       | passed | failed | result | elapsed_time (sec) |
+------------------+---------------+--------------------+-----------------+--------+--------+--------+--------------------+
| LPC546XX-GCC_ARM | LPC546XX      | tests-network-emac | EMAC broadcast  | 0      | 1      | FAIL   | 10.37              |
| LPC546XX-GCC_ARM | LPC546XX      | tests-network-emac | EMAC initialize | 1      | 0      | OK     | 1.88               |
+------------------+---------------+--------------------+-----------------+--------+--------+--------+--------------------+

@mmahadevan108
Copy link
Contributor Author

@maclobdell I am seeing issues acquiring a semaphore. I am not clear if I am missing something in my code. I have highlighted this above, any suggestions.

@maclobdell
Copy link
Contributor

@mikaleppanen Please see issue acquiring semaphore that Mahesh highlighted. Let us know if you have any suggestions.

@mikaleppanen
Copy link

The semaphore here:

https://github.com/ARMmbed/mbed-os/blob/feature-emac/features/FEATURE_LWIP/lwip-interface/LWIPInterface.cpp#L522

waits for the LWIP stack DHCP negotiation to complete, so failing to acquire the semaphore indicates that there could be any problem in IP message transfer. Can you acquire logs from wire to see in what phase the negotiation fails.

Copy link

@mikaleppanen mikaleppanen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two comments based on greentea testing.

ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT),
};

ENET_Init(ENET, &config, hwaddr, refClock);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the new emac interface power_up() mac address is not yet set at this point so it contains null string. At old lwip driver interface it was valid already at this point. On new emac, mac is written by network stack to emac after the power_up() with void set_hwaddr() call.

We are having test case failures (at least with IAR) where the device does not receive messages sent to its mac address.

Could you check that mac address configuration works as expected. Just was testing purposes, we changed code so that mac is valid already here and the driver worked. But that cannot be a solution in new emac since mac written later using the set_hwaddr().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems like you should be passing NULL here rather than hwaddr, so ENET_Init doesn't try programming the MAC address yet.

Not sure what the other test failures were.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option is to use the mbed_mac_address() call to set the address to hwaddr before the ENET_Init call.

update_read_buffer(bdPtr, NULL);
} else {
if (bdPtr->control & ENET_RXDESCRIP_WR_LD_MASK) {
length = (bdPtr->control & ENET_RXDESCRIP_WR_PACKETLEN_MASK);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing, we are seeing here that the length here is 4 bytes more than expected. Also with incoming message with 1500 bytes long payload there is a buffer tail overwrite of the received emac_mem_buf_t. Could you check the length handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see an issue with this code. I need to debug more why this is happening.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The datasheet says that the packet written to the buffer includes the CRC, and the length in this descriptor reflects that.

You just need to subtract 4, as far as I can see, as we want the packet length including MAC header, but excluding CRC. (You or the hardware are assumed to have checked and stripped the CRC - the hardware here has checked it but not stripped it.)


void LPC546XX_EMAC::add_multicast_group(const uint8_t *addr)
{
/* No-op at this stage */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing with greentea, driver did not pass multicast packets to network stack. You should add set_all_multicast(true) call here, so in case network stack configures multicast (i.e. is ipv6 capable) multicast filtering is disabled.

@kjbracey
Copy link
Contributor

Any progress here?

@maclobdell
Copy link
Contributor

@mmahadevan108 - please let us know if these suggested updates work for you.

Signed-off-by: Mahesh Mahadevan <[email protected]>
@cmonr
Copy link
Contributor

cmonr commented May 17, 2018

@mmahadevan108 ^^^

@mmahadevan108 mmahadevan108 force-pushed the feature-emac-lpc546xx branch from 9660393 to fa72cde Compare May 17, 2018 16:15
@mmahadevan108
Copy link
Contributor Author

I have updated the PR to include the call for set_all_multicast(true); inside add_multicast_group() function. I am not clear why we are seeing the length issue.

@kjbracey
Copy link
Contributor

On the MAC address, the problem is due to an error in the driver code for ENET_SetMacAddr.

base->MAC_ADDR_LOW = ((uint32_t)macAddr[3] << 24) | ((uint32_t)macAddr[2] << 16) | ((uint32_t)macAddr[1] << 8) |

The MAC_ADDR_LOW register must be written last. The user manual says:

If the MAC address registers are configured to be double-synchronized to the MII clock
domains, then the synchronization is triggered only when bits 31:24 (in little-endian mode)
or bits 7:0 (in Big-Endian mode) of the MAC address low register are written to.

Swapping the order has made it work here.

@kjbracey
Copy link
Contributor

The remaining issue is the memory buffer tail overwrite. We've not run the tests yet, but I believe the issue is that you are configuring the hardware buffer size to ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT) - this is 4-byte aligned, as the hardware requires (1520)

But you're only actually allocating ENET_ETH_MAX_FLEN (1518) from the memory pool, so the hardware is overwriting by 2 bytes. Increase the pool allocation request to the aligned number.

@kjbracey
Copy link
Contributor

I've applied the 3 fixes I describe to the combined PR here #6936

Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, with the 3 changes I've applied on the combined test PR. Passing tests here.

@kjbracey
Copy link
Contributor

Merged via #6936

@kjbracey kjbracey closed this May 21, 2018
@mmahadevan108 mmahadevan108 deleted the feature-emac-lpc546xx branch July 4, 2018 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants