nrf_wifi fails : memory allocation failure at boot and crash at config

Using an nrf5340 with nrf7002 wifi, connected via SPI4. Using a shared (chip) antenna, and the COEX signals (pretty much exactly as per the dev board schema).

DTS snippets:

    // Wifi nrf7002 : SPI4 using SCK P0.08, MOSI P0.09, MISO P0.10, CS P0.11
    // BUCKEN P0.12, IRQ P0.23, COEX_GRANT P0.24, COEX_REQ P0.28, STATUS0 P0.30, STATUS1 P0.29, NRF7002_IOVDD_EN ioexp0/GPB0
    nrf_radio_coex: nrf7001-coex {
        status = "okay";
        compatible = "nordic,nrf700x-coex";
        req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>;
        status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
        grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>;
        swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>;
        // btrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; No, controlled by nrf7002 directly???
    };

    nordic_wlan0: nordic_wlan0 {
        compatible = "nordic,wlan0";
        status = "okay";
    };
&spi4 {                     // Wifi nrf7002
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi4_default>;
    pinctrl-1 = <&spi4_sleep>;
    cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; /* P0.11 */
    pinctrl-names = "default", "sleep";
    nrf700x: nrf7002@0 {
        status = "okay";
        compatible = "nordic,nrf700x-spi";
        reg = <0>;
        spi-max-frequency = <33000000>;
//      sck-frequency = <24000000>;
        /* Wi-Fi Pins used */
        iovdd-ctrl-gpios = <&ioexp0 8 GPIO_ACTIVE_HIGH>;            // GPB00
        bucken-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
        host-irq-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>;
    };
};

I have configured prj.conf to have the wifi STA 'iot' operation, as per the docs:

# WIFI config
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y

# WPA supplicant
CONFIG_WPA_SUPP=y
CONFIG_NRF700X_AP_MODE=n
CONFIG_NRF700X_P2P_MODE=n

# Networking layers
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_LOG=y
CONFIG_NET_IPV4=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_DHCPV4=y

CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=2
CONFIG_NET_MAX_CONTEXTS=1
CONFIG_NET_CONTEXT_SYNC_RECV=y

CONFIG_NET_L2_ETHERNET=y

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_INIT_TIMEOUT=0

CONFIG_NET_SOCKETS_POLL_MAX=1

# Memory usage
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096

# Optimized networking settings for memory usage (STA MODE IOT DEVICES profile)
# https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/protocols/wifi/stack_configuration.html
CONFIG_NRF700X_MAX_TX_TOKENS=5
CONFIG_NRF700X_MAX_TX_AGGREGATION=1
CONFIG_NRF700X_RX_NUM_BUFS=6

CONFIG_NET_TC_TX_COUNT=1
CONFIG_NET_PKT_RX_COUNT=6
CONFIG_NET_PKT_TX_COUNT=6

CONFIG_NET_BUF_RX_COUNT=6
CONFIG_NET_BUF_TX_COUNT=12
# can take BUF_DATAT_SIZE down to 500
CONFIG_NET_BUF_DATA_SIZE=800

However, at boot time I see these logs:

[00:00:00.015,686] <inf> wifi_nrf_bus: SPIM spi@a000: freq = 33 MHz
[00:00:00.022,369] <inf> wifi_nrf_bus: SPIM spi@a000: latency = 1
[00:00:01.074,981] <err> wifi_nrf: hal_fw_patch_load: Failed to allocate memory for patch UMAC-bin: chunk 1/6, size: 8192
[00:00:01.086,639] <err> wifi_nrf: nrf_wifi_fmac_fw_load: UMAC patch load failed

[00:00:01.094,818] <err> wifi_nrf: nrf_wifi_fw_load: nrf_wifi_fmac_fw_load failed
[00:00:01.103,027] <err> wifi_nrf: nrf_wifi_fmac_dev_add_zep: nrf_wifi_fw_load failed
[00:00:01.113,891] <err> wifi_nrf: nrf_wifi_if_start_zep: nrf_wifi_fmac_dev_add_zep failed

Note I also have configured malloc to use the system heap, and for it to occupy all remaining RAM:

CONFIG_COMMON_LIBC_MALLOC=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=-1
The heap size at boot time is 233576 bytes so no reason for a malloc to fail?

Then when I attempt to initialise the wifi I get this crash

[00:00:13.322,784] <err> os: ***** USAGE FAULT *****
[00:00:13.328,399] <err> os: Unaligned memory access
[00:00:13.334,197] <err> os: r0/a1: 0xa07eeaff r1/a2: 0x00000068 r2/a3: 0x0000005c
[00:00:13.342,834] <err> os: r3/a4: 0x20047130 r12/ip: 0x00000000 r14/lr: 0x00063dc9
[00:00:13.351,440] <err> os: xpsr: 0x61000000
[00:00:13.356,628] <err> os: Faulting instruction address (r15/pc): 0x0009bafe
[00:00:13.364,501] <err> os: >>> ZEPHYR FATAL ERROR 31: Unknown error on CPU 0
[00:00:13.372,375] <err> os: Current thread: 0x20007340 (sysworkq)
[00:00:13.379,180] <err> os: Halting system

in  nrf_wifi_osal_mem_zalloc() according to zephyr.map.

This is called somewherr from nrf_wifi_coex_config_non_pta():

    /* Configure Coexistence Hardware */
    log_info("netwifi: Configuring non-PTA registers. seperate antennas:%s  is_sr_protocol_ble: %s",separate_antennas?"YES":"NO", is_sr_protocol_ble?"YES":"NO");
    ret = nrf_wifi_coex_config_non_pta(separate_antennas, is_sr_protocol_ble);
    if (ret != 0) {
        log_warn("netwifi: Configuring non-PTA registers of CoexHardware FAIL");
        return false;
    }
Note the wifi sample projects (wifi_radio_test, wifi_shell)all run just FINE (with no error logs at boot) so the hardware is apparently good, but I haven't managed to get from them to my full app without this problem occuring...
Any ideas?
  • HI Charlie,

    After much pain over the holiday period, I have managed to get my application back compiling and working on NCS 2.8 (but using --nosys-build as that was just too much to deal with right now).

    Wifi seems to be more stable, but I haven't yet tried anything too hard (like making the AP appear and disappear when the device moves about..)

    I have still not managed to get https to work, due to certificate loading issues : I have posted where I have got to (essentially a config issue due to the nrf setup?) here:

    devzone.nordicsemi.com/.../nrf5340-ncs-2-8-cannot-get-tls-socket-to-load-ca-certif-due-to-net_sock_tls-mbedtls-error--0x262e

    If you have any insights on how to setup the mbedtls / nrf-security in NCS 2.8 to get it to include RSA then that would be great...

  • Hi Brian,

    Thank you for updating me on your current status.

    Your new request is now being handled by my colleague. However, due to the backlog we are addressing after the vacation, it might take some time to process your new ticket.

    We appreciate your patience and assure you that we are doing our best to resolve this issue promptly.

    Best regards,

    Charlie

  • Hi,

    I am struggling with a similar problem related to DT_HAS_NORDIC_NRF7002_SPI_ENABLED being unsatisfied despite attempting to set up my .overlay file to match the working nRF7002 samples.

    Could you share what you did to be able to get CONFIG_WIFI_NRF70 to propagate to "y" when built? My project builds, but that flag seems to get ignored (due to the unsatisfied dependency) and the driver is never enabled.

    Greatly appreciate any help, thank you!

  • My prj.conf has:

    # WIFI
    CONFIG_WIFI=y
    CONFIG_WIFI_NRF70=y
    # the fact its a 7002 and on SPI should come from DTS config
    For the DTS I have extracted the wifi bits below:
    /{
    ...
      chosen {
        ...
            zephyr,wifi = &wlan0;
      };
      nrf_radio_coex: coex {
            compatible = "nordic,nrf7002-coex";
    //  nrf_radio_coex: nrf7001-coex {
    //  compatible = "nordic,nrf700x-coex";
            status = "okay";
            req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>;
            status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
            grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>;
            swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>;
            // controlled by nrf7002??? btrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; this is epd sck gpio
      };

      &spi4 {                     // Wifi nrf7002
        status = "okay";
        compatible = "nordic,nrf-spim";
        pinctrl-0 = <&spi4_default>;
        pinctrl-1 = <&spi4_sleep>;
        cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; /* P0.11 */
        pinctrl-names = "default", "sleep";
        nrf70: nrf7002@0 {
            status = "okay";
            compatible = "nordic,nrf7002-spi";
            reg = <0>;
    //      spi-max-frequency = <33000000>;
            spi-max-frequency = <24000000>;
    //      sck-frequency = <24000000>;
            /* Wi-Fi Pins used */
            iovdd-ctrl-gpios = <&ioexp0 8 GPIO_ACTIVE_HIGH>;            // GPB00
            bucken-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
            host-irq-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>;
            wifi-max-tx-pwr-2g-dsss = <21>;
            wifi-max-tx-pwr-2g-mcs0 = <16>;
            wifi-max-tx-pwr-2g-mcs7 = <16>;
            wifi-max-tx-pwr-5g-low-mcs0 = <9>;
            wifi-max-tx-pwr-5g-low-mcs7 = <9>;
            wifi-max-tx-pwr-5g-mid-mcs0 = <11>;
            wifi-max-tx-pwr-5g-mid-mcs7 = <11>;
            wifi-max-tx-pwr-5g-high-mcs0 = <13>;
            wifi-max-tx-pwr-5g-high-mcs7 = <13>;
            wlan0: nordic_wlan {
                compatible = "nordic,wlan";
                status = "okay";
         };
      };
    ...
    };
     
    &pinctrl {
       ...
        spi4_default: spi4_default {                    // nRF7002 Wifi SPI
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,    // P0.08
                <NRF_PSEL(SPIM_MISO, 0, 10)>,       // P0.10
                <NRF_PSEL(SPIM_MOSI, 0, 9)>;       // P0.09
            };
        };

        spi4_sleep: spi4_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
                    <NRF_PSEL(SPIM_MISO, 0, 10)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 9)>;
                low-power-enable;
            };
        };
    ...
    };
    I believe it was having the "compatible" attributes that fixed the DT_HAS_XXX dependancies.
  • Thank you, my SPI traffic looks normal now. Cheers!

Related