This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8c8ae92530713bca49526fa6fab519d9fce9a55f
Author: jsanchez-2g <[email protected]>
AuthorDate: Tue Aug 18 16:14:46 2026 -0500

    boards/nucleo-f072rb: Add USB device support and a CDC/ACM configuration.
    
    The STM32F072RB provides a full speed USB device controller, but the
    Nucleo-F072RB board support did not enable it and no configuration
    exercised it.
    
    Add the pieces required to run USB device mode on this board:
    
    - Select HSI48 as the 48MHz source and use the USB start of frame packet
      as the CRS synchronisation event, which is the intended crystal-less
      USB configuration for this part.
    - Add the USB device pin definitions to the STM32F07x pin map.
    - Provide board level pull-up control and register the CDC/ACM class at
      boot when it is selected.
    - Add a usb-cdc-uart configuration that presents an NSH console on
      USART2 and a CDC/ACM serial device on USB.
    - Enable the USB device pins in the nsh configuration so the two
      configurations stay consistent.
    
    Assisted-by: GitHub Copilot:claude-opus-5
    Signed-off-by: jsanchez-2g <[email protected]>
---
 arch/arm/src/stm32f0/hardware/stm32f07x_pinmap.h   |  5 +++
 .../stm32f0/nucleo-f072rb/configs/nsh/defconfig    |  6 +++
 .../configs/{nsh => usb-cdc-uart}/defconfig        | 32 ++++++++++++---
 boards/arm/stm32f0/nucleo-f072rb/include/board.h   |  4 ++
 boards/arm/stm32f0/nucleo-f072rb/src/stm32_boot.c  | 45 ++++++++++++++++++++++
 .../arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c  | 13 +++++++
 6 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/stm32f0/hardware/stm32f07x_pinmap.h 
b/arch/arm/src/stm32f0/hardware/stm32f07x_pinmap.h
index 24255d24048..cb03def2028 100644
--- a/arch/arm/src/stm32f0/hardware/stm32f07x_pinmap.h
+++ b/arch/arm/src/stm32f0/hardware/stm32f07x_pinmap.h
@@ -35,6 +35,11 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* USB */
+
+#define GPIO_USB_DM                (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | 
GPIO_PIN11)
+#define GPIO_USB_DP                (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | 
GPIO_PIN12)
+
 /* Alternate Pin Functions.
  *
  * Alternative pin selections are provided with a numeric suffix like _1, _2,
diff --git a/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig 
b/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig
index 4a266b9184f..f1fd3ab108a 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig
+++ b/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig
@@ -32,6 +32,10 @@ CONFIG_ARCH_IRQBUTTONS=y
 CONFIG_ARCH_STACKDUMP=y
 CONFIG_BOARD_LOOPSPERMSEC=2796
 CONFIG_BUILTIN=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEV_CONSOLE=y
 CONFIG_DEFAULT_SMALL=y
 CONFIG_FS_PROCFS=y
 CONFIG_INIT_ENTRYPOINT="nsh_main"
@@ -53,6 +57,8 @@ CONFIG_START_MONTH=5
 CONFIG_START_YEAR=2013
 CONFIG_STM32_PWR=y
 CONFIG_STM32_USART2=y
+CONFIG_SYSLOG_CHAR=y
+CONFIG_SYSLOG_DEVPATH="/dev/ttyS0"
 CONFIG_SYSTEM_NSH=y
 CONFIG_TASK_NAME_SIZE=0
 CONFIG_USART2_RXBUFSIZE=32
diff --git a/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig 
b/boards/arm/stm32f0/nucleo-f072rb/configs/usb-cdc-uart/defconfig
similarity index 67%
copy from boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig
copy to boards/arm/stm32f0/nucleo-f072rb/configs/usb-cdc-uart/defconfig
index 4a266b9184f..7e5d3b70c24 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/configs/nsh/defconfig
+++ b/boards/arm/stm32f0/nucleo-f072rb/configs/usb-cdc-uart/defconfig
@@ -1,9 +1,6 @@
 #
-# This file is autogenerated: PLEASE DO NOT EDIT IT.
-#
-# You can use "make menuconfig" to make any modifications to the installed 
.config file.
-# You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
-# modifications.
+# USB CDC ACM device with NSH and syslog retained on USART2/ST-Link VCP.
+# CDCACM_CONSOLE and NSH_USBCONSOLE are intentionally disabled.
 #
 # CONFIG_FS_PROCFS_EXCLUDE_BLOCKS is not set
 # CONFIG_FS_PROCFS_EXCLUDE_ENVIRON is not set
@@ -30,8 +27,20 @@ CONFIG_ARCH_CHIP_STM32F072RB=y
 CONFIG_ARCH_CHIP_STM32F0=y
 CONFIG_ARCH_IRQBUTTONS=y
 CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARDCTL=y
+CONFIG_BOARDCTL_USBDEVCTRL=y
+CONFIG_BOARD_LATE_INITIALIZE=y
 CONFIG_BOARD_LOOPSPERMSEC=2796
 CONFIG_BUILTIN=y
+CONFIG_CDCACM=y
+CONFIG_CDCACM_RXBUFSIZE=256
+CONFIG_CDCACM_TXBUFSIZE=256
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEBUG_USB=y
+# CONFIG_DEBUG_USB_INFO is not set
+CONFIG_DEV_CONSOLE=y
 CONFIG_DEFAULT_SMALL=y
 CONFIG_FS_PROCFS=y
 CONFIG_INIT_ENTRYPOINT="nsh_main"
@@ -41,6 +50,7 @@ CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
 CONFIG_NSH_BUILTIN_APPS=y
 CONFIG_NSH_FILEIOSIZE=64
 CONFIG_NUNGET_CHARS=0
+# CONFIG_NSH_USBDEV_TRACE is not set
 CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536
 CONFIG_PTHREAD_STACK_DEFAULT=1536
 CONFIG_RAM_SIZE=16384
@@ -51,10 +61,20 @@ CONFIG_SCHED_WAITPID=y
 CONFIG_START_DAY=19
 CONFIG_START_MONTH=5
 CONFIG_START_YEAR=2013
+CONFIG_STM32_HSI48=y
 CONFIG_STM32_PWR=y
 CONFIG_STM32_USART2=y
+CONFIG_STM32_USB=y
+CONFIG_SYSLOG_CHAR=y
+CONFIG_SYSLOG_DEVPATH="/dev/ttyS0"
 CONFIG_SYSTEM_NSH=y
 CONFIG_TASK_NAME_SIZE=0
+CONFIG_TWO_G_USB_DIAGNOSTICS=y
+CONFIG_USBDEV_TRACE=y
+CONFIG_USBDEV_TRACE_INITIALIDSET=0
+CONFIG_USBDEV_TRACE_NRECORDS=128
+CONFIG_USBDEV_TRACE_STRINGS=y
+# CONFIG_USBMONITOR is not set
 CONFIG_USART2_RXBUFSIZE=32
 CONFIG_USART2_SERIAL_CONSOLE=y
-CONFIG_USART2_TXBUFSIZE=32
+CONFIG_USART2_TXBUFSIZE=32
\ No newline at end of file
diff --git a/boards/arm/stm32f0/nucleo-f072rb/include/board.h 
b/boards/arm/stm32f0/nucleo-f072rb/include/board.h
index 2a028f5bf93..b8d602b96ec 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/include/board.h
+++ b/boards/arm/stm32f0/nucleo-f072rb/include/board.h
@@ -30,6 +30,7 @@
 #include <nuttx/config.h>
 
 #ifndef __ASSEMBLY__
+#  include <stdbool.h>
 #  include <stdint.h>
 #endif
 
@@ -102,6 +103,9 @@
 #define STM32_CFGR_PLLSRC        RCC_CFGR_PLLSRC_HSId2       /* Source is 
HSI/2 */
 #define STM32_PLLSRC_FREQUENCY   (STM32_HSI_FREQUENCY/2)     /* 8MHz / 2 = 
4MHz */
 #ifdef CONFIG_STM32_USB
+#  define STM32_USE_CLK48
+#  define STM32_CLK48_SEL         RCC_CFGR3_CLK48_HSI48
+#  define STM32_HSI48_SYNCSRC     SYNCSRC_USB
 #  undef  STM32_CFGR2_PREDIV                                 /* Not used with 
source HSI/2 */
 #  define STM32_CFGR_PLLMUL      RCC_CFGR_PLLMUL_CLKx12      /* PLLMUL = 12 */
 #  define STM32_PLL_FREQUENCY    (12*STM32_PLLSRC_FREQUENCY) /* PLL VCO 
Frequency is 48MHz */
diff --git a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_boot.c 
b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_boot.c
index e1c37566fda..52a32152ce7 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_boot.c
+++ b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_boot.c
@@ -26,12 +26,18 @@
 
 #include <nuttx/config.h>
 
+#include <stdbool.h>
+
 #include <nuttx/debug.h>
 
 #include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/usb/usbdev.h>
 #include <arch/board/board.h>
 
 #include "arm_internal.h"
+#include "hardware/stm32_usbdev.h"
+#include "stm32_usbdev.h"
 #include "nucleo-f072rb.h"
 
 /****************************************************************************
@@ -58,6 +64,45 @@ void stm32_boardinitialize(void)
 #endif
 }
 
+#if defined(CONFIG_STM32_USB) && defined(CONFIG_USBDEV)
+int stm32_usb_setpullup(bool enable)
+{
+  irqstate_t flags;
+  uint16_t regval;
+
+  flags = enter_critical_section();
+  regval = getreg16(STM32_USB_BCDR);
+
+  if (enable)
+    {
+      regval |= USB_BCDR_DPPU;
+    }
+  else
+    {
+      regval &= ~USB_BCDR_DPPU;
+    }
+
+  putreg16(regval, STM32_USB_BCDR);
+  leave_critical_section(flags);
+
+  return OK;
+}
+
+bool stm32_usb_pullup_enabled(void)
+{
+  return (getreg16(STM32_USB_BCDR) & USB_BCDR_DPPU) != 0;
+}
+
+int stm32_usbpullup(FAR struct usbdev_s *dev, bool enable)
+{
+  return stm32_usb_setpullup(enable);
+}
+
+void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
+{
+}
+#endif
+
 /****************************************************************************
  * Name: board_late_initialize
  *
diff --git a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c 
b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
index ccf38aeb624..43149b3c8bf 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
+++ b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
@@ -31,6 +31,7 @@
 
 #include <nuttx/fs/fs.h>
 #include <nuttx/i2c/i2c_master.h>
+#include <nuttx/usb/cdcacm.h>
 
 #include "stm32_i2c.h"
 #include "nucleo-f072rb.h"
@@ -44,6 +45,10 @@
 #  define HAVE_I2C_DRIVER 1
 #endif
 
+#if defined(CONFIG_CDCACM) && !defined(CONFIG_CDCACM_COMPOSITE)
+#  define HAVE_CDCACM 1
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -96,6 +101,14 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef HAVE_CDCACM
+  ret = cdcacm_initialize(0, NULL);
+  if (ret < 0)
+    {
+      ferr("ERROR: Failed to register CDC ACM: %d\n", ret);
+    }
+#endif
+
   UNUSED(ret);
   return OK;
 }

Reply via email to