Could not allocate rx buffer error with Ethernet samples using ENC424J600 with nRF52840

Hi,

I've got a custom board with an ENC424J600 connected to an nRF52840. I started with nRF Connect v2.0.0 but I've since upgraded to the latest (v2.3.0-rc1) to see if it fixed my problem - which it didn't.

I made a custom zephyr "board" based on the nRF52840 devkit files and modified it as needed to add a the enc424j600 to SPI0. I got the http_client demo to connect to a simple unsecure server running on my PC (the TCPIP_Demo.jar app from Microchip) - so the hardware and the basics of adding the mac/phy to my project seems to be good.

My next step is to get it working with something out in the real world - like doing an http get from google or bouncing something off the tcpbin.com echo server. The problem is that when I try to do a DNS lookup with getaddrinfo() I get a "Could not allocate rx buffer" error. I've tried the http_get and the http_client examples with the same result. Fulll RTT output below:

00> [00:00:00.314,422] <inf> ethdrv: Link down
00> [00:00:00.314,483] <inf> ethdrv: ENC424J600 Initialized
00> [00:00:00.314,758] <inf> ethdrv: Not suspended
00> *** Booting Zephyr OS build v3.2.99-ncs2-rc1 ***
00> [00:00:00.315,032] <inf> net_config: Initializing network
00> [00:00:00.315,063] <inf> net_config: Waiting interface 1 (0x20001338) to be up...
00> [00:00:01.838,989] <inf> ethdrv: Link up
00> [00:00:01.839,233] <inf> ethdrv: 100Mbps
00> [00:00:01.839,233] <inf> ethdrv: full duplex
00> [00:00:01.840,179] <inf> net_config: Interface 1 (0x20001338) coming up
00> [00:00:01.846,527] <inf> net_config: IPv4 address: 192.168.137.2
00> [00:00:07.770,538] <err> ethdrv: Could not allocate rx buffer

It seems like the error is coming from a memory allocation attempt in mem_slab.c.

I've been trying to increase all of the memory sizes I can but either I haven't found the right one to increase, or maybe I'm just not setting them high enough. Here's what I've added so far - with no change in results:

CONFIG_ETH_ENC424J600_RX_THREAD_STACK_SIZE=1536
CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION=y
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_MAIN_STACK_SIZE=1536
Please help! This is quite urgent as we need to determine if this hardware solution is solid before we fully commit to this path for manufacturing.
Thanks,
Glen
  • I think adding CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE might have fixed that memory allocation issue - but I am still having failures with getaddrinfo (returning error code -2), so I decided to try the dns_resolve sample project. This one makes it look like it's sending out a request, but then it always comes back as canceled. See log below.

    Could this be a hardware issue? Any ideas why my dns request is being canceled?

    00> [00:00:00.315,856] <inf> ethdrv: Link down
    00> [00:00:00.315,887] <inf> ethdrv: ENC424J600 Initialized
    00> [00:00:00.316,436] <inf> ethdrv: Not suspended
    00> *** Booting Zephyr OS build v3.2.99-ncs2-rc1 ***
    00> [00:00:00.317,169] <inf> net_config: Initializing network
    00> [00:00:00.317,169] <inf> net_config: Waiting interface 1 (0x20001114) to be up...
    00> [00:00:08.753,601] <inf> ethdrv: Link up
    00> [00:00:08.753,814] <inf> ethdrv: 100Mbps
    00> [00:00:08.753,845] <inf> ethdrv: full duplex
    00> [00:00:08.754,760] <inf> net_config: Interface 1 (0x20001114) coming up
    00> [00:00:08.761,077] <inf> net_config: IPv4 address: 192.0.2.1
    00> [00:00:08.864,624] <inf> net_config: IPv6 address: 2001:db8::1
    00> [00:00:08.864,685] <inf> net_dns_resolve_client_sample: Starting DNS resolve sample
    00> [00:00:08.865,142] <err> net_arp: Gateway not set for iface 0x20001114
    00> [00:00:08.865,173] <dbg> net_dns_resolve_client_sample: do_ipv4_lookup: DNS id 24221
    00> [00:00:08.865,203] <dbg> net_dns_resolve_client_sample: do_mdns_ipv4_lookup: Doing mDNS IPv4 query
    00> [00:00:08.867,156] <dbg> net_dns_resolve_client_sample: do_mdns_ipv4_lookup: mDNS v4 query sent
    00> [00:00:10.865,020] <inf> net_dns_resolve_client_sample: DNS query was canceled
    00> [00:00:10.865,509] <inf> net_dns_resolve_client_sample: mDNS query was canceled

    Thanks,

    Glen

  • Hi,

    I am afraid we don't have much experience with the ENC424J600 device. I suggest you ask in the the Zephyr community on Discord.

  • Has anyone successfully used the Zephyr networking sample projects with a Nordic part? 

    I'm still stuck where the http_client demo will work, but none of the other Ethernet-type samples do (I've tried dns_resolve, http_get, sntp_client, dhvpv4_client). On a lot of them I may just have the server and other CONFIG stuff wrong - but there's very little configuration to the dhcp client one. That seems like it ought to just work.

    I asked a question on the discord - hopefully someone will help

  • A bit more info here. Once I got the configuration right, I was able to get the dns_resolve sample to work, but still none of the others. I found that dns_resolve uses dns_get_addr_info() to look up an IP address, while the rest of the Zephyr socket samples use getaddrinfo(), which doesn't seem to work.

    So at the moment I'm trying to put the rest of the socket code (connect, send etc) from the http_get sample into my working dns_resolve to confirm that I can read http data from the internet. I'm also using the https_client sample for the nrf9160 for reference since that's something with a Nordic processor that's using the socket code.

    Then once that works I'll work on getting TLS going.

    It would still be really helpful to know if anyone has successfully used any of these socket sample programs with any Nordic processors, and if possible to see the code. It's disappointing that once I got my devicetree stuff sorted out to hook up the device that all of this stuff didn't just work - and the only advice I've gotten so far is to check a 3rd party site where I found no help.

  • I've managed to get this working. Here's what I learned in case someone else is trying to get the Zephyr Ethernet  socket samples (specifically http_get) working.

    1) I've been using my Segger J-Link+ with RTT viewer 7.66a to see the debug output, and I found that it stops printing data well before the program was dying.

    I bought a cheap tp-link managed switch with port mirroring so that I can direct all of the traffic to-from my test board to my work computer and I can see all of the packets with Wireshark. That immediately showed me that I was getting farther in the sample code than I thought I was based on the RTT output.

    I also changed the code which calls getaddrinfo to look up the IP address to call it in a loop until it's successful rather than bailing out and stopping the sample program at the first failure.

    I added the following lines to my prj.conf to get the debug info to come out of my debug UART instead:

    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_UART=y
    2) The http_get sample to Google by default, but Google no longer supports insecure connections so it fails. So turning TLS on by putting the stuff from overlay-tls.conf into my main prj.conf file got me to the point where I got a response from google. Also, the sample goes to "google.com" which gets you a "permanently moved" response - changing it to "www.google.com" got me a real HTTP GET of the page.
Related