Skip to content

Conversation

multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Oct 10, 2025

Summary of changes

This MR turned into a bit of a bigger project then I originally intended, but... I have noticed for a while that devices with Cypress WHD wi-fi modules hard fault when running the nanostack and EMAC tests. Recently I investigated why, and it turns out that the memory manager code for the wi-fi driver is hardcoded to use LwIP, so it will segfault if used before LwIP has been initialized. This is not the way! Network drivers should use the memory manager interface so that they are agnostic of the network stack in use and so that they can be run with the emac tests.

This MR rewrites the WHD driver's memory manager interface code to talk to a NetStackMemoryManager instance. It also adds new code to the net stack memory manager to provide an equivalent of pbuf_header(), which is a required interface for the network driver.

I also ran into a failure in the TLS tests caused by the RTC not initializing properly to a representable time. I fixed this and added a new test to check for it (though the test only actually catches the issue if it's the first RTC-related test run after a power cycle, sadly).

Impact of changes

  • WHD driver can now be used with Nanostack and the EMAC tests (though nanostack doesn't seem to be fully working yet...)
  • PSoC RTC driver now returns a representable time immediately after being initialized. This means you don't need to manually set the RTC time in order to avoid an assert failure.

Migration actions required

Documentation

None (this is more focused on making something behave in the way it's supposed to according to the docs...)


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR
  • All netsocket lwip tests pass
  • netsocket wifi test passes
  • netsocket emac test passes except for the no-memory test case (WHD driver doesn't handle running out of memory well, for now) and the multicast test case (no support for passing all multicast packets :((( )
  • netsocket nanostack tests still fail (something is going wrong with DNS, and I wasn't able to find any obvious reason why, so saving that for another day...)

* Current number of header bytes that have been removed (skipped) from the start of the buffer.
* Added by Mbed to implement memory manager functionality.
*/
u16_t header_bytes_removed;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also had to patch LwIP to track the current amount of header bytes added/removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO can we remove this and just do math based on the pointer?

hostname = user_network_interface->get_hostname();
if (hostname) {
netif_set_hostname(&interface->netif, hostname);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found a bug in this change that was submitted a while back. If the user network interface is null (and it can be), you get a hard fault.

* @param to_buf Memory buffer chain to copy to
* @param from_buf Memory buffer chain to copy from
*/
virtual void copy(net_stack_mem_buf_t *to_buf, const net_stack_mem_buf_t *from_buf) = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am removing this function as it's complex to implement, is not really properly specified in terms of how it works, and is (wait for it!) totally unused in the entire Mbed codebase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update: Turns out it is used in some target-specific EMAC code, BUT every usage I have found so far can be more ergonomically replaced by the realloc_heap() function.

}
time_t seconds;
if (!_rtc_maketime(&rtc_time, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT)) {
if (!_rtc_maketime(&rtc_time, &seconds, RTC_4_YEAR_LEAP_YEAR_SUPPORT)) {
Copy link
Collaborator Author

@multiplemonomials multiplemonomials Oct 10, 2025

Choose a reason for hiding this comment

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

Looking at the datasheet, it is quite clear that PSoC 62 only has 4 year leap year support, not full leap year support. Rather surprised there's no test that will detect if this is set incorrectly...

image

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.

1 participant