u-blox / ubxlib

Portable C libraries which provide APIs to build applications with u-blox products and services. Delivered as add-on to existing microcontroller and RTOS SDKs.
Apache License 2.0
301 stars 89 forks source link

Zephyr Nordic NRF52832 device opened with error -256 #273

Closed andagent closed 2 weeks ago

andagent commented 2 weeks ago

Hi everyone!

I am having some issue with my ubxlib setup. When trying to open LEXI-R10 device I am getting error -256. Could anyone help me please?

I am getting this U_PORT_BOARD_CFG: using CELLULAR device "cfg-device-cellular" from the device tree, module-type 10 on UART 0, uart-baud-rate 115200 with pin-enable-power -1 (0xffffffff), pin-pwr-on -1 (0xffffffff), pin-vint -1 (0xffffffff), pin-dtr-power-saving -1 (0xffffffff).

[00:00:02.008,239] modem_service: modem_init: Opened device with return code -256.

My dts looks like:

/ {
    model = "ugo-v1";
    compatible = "fb-innovation-srls,ugo-v1";

    cfg-device-cellular {
        status = "okay";
        compatible = "u-blox,ubxlib-device-cellular";
        transport-type = "uart0";
        module-type = "U_CELL_MODULE_TYPE_LEXI_R10";
        uart-baud-rate = <115200>;
    };
};

&gpio0 {
    status = "okay";
};

&gpiote {
    status = "okay";
};

&uart0 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    hw-flow-control;
    pinctrl-0 = <&uart0_default>;
    pinctrl-names = "default";
    current-speed = <115200>;
};

&pinctrl {
    uart0_default: uart0_default {
        group1 {
            psels = <NRF_PSEL(UART_TX, 0, 5)>,
                    <NRF_PSEL(UART_RX, 0, 4)>,
                    <NRF_PSEL(UART_RTS, 0, 6)>,
                    <NRF_PSEL(UART_CTS, 0, 7)>;
        };
    };
};

my init code like:

uDeviceHandle_t modem_init() {
    static const uDeviceCfg_t gDeviceCfg = {
        .version = 0,
        .deviceType = U_DEVICE_TYPE_CELL,
        .transportType = U_DEVICE_TRANSPORT_TYPE_UART,
        .transportCfg = {
            .cfgUart = {
                .uart = 0,
            },
        },
    };
    // NETWORK configuration for cellular
    static const uNetworkCfgCell_t gNetworkCfg = {
        .version = 0,
        .type = U_NETWORK_TYPE_CELL,
        .pApn = "em",
        .timeoutSeconds = 2400,
        .pKeepGoingCallback = 0,
        .pUsername = NULL,
        .pPassword = NULL,
        .authenticationMode = 1,
        .pMccMnc = 0
    };
    static const uNetworkType_t gNetType = U_NETWORK_TYPE_CELL;

    // Init the variables
    uDeviceHandle_t device = NULL;
    int32_t returnCode;

    // Initialization code here
    uPortInit();
    uDeviceInit();

    // Open the device
    returnCode = uDeviceOpen(NULL, &device);
    LOG_INF("Opened device with return code %ld.", returnCode);

    if (returnCode == 0) {
        LOG_INF("Bringing up the network..");

        // Bring up the network
        if (uNetworkInterfaceUp(device, gNetType, &gNetworkCfg) != 0) {
            LOG_ERR("Unable to bring up the device!\n");
        }

        // Read current RAT
        // *currentRat = uCellNetGetActiveRat(device);
        // uCellNetGetOperatorStr(device, apn_string, U_CELL_NET_MAX_OPERATOR_LENGTH_BYTES);
        LOG_INF("Cellular is up!");

        return device;
    } else return NULL;
}
andagent commented 2 weeks ago

Important to mention, when I connected a UART adapter to the modem and tried operating it from there, it works. It responds OK to my AT photo_2024-08-25 19 54 09

andagent commented 2 weeks ago

After some digging, I see that the issue is in malloc.

Screenshot 2024-08-26 at 11 46 19

I am getting this:

No receive buffer provided, allocating memory Entering pUPortMalloc with sizeBytes: 2084 Memory allocation failed Exiting pUPortMalloc

However, in my prj.conf I have it set this way: CONFIG_HEAP_MEM_POOL_SIZE=10240 CONFIG_MAIN_STACK_SIZE=8192

andagent commented 2 weeks ago

After even more digging I found out that the heap memory was lacking, so I incresed it to 16384