I have working zigbee switch example for nrf52840 dongle and I want to add print. Am I using correct code changes? please suggest, Thank you.
printk is not giving any printouts. I can see the "Zephyr USB Console Sample" in available ports in windows.
I took reference from the zephyr/samples/subsys/usb/console example.
nrf52840dongle_nrf52840.overlay
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
/ {
chosen {
zephyr,entropy = &rng;
zephyr,console = &cdc_acm_uart0;
};
pwmleds {
pwm_led3: pwm_led_3 {
pwms = <&pwm0 12>;
};
};
buttons {
compatible = "gpio-keys";
rst_button0: rst_button_0 {
gpios = <&gpio0 19 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Reset button";
};
};
aliases {
rst0 = &rst_button0;
};
};
&zephyr_udc0 {
compatible = "nordic,nrf-usbd";
status = "okay";
label = "USBD";
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
label = "CDC_ACM_0";
};
};
prj.conf
# # Copyright (c) 2020 Nordic Semiconductor ASA # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # #CONFIG_NCS_SAMPLES_DEFAULTS=y CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console" #CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_SERIAL=y CONFIG_GPIO=y # Make sure printk is not printing to the UART console CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y #CONFIG_UART_LINE_CTRL=y CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_ZIGBEE=y CONFIG_ZIGBEE_APP_UTILS=y CONFIG_ZIGBEE_ROLE_END_DEVICE=y # Enable DK LED and Buttons library CONFIG_DK_LIBRARY=y # This example requires more workqueue stack CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 # Enable nRF ECB driver CONFIG_CRYPTO=y CONFIG_CRYPTO_NRF_ECB=y CONFIG_CRYPTO_INIT_PRIORITY=80 # Cryptocell is not supported through CSPRNG driver API: NCSDK-4813 CONFIG_ENTROPY_CC3XX=n # Enable API for powering down unused RAM parts CONFIG_RAM_POWER_DOWN_LIBRARY=y #Networking CONFIG_NET_IPV6_MLD=n CONFIG_NET_IPV6_NBR_CACHE=n CONFIG_NET_IPV6_RA_RDNSS=n CONFIG_NET_IP_ADDR_CHECK=n CONFIG_NET_UDP=n
kconfig
config USB_DEVICE_PID default USB_PID_CONSOLE_SAMPLE source "Kconfig.zephyr"
& addition in main.c
BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
"Console device is not ACM CDC UART device");
// In main
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");