eclipse-zenoh / zenoh-pico

Eclipse zenoh for pico devices
Other
114 stars 72 forks source link

[Bug] Zenoh Pico 0.11.0 example crashes Zephyr with Nucleo-F767ZI #558

Closed ypearson-bdai closed 2 months ago

ypearson-bdai commented 2 months ago

BUG, mode1 (Client Mode)

Firmware crashes a few seconds after rebooting if z_sub or zenohd is running on the host PC that is on the same network as the Nucleo-F767ZI

//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zenoh-pico.h>

#define CLIENT_OR_PEER 0  // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT ""  // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif

#define KEYEXPR "demo/example/zenoh-pico-pub"
#define VALUE "[STSTM32]{nucleo-F767ZI} Pub from Zenoh-Pico!"

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
    sleep(5);

    // Initialize Zenoh Session and other parameters
    z_owned_config_t config = z_config_default();
    zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE));
    if (strcmp(CONNECT, "") != 0) {
        zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(CONNECT));
    }

    // Open Zenoh session
    printf("Opening Zenoh Session...");
    z_owned_session_t s = z_open(z_move(config));
    if (!z_check(s)) {
        printf("Unable to open session!\n");
        exit(-1);
    }
    printf("OK\n");

    // Start the receive and the session lease loop for zenoh-pico
    zp_start_read_task(z_loan(s), NULL);
    zp_start_lease_task(z_loan(s), NULL);

    printf("Declaring publisher for '%s'...", KEYEXPR);
    z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(KEYEXPR), NULL);
    if (!z_check(pub)) {
        printf("Unable to declare publisher for key expression!\n");
        exit(-1);
    }
    printf("OK\n");

    char buf[256];
    for (int idx = 0; 1; ++idx) {
        sleep(1);
        sprintf(buf, "[%4d] %s", idx, VALUE);
        printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf);
        z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), NULL);
    }

    printf("Closing Zenoh Session...");
    z_undeclare_publisher(z_move(pub));

    // Stop the receive and the session lease loop for zenoh-pico
    zp_stop_read_task(z_loan(s));
    zp_stop_lease_task(z_loan(s));

    z_close(z_move(s));
    printf("OK!\n");

    return 0;
}
#else
int main(void) {
    printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
    return -2;
}
#endif
*** Booting Zephyr OS build zephyr-v30600 ***
[00:00:00.011,000] <inf> net_config: Initializing network
[00:00:00.011,000] <inf> net_config: Waiting interface 1 (0x20021d7c) to be up...
[00:00:01.512,000] <inf> net_config: Interface 1 (0x20021d7c) coming up
[00:00:01.512,000] <inf> net_config: IPv4 address: 192.168.11.2
[00:00:01.612,000] <inf> net_config: IPv6 address: 2001:db8::2
[00:00:01.612,000] <inf> net_config: IPv6 address: 2001:db8::2
uart:~$ Opening Zenoh Session...Unable to open session!
[00:00:11.551,000] <err> pthread_mutex: Mutex claims to be initialized (80000000)
[00:00:11.551,000] <err> pthread_mutex: Mutex claims to be initialized (80000001)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.551,000] <err> pthread_mutex: Mutex is uninitialized (0)
[00:00:11.555,000] <err> os: ***** USAGE FAULT *****
[00:00:11.555,000] <err> os:   Illegal use of the EPSR
[00:00:11.555,000] <err> os: r0/a1:  0x00000000  r1/a2:  0x00000000  r2/a3:  0x20024894
[00:00:11.555,000] <err> os: r3/a4:  0x00000000 r12/ip:  0x00000030 r14/lr:  0x0800618d
[00:00:11.555,000] <err> os:  xpsr:  0x000f0000
[00:00:11.556,000] <err> os: Faulting instruction address (r15/pc): 0x00000000
[00:00:11.556,000] <err> os: >>> ZEPHYR FATAL ERROR 35: Unknown error on CPU 0
[00:00:11.556,000] <err> os: Current thread: 0x20023210 (main)
[00:00:11.583,000] <err> os: Halting system

BUG, mode2 (Client Mode)

If z_sub or zenohd is not running on the network, firmware doesn't crash but nothing is published, z_scout doesn't find any zenoh processes

Also there is no print that shows opening Zenoh session

*** Booting Zephyr OS build zephyr-v30600 ***
[00:00:00.011,000] <inf> net_config: Initializing network
[00:00:00.011,000] <inf> net_config: Waiting interface 1 (0x20021d7c) to be up...
[00:00:02.012,000] <inf> net_config: Interface 1 (0x20021d7c) coming up
[00:00:02.012,000] <inf> net_config: IPv4 address: 192.168.11.2
[00:00:02.113,000] <inf> net_config: IPv6 address: 2001:db8::2

To reproduce

$HOME/.platformio/penv/bin/platformio init -b nucleo_f767zi --project-option framework=zephyr
$HOME/.platformio/penv/bin/platformio run
cp zenoh-pico-0.11.0/docs/zephyr/nucleo_f767zi/prj.conf zephyr/
cp zenoh-pico-0.11.0/examples/zephyr/z_pub.c src/
rm src/main.c # remove generated main.c

Add lib_deps = https://github.com/eclipse-zenoh/zenoh-pico#0.11.0 to platformio.ini

$HOME/.platformio/penv/bin/platformio run --target clean && $HOME/.platformio/penv/bin/platformio run --target upload
picocom -b 115200 /dev/ttyACM0

Tried this patch but same result: int8_t z_mutex_free(z_mutex_t *m) { if(!m || !*m) return 0; return pthread_mutex_destroy(m); }

System info

ypearson-bdai commented 2 months ago

Should be fixed by 1.0.0.6