From 21975231e267309b57d0d7706c667728ec008922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Wed, 14 Dec 2022 07:46:28 +0100 Subject: [PATCH] usb: device: cdc_acm: Prevent recursive logging loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow enabling CDC ACM logging only if CDC ACM is not used as logging backend. This prevents endless recursive logging loop, especially visible when minimal footprint logging is enabled. Fixes: #52981 Signed-off-by: Tomasz Moń --- boards/arm/adafruit_itsybitsy_nrf52840/Kconfig.defconfig | 5 +++-- boards/arm/xiao_ble/xiao_ble_defconfig | 3 +++ samples/boards/sensortile_box/prj.conf | 1 + subsys/usb/device/class/cdc_acm.c | 8 ++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/boards/arm/adafruit_itsybitsy_nrf52840/Kconfig.defconfig b/boards/arm/adafruit_itsybitsy_nrf52840/Kconfig.defconfig index 964bd85868e..dd0d8f9aa17 100644 --- a/boards/arm/adafruit_itsybitsy_nrf52840/Kconfig.defconfig +++ b/boards/arm/adafruit_itsybitsy_nrf52840/Kconfig.defconfig @@ -33,10 +33,11 @@ config USB_DEVICE_REMOTE_WAKEUP if LOG -# Set USB and CDC log level to error only +# Logger cannot use itself to log config USB_CDC_ACM_LOG_LEVEL - default 1 + default 0 +# Set USB log level to error only config USB_DEVICE_LOG_LEVEL default 1 diff --git a/boards/arm/xiao_ble/xiao_ble_defconfig b/boards/arm/xiao_ble/xiao_ble_defconfig index ac0a5b9bb22..faef5befa1f 100644 --- a/boards/arm/xiao_ble/xiao_ble_defconfig +++ b/boards/arm/xiao_ble/xiao_ble_defconfig @@ -19,6 +19,9 @@ CONFIG_SERIAL=y # enable console CONFIG_CONSOLE=y +# Logger cannot use itself to log +CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y + # enable USB CONFIG_USB_DEVICE_STACK=y diff --git a/samples/boards/sensortile_box/prj.conf b/samples/boards/sensortile_box/prj.conf index 71d385731fb..5fd052d1ecf 100644 --- a/samples/boards/sensortile_box/prj.conf +++ b/samples/boards/sensortile_box/prj.conf @@ -21,6 +21,7 @@ CONFIG_USB_DEVICE_VID=0x0483 CONFIG_USB_DEVICE_PID=0x1234 CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC SensorTile.box" +CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_LINE_CTRL=y diff --git a/subsys/usb/device/class/cdc_acm.c b/subsys/usb/device/class/cdc_acm.c index 0c269bd4b2c..5c51c967fe6 100644 --- a/subsys/usb/device/class/cdc_acm.c +++ b/subsys/usb/device/class/cdc_acm.c @@ -56,6 +56,14 @@ /* definitions */ #include +#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart) \ + && defined(CONFIG_USB_CDC_ACM_LOG_LEVEL) \ + && CONFIG_USB_CDC_ACM_LOG_LEVEL != LOG_LEVEL_NONE +/* Prevent endless recursive logging loop and warn user about it */ +#warning "USB_CDC_ACM_LOG_LEVEL forced to LOG_LEVEL_NONE" +#undef CONFIG_USB_CDC_ACM_LOG_LEVEL +#define CONFIG_USB_CDC_ACM_LOG_LEVEL LOG_LEVEL_NONE +#endif LOG_MODULE_REGISTER(usb_cdc_acm, CONFIG_USB_CDC_ACM_LOG_LEVEL); /* 115200bps, no parity, 1 stop bit, 8bit char */