Skip to content
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

w5500: mac: poll VERSIONR to ensure the chip is initialised (IDFGH-10061) #11337

Closed
wants to merge 3 commits into from
Closed

Conversation

huming2207
Copy link
Contributor

See discussion: #11331 and #10554 (comment)

This addresses the fix for the version check. Based on our experiments, we have to wait for at least 10ms (one FreeRTOS tick) to let the W5500 fully come up and talks to the host ESP32. We've also implemented a poll to retry 20 times just in case a simple wait doesn't work in some cases.

@CLAassistant
Copy link

CLAassistant commented May 5, 2023

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label May 5, 2023
@github-actions github-actions bot changed the title w5500: mac: poll VERSIONR to ensure the chip is initialised w5500: mac: poll VERSIONR to ensure the chip is initialised (IDFGH-10061) May 5, 2023
@suda-morris
Copy link
Collaborator

because the w5500_verify_id is called directly after the w5500_reset, maybe what we need is a better exit path for the w5500_reset function? cc @kostaond

@suda-morris suda-morris requested a review from kostaond May 5, 2023 02:19
@huming2207
Copy link
Contributor Author

because the w5500_verify_id is called directly after the w5500_reset, maybe what we need is a better exit path for the w5500_reset function? cc @kostaond

Thanks for your reply @suda-morris

I've read the code again and I wonder if we should enforce a delay before the MR mode register read instead?

@huming2207
Copy link
Contributor Author

@suda-morris @kostaond Done, I've 1. removed the excessive retry count macro and used the reset timeout value instead, and 2. enforce at least a 10ms wait to poll the RST in the mode register just in case that poll read causes any undefined behavior.

@kostaond
Copy link
Collaborator

kostaond commented May 5, 2023

because the w5500_verify_id is called directly after the w5500_reset, maybe what we need is a better exit path for the w5500_reset function? cc @kostaond

Good point, however I am afraid there is no better condition to exit the reset function... Checking the state of autoclear reset bit is kind of standard way. The only thing which crossed my mind was to check the reset bit and the Version ID in the same condition. On the other hand, I don't see much value added in such approach and having it spitted into two calls seems good enough to me.

I've read the code again and I wonder if we should enforce a delay before the MR mode register read instead?

I would keep it as it was since reading immediately seems to work for majority of chips and it ensures the faster startup for this majority. Polling the Version ID will capture the corner cases when the fastest path does not work.

@huming2207
Copy link
Contributor Author

I would keep it as it was since reading immediately seems to work for majority of chips and it ensures the faster startup for this majority. Polling the Version ID will capture the corner cases when the fastest path does not work.

Sure, I will revert this change ASAP. Is there anything else I can do for this PR?

@huming2207
Copy link
Contributor Author

@kostaond Done, ready for review. I've also squashed the commits into one to make the commit message cleaner.

@huming2207
Copy link
Contributor Author

Any updates on this? @kostaond @suda-morris

@huming2207
Copy link
Contributor Author

Any further updates? @kostaond

Copy link
Collaborator

@kostaond kostaond left a comment

Choose a reason for hiding this comment

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

I left two final comments. @suda-morris could you please also have a look?

ESP_LOGI(TAG, "Waiting W5500 to start & verify version...");
uint32_t to = 0;
for (to = 0; to < emac->sw_reset_timeout_ms / 10; to++) {
vTaskDelay(pdMS_TO_TICKS(10));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed this one previously because I though we already discussed it. However, please place the delay at the end of the loop. We should try the fastest way at first.


err:
return ret;
ESP_LOGI(TAG, "Waiting W5500 to start & verify version...");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove or make it debug level.

@huming2207
Copy link
Contributor Author

@kostaond @suda-morris Done, waiting for review

@KaeLL
Copy link
Contributor

KaeLL commented May 11, 2023

Assuming you're not using a counterfeit chip, you should file an issue on Wiznet forums, since this is something worthy of an update of the datasheet at least.

@huming2207
Copy link
Contributor Author

Assuming you're not using a counterfeit chip, you should file an issue on Wiznet forums, since this is something worthy of an update of the datasheet at least.

I think this is necessary but a bit off-topic. We wish we have time to confirm with Wiznet but we've already bought a handful of these W5500 modules and chips. We are also experiencing a short deadline, but we also want to help anyone with the same issue as ours, so we push this fix to the mainline ESP-IDF. As long as this fix works for us (and anyone else, hopefully), it's acceptable anyway.

@kostaond kostaond requested a review from suda-morris May 16, 2023 07:24
@kostaond
Copy link
Collaborator

kostaond commented May 17, 2023

sha=506b372d28bea8899c7958e5095fc21487ce4aed

@kostaond kostaond added PR-Sync-Merge Pull request sync as merge commit and removed PR-Sync-Merge Pull request sync as merge commit labels May 17, 2023
@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels May 19, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: In Progress Work is in progress labels May 23, 2023
@kostaond kostaond closed this May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Sync-Merge Pull request sync as merge commit Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants