Zephyr K_FIFO-Error

Hi

I have a strange error in the k_fifo-useage:

Basis is the project peripheral uart

I want to answer on specific commands send via bluetooth

static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
              uint16_t len)
{
    int err;
    char addr[BT_ADDR_LE_STR_LEN] = {0};
    struct answer_buffer_t *buf;
        uint8_t answer[UART_BUF_SIZE];
    bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

    LOG_INF("Received %i data %s from: %s", len, data, log_strdup(addr));
                               

        if (strncmp(data, "&I", 2) == 0 )
        {
        uint8_t stringbuffer[100];
          buf = k_malloc(sizeof(*buf));
          iCounter++;
          LOG_INF("&I %i", iCounter);
          buf->len = sprintf(stringbuffer, "&I %i\n", iCounter);
          memcpy(stringbuffer, &buf, buf->len);

          k_fifo_put(&answer_buffer, buf);
        }
       
}

But when I send "&I" zephyr crashes:

[00:00:34.164,001] [0m<inf> peripheral_uart: &I 1[0m
[00:00:35.179,046] [1;31m<err> os: r0/a1:  0x00000004  r1/a2:  0x000000d1  r2/a3:  0x00000001[0m
[00:00:35.179,046] [1;31m<err> os: r3/a4:  0x0001dbbd r12/ip:  0x00000000 r14/lr:  0x00011d2b[0m
[00:00:35.179,046] [1;31m<err> os:  xpsr:  0x41000000[0m
[00:00:35.179,046] [1;31m<err> os: Faulting instruction address (r15/pc): 0x00028d2c[0m
[00:00:35.179,077] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0[0m
[00:00:35.179,077] [1;31m<err> os: Current thread: 0x200017c8 (unknown)[0m
[00:00:35.376,464] [1;31m<err> fatal_error: Resetting system[0m

What do I do wrong?

Parents
  • I found out this line:

    LOG_INF("Received %i data %s from: %s", len, data, log_strdup(addr));
    

    Without this its working but i had another error here (caused by my try and arror):

    This is the right code:

        if (strncmp(data, "&I", 2) == 0 )
        {
          buf = k_malloc(sizeof(*buf));
          iCounter++;
          LOG_INF("&I %i", iCounter);
          buf->len = sprintf(buf->data, "&I %i\n", iCounter);
          k_fifo_put(&answer_buffer, buf);
        }
    
Reply
  • I found out this line:

    LOG_INF("Received %i data %s from: %s", len, data, log_strdup(addr));
    

    Without this its working but i had another error here (caused by my try and arror):

    This is the right code:

        if (strncmp(data, "&I", 2) == 0 )
        {
          buf = k_malloc(sizeof(*buf));
          iCounter++;
          LOG_INF("&I %i", iCounter);
          buf->len = sprintf(buf->data, "&I %i\n", iCounter);
          k_fifo_put(&answer_buffer, buf);
        }
    
Children
Related