Problems with LWIP port in ksdk v2.2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with LWIP port in ksdk v2.2

2,077 Views
andrewparlane2
Contributor III

I've had to make some changes to get LWIP building in my project. I think these issues are in LWIP port and not on my end.

  1. My project is C++ whereas LWIP and the port are C. ethernetif.h is missing the extern "C" wrapper. Meaning netif_add(..., ethernetif_init, ...); fails as it can't find the symbol ethernetif_init.
  2. lwipopts.h is in the port folder. This should be a project specific file and not included in the port. I could set up the include directory lists to make sure it includes the custom file first if it exists, but that kind of seems nasty and prone to weird bugs. If you want to add an example file, it should be lwipopts.h.example or something, so it doesn't get  used by default.
  3. There's a compile issue with both port/cc.h and src/include/lwip/arch.h defining basic types like u8_t. You can fix this by defining LWIP_NO_STDINT_H as per the comment in arch.h.

/** Define this to 1 in arch/cc.h of your port if your compiler does not provide
* the stdint.h header. This cannot be \#defined in lwipopts.h since
* this is not an option of lwIP itself, but an option of the lwIP port
* to your system.
* Additionally, this header is meant to be \#included in lwipopts.h
* (you may need to declare function prototypes in there).
*/

This specifically states that it should be defined in cc.h and not in lwipopts.h Yet it is defined in your default lwipopts.h and not in cc.h. Also it's designed for if there isn't a stdint.h which there is by default.

I'm not sure how to fix this one. The easy but maybe not entirely correct version is to define LWIP_NO_STDINT_H in cc.h. It would be better if we could not define the basic types in cc.h and just use the arch.h version, but this messes up the u32_t lwip_rand(void) signiture in sys_arch.h and I'm not all too sure how to fix that.

 

If these issues could be patched in the next KSDK version, that'd be great.

Thanks,

Andrew Parlane

Tags (2)
0 Kudos
6 Replies

1,504 Views
andrewparlane2
Contributor III

Found some more issues.

4. ethernetif.c enet_init() blocks until a link comes up or it times out (default 0xFFF). That takes quite a while, and seems silly, being that you can boot a board without a cable plugged in. Sure I can override the timeout, but I'm not sure this is sensible for default behaviour.

5. ethernetif.c enet_init() calls ENET_Init() (that seems slightly confusing in itself) with the default enet_config_t (except for linux speed and duplex, if there's a link). So on my custom board I'm using MII mode. There is no way to set MII mode rather than RMII mode. I'll patch ethernetif.c and .h to base this off a define. I may have to do this for some other of the enet_config_t members too.

6. The mac address gets set by a series of defines. I can override this defines. However in general you don't want to use a hardcoded MAC in your source files, since it'd be the same for every board you use. I feel instead a function should be called to get the mac, the user then has to provide this function. Sure I can do this with some defines in lwipopts.h to call functions / read it from an array, but replacing the code in low_level_init() from:

/* set MAC hardware address */
netif->hwaddr[0] = configMAC_ADDR0;
netif->hwaddr[1] = configMAC_ADDR1;
netif->hwaddr[2] = configMAC_ADDR2;
netif->hwaddr[3] = configMAC_ADDR3;
netif->hwaddr[4] = configMAC_ADDR4;
netif->hwaddr[5] = configMAC_ADDR5;

to:

get_mac_addr(netif, netif->hwaddr);

The user can then provide get_mac_addr and look at netif->num or netif->name or netif->state or whatever to work out which interface it is (if there's more than one).

You could also add a "weak" implementation of this function in ethernetif.c that uses the static defines, so that it compiles easier, however I think it's much more obvious to the user that they can set the MAC address and how, when they get a link error for missing symbol get_mac_addr().

Andy

0 Kudos

1,504 Views
andrewparlane2
Contributor III

Anybody from NXP seen this?

I posted it two weeks ago.

0 Kudos

1,504 Views
danielchen
NXP TechSupport
NXP TechSupport

HI Andrew:

Have you tried the new version? I downloaded the ksdk_v2.2 for TWR-K65, the lwip version is 2.0.0.  I can find the external "C"  in ethernetif.h. I think maybe your issue is fixed in this version.

Regards

Daniel

0 Kudos

1,504 Views
andrewparlane2
Contributor III

Hi,

Sorry for taking forever to reply, my e-mail notifications don't seem to be working.

I have the following SDK SDK_2.2_MK66FN2M0xxx18, In the middleware directory is lwip_2.0.0, ethernetif.h definitely doesn't have extern "C"ini it.

I'm working on re-creating my config and downloading the SDK again to check.

0 Kudos

1,504 Views
andrewparlane2
Contributor III

OK, created a new config for the MK66FN2M0xxx18, built and downloaded the SDK,

It does not have this change in ethernetif.h.

Thanks,
Andrew

0 Kudos

1,504 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Andrew:

Thank you for your sincere feedback, let me check these issues first and I will report it to the lwip team

Regards

Daniel

0 Kudos