This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

merge cdc-acm support and BLE service

I has successfully built the following demos and run them on a nrf52840 dongle (board: nrf52840dongle_nrf52840) :

  • cdc-acm-console demo            from Samples and Demos » Various Subsystems Samples » USB device support samples
  • bluetooth-st_ble_sensor demo from Samples and Demos » Bluetooth Samples

Based on these demos I am trying to introduce cdc-acm-console support to the bluetooth-st_ble_sensor demo.

Could you please help me to produce the right project configuration (and eventual overlay) to merge both functions (cdc-acm-console and ble GATT services) on a single demo ?

thanks in advance

Parents Reply
  • Thanks, that's what I did :I added the contains of USB console’s prj.conf in the bluetooth sample’s prj.conf.

    and I assume that the overlay is properly taken into account, as I see :

    Building st_ble_sensor

    west build --build-dir c:\ Perso\Nordic\st_ble_sensor\build c:\Perso\Nordic\st_ble_sensor --pristine --board nrf52840dongle_nrf52840 -- -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DBOARD_ROOT:STRING="c:/Perso/Nordic/peripheral_lbs1" -DCONF_FILE:STRING="c: /Perso/Nordic/st_ble_sensor/prj.conf" -DDTC_OVERLAY_FILE:STRING="c:/ Perso/Nordic/st_ble_sensor/app.overlay"

     

    Then, in the main.c I instantiate the console :

    BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),  "Console device is not ACM CDC UART device");

     

    but the build stops at this point :

    c:\Perso\Nordic\st_ble_sensor\src\main.c:30:1: error: static assertion failed: "Console device is not ACM CDC UART device"
    30 | BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
    | ^~~~~~~~~~~

    hence the console is not properly set-up

Children
  • Hi,

    I tried reproducing this, but I did not get this build assert.

    What version of nRF Connect SDK(NCS) are you using ?

    If you are using an older version, app.overlay might need to look like this

    /*
     * Copyright (c) 2021 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
     / {
    	chosen {
    		zephyr,console = &cdc_acm_uart0;
    	};
    };
    
    &usbd {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    		label = "CDC_ACM_0";
    	};
    };

    (i.e. &usbd instead of &zephyr_udc0)

  • Good for the substitution &usbd instead of &zephyr_udc
    Now the build is achieved properly.
    However, when I run the application, the usbd-console output works but I cannot see any BLE advertising.

  • Sergio Bezz said:
    Now the build is achieved properly.

    Good.

    Sergio Bezz said:
    However, when I run the application, the usbd-console output works but I cannot see any BLE advertising.

    How does your main.c file look like now?

  • I have included the following within the #includes of the main.c :


    #include <usb/usb_device.h>
    #include <drivers/uart.h>
    BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
    "Console device is not ACM CDC UART device");

    and here is the main() including calls to printk :

    void main(void)
    {
    int err, n=0;

    err = button_init(button_callback);
    if (err) {
         return;
    }

    err = led_init();
    if (err) {
         return;
    }

    // exemple console (SB)
    const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
    uint32_t dtr = 0;

    if (usb_enable(NULL)) {
         return;
    }

    /* Poll if the DTR flag was set */
    while (!dtr) {
         uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
         /* Give CPU resources to low priority threads. */
         k_sleep(K_MSEC(100));
    }

    printk("Hello World! %s\n", CONFIG_ARCH);
    // fin exemple console (SB)

    /* Initialize the Bluetooth Subsystem */
    err = bt_enable(bt_ready);
    if (err) {
    L     OG_ERR("Bluetooth init failed (err %d)", err);
    }

    /* do not exit but print forever */

    while (1) {
         printk("Hello running ! %d\n", n++);
         k_sleep(K_SECONDS(1));
    }

    }

  • Sergio Bezz said:
    but I cannot see any BLE advertising.

    I tested with nRF Connect SDK v1.8.0, and it works fine here.

    What version are you using? Can you try v1.8.0? (use &zephyr_udc if you are on v1.8.0)

Related