You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/28 05:36:40 UTC
(nuttx) branch master updated: weact stm32h743vit6 usbconsole fix
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b5382234cc weact stm32h743vit6 usbconsole fix
b5382234cc is described below
commit b5382234cc15ae7a632290a149765f452f98faed
Author: Tomashevskiy <iv...@gmail.com>
AuthorDate: Wed Sep 25 22:55:01 2024 +0300
weact stm32h743vit6 usbconsole fix
fix previous problemc
added defconfig for weact-stm32h743:nshusb
board.h
Wrong column position or missing blank line before comment: FIX
hopefully last commit
---
.../weact-stm32h743/configs/nshusb/defconfig | 56 ++++
boards/arm/stm32h7/weact-stm32h743/include/board.h | 6 +
boards/arm/stm32h7/weact-stm32h743/src/Makefile | 2 +-
.../src/{weact-stm32h743.h => stm32_ioctl.c} | 76 +++---
boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c | 294 +++++++++++++++++++++
.../stm32h7/weact-stm32h743/src/weact-stm32h743.h | 51 ++++
6 files changed, 440 insertions(+), 45 deletions(-)
diff --git a/boards/arm/stm32h7/weact-stm32h743/configs/nshusb/defconfig b/boards/arm/stm32h7/weact-stm32h743/configs/nshusb/defconfig
new file mode 100644
index 0000000000..1647157f21
--- /dev/null
+++ b/boards/arm/stm32h7/weact-stm32h743/configs/nshusb/defconfig
@@ -0,0 +1,56 @@
+#
+# 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.
+#
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_PS is not set
+# CONFIG_STANDARD_SERIAL is not set
+# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="weact-stm32h743"
+CONFIG_ARCH_BOARD_WEACT_STM32H743=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743VI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_BOARDCTL_IOCTL=y
+CONFIG_BOARDCTL_USBDEVCTRL=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BUILTIN=y
+CONFIG_CDCACM=y
+CONFIG_CDCACM_CONSOLE=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_MM_REGIONS=4
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=245760
+CONFIG_RAM_START=0x20010000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SPI=y
+CONFIG_START_DAY=11
+CONFIG_START_MONTH=5
+CONFIG_START_YEAR=2024
+CONFIG_STM32H7_HSI48=y
+CONFIG_STM32H7_OTGFS=y
+CONFIG_STM32H7_USART1=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USBDEV=y
diff --git a/boards/arm/stm32h7/weact-stm32h743/include/board.h b/boards/arm/stm32h7/weact-stm32h743/include/board.h
index c8a4e35099..cb6d20eee4 100644
--- a/boards/arm/stm32h7/weact-stm32h743/include/board.h
+++ b/boards/arm/stm32h7/weact-stm32h743/include/board.h
@@ -338,6 +338,12 @@
#define GPIO_USART1_RX (GPIO_USART1_RX_1 | GPIO_SPEED_100MHz) /* PB15 */
#define GPIO_USART1_TX (GPIO_USART1_TX_1 | GPIO_SPEED_100MHz) /* PB14 */
+/* OTGFS */
+
+#define GPIO_OTGFS_DM (GPIO_OTGFS_DM_0|GPIO_SPEED_100MHz) /* PA11 */
+#define GPIO_OTGFS_DP (GPIO_OTGFS_DP_0|GPIO_SPEED_100MHz) /* PA12 */
+#define GPIO_OTGFS_ID (GPIO_OTGFS_ID_0|GPIO_SPEED_100MHz) /* PA10 */
+
/****************************************************************************
* Public Data
****************************************************************************/
diff --git a/boards/arm/stm32h7/weact-stm32h743/src/Makefile b/boards/arm/stm32h7/weact-stm32h743/src/Makefile
index c80e7e486f..7a7b2fcb8e 100644
--- a/boards/arm/stm32h7/weact-stm32h743/src/Makefile
+++ b/boards/arm/stm32h7/weact-stm32h743/src/Makefile
@@ -20,7 +20,7 @@
include $(TOPDIR)/Make.defs
-CSRCS = stm32_boot.c stm32_bringup.c
+CSRCS = stm32_boot.c stm32_bringup.c stm32_usb.c stm32_ioctl.c
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
diff --git a/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h b/boards/arm/stm32h7/weact-stm32h743/src/stm32_ioctl.c
similarity index 50%
copy from boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
copy to boards/arm/stm32h7/weact-stm32h743/src/stm32_ioctl.c
index be9c3fac6c..214cf84c6e 100644
--- a/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
+++ b/boards/arm/stm32h7/weact-stm32h743/src/stm32_ioctl.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
+ * boards/arm/stm32h7/weact-stm32h743/src/stm32_ioctl.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,69 +18,57 @@
*
****************************************************************************/
-#ifndef __BOARDS_ARM_STM32H7_WEACT_STM32H743_SRC_WEACT_STM32H743_H
-#define __BOARDS_ARM_STM32H7_WEACT_STM32H743_SRC_WEACT_STM32H743_H
-
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
-#include <nuttx/compiler.h>
+#include <sys/types.h>
#include <stdint.h>
+#include <errno.h>
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-/* procfs File System */
-
-#ifdef CONFIG_FS_PROCFS
-# ifdef CONFIG_NSH_PROC_MOUNTPOINT
-# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT
-# else
-# define STM32_PROCFS_MOUNTPOINT "/proc"
-# endif
-#endif
+#include <nuttx/board.h>
-/* LED
- *
- * The WeAct STM32H743 board has only one Blue LED (E3) controlled by GPIO.
- * LED E3: connected to PC3
- */
-
-#define GPIO_LD1 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
- GPIO_OUTPUT_CLEAR | GPIO_PORTE | GPIO_PIN3)
-
-/* BUTTONS
- *
- * The pushbutton K1 is connected to GPIO PC13.
- */
+#include "weact-stm32h743.h"
-#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
+#ifdef CONFIG_BOARDCTL_IOCTL
/****************************************************************************
- * Public Function Prototypes
+ * Public Functions
****************************************************************************/
/****************************************************************************
- * Name: stm32_bringup
+ * Name: board_ioctl
*
* Description:
- * Perform architecture-specific initialization
+ * The "landing site" for much of the boardctl() interface. Generic board-
+ * control functions invoked via ioctl() get routed through here.
+ *
+ * Since we don't do anything unusual at the moment, this function
+ * accomplishes nothing except avoid a missing-function linker error if
+ * CONFIG_BOARDCTL_IOCTL is selected.
*
- * CONFIG_BOARD_LATE_INITIALIZE=y :
- * Called from board_late_initialize().
+ * Input Parameters:
+ * cmd - IOCTL command being requested.
+ * arg - Arguments for the IOCTL.
*
- * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y &&
- * CONFIG_NSH_ARCHINIT:
- * Called from the NSH library
+ * Returned Value:
+ * we don't yet support any boardctl IOCTLs. This function always returns
+ * -ENOTTY which is the standard IOCTL return value when a command is not
+ * supported
*
****************************************************************************/
-int stm32_bringup(void);
+int board_ioctl(unsigned int cmd, uintptr_t arg)
+{
+ switch (cmd)
+ {
+ default:
+ return -ENOTTY;
+ }
+
+ return OK;
+}
-#endif /* __BOARDS_ARM_STM32H7_WEACT_STM32H743_SRC_WEACT_STM32H743_H */
+#endif /* CONFIG_BOARDCTL_IOCTL */
diff --git a/boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c b/boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c
new file mode 100644
index 0000000000..1510040989
--- /dev/null
+++ b/boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c
@@ -0,0 +1,294 @@
+/****************************************************************************
+ * boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <sched.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kthread.h>
+#include <nuttx/usb/usbdev.h>
+#include <nuttx/usb/usbhost.h>
+#include <nuttx/usb/usbdev_trace.h>
+
+#include "arm_internal.h"
+#include "chip.h"
+#include "stm32_gpio.h"
+#include "stm32_otg.h"
+#include "weact-stm32h743.h"
+
+#ifdef CONFIG_STM32H7_OTGFS
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST)
+# define HAVE_USB 1
+#else
+# warning "CONFIG_STM32_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST"
+# undef HAVE_USB
+#endif
+
+#ifndef CONFIG_WEACT_STM32H743_USBHOST_PRIO
+# define CONFIG_WEACT_STM32H743_USBHOST_PRIO 100
+#endif
+
+#ifndef CONFIG_WEACT_STM32H743_USBHOST_STACKSIZE
+# define CONFIG_WEACT_STM32H743_USBHOST_STACKSIZE 1024
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+static struct usbhost_connection_s *g_usbconn;
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: usbhost_waiter
+ *
+ * Description:
+ * Wait for USB devices to be connected.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+static int usbhost_waiter(int argc, char *argv[])
+{
+ struct usbhost_hubport_s *hport;
+
+ uinfo("Running\n");
+ for (; ; )
+ {
+ /* Wait for the device to change state */
+
+ DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
+ uinfo("%s\n", hport->connected ? "connected" : "disconnected");
+
+ /* Did we just become connected? */
+
+ if (hport->connected)
+ {
+ /* Yes.. enumerate the newly connected device */
+
+ CONN_ENUMERATE(g_usbconn, hport);
+ }
+ }
+
+ /* Keep the compiler from complaining */
+
+ return 0;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_usbhost_initialize
+ *
+ * Description:
+ * Called at application startup time to initialize the USB host
+ * functionality.
+ * This function will start a thread that will monitor for device
+ * connection/disconnection events.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+int stm32_usbhost_initialize(void)
+{
+ int ret;
+
+ /* First, register all of the class drivers needed to support the drivers
+ * that we care about:
+ */
+
+ uinfo("Register class drivers\n");
+
+#ifdef CONFIG_USBHOST_HUB
+ /* Initialize USB hub class support */
+
+ ret = usbhost_hub_initialize();
+ if (ret < 0)
+ {
+ uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_MSC
+ /* Register the USB mass storage class class */
+
+ ret = usbhost_msc_initialize();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_CDCACM
+ /* Register the CDC/ACM serial class */
+
+ ret = usbhost_cdcacm_initialize();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_HIDKBD
+ /* Initialize the HID keyboard class */
+
+ ret = usbhost_kbdinit();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the HID keyboard class\n");
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_HIDMOUSE
+ /* Initialize the HID mouse class */
+
+ ret = usbhost_mouse_init();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the HID mouse class\n");
+ }
+#endif
+
+ /* Then get an instance of the USB host interface */
+
+ uinfo("Initialize USB host\n");
+ g_usbconn = stm32_otgfshost_initialize(0);
+ if (g_usbconn)
+ {
+ /* Start a thread to handle device connection. */
+
+ uinfo("Start usbhost_waiter\n");
+
+ ret = kthread_create("usbhost", CONFIG_WEACT_STM32H743_USBHOST_PRIO,
+ CONFIG_WEACT_STM32H743_USBHOST_STACKSIZE,
+ usbhost_waiter, NULL);
+ return ret < 0 ? -ENOEXEC : OK;
+ }
+
+ return -ENODEV;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_usbhost_vbusdrive
+ *
+ * Description:
+ * Enable/disable driving of VBUS 5V output. This function must be
+ * provided be each platform that implements the STM32 OTG FS host
+ * interface
+ *
+ * "On-chip 5 V VBUS generation is not supported. For this reason, a
+ * charge pump or, if 5 V are available on the application board, a
+ * basic power switch, must be added externally to drive the 5 V VBUS
+ * line. The external charge pump can be driven by any GPIO output.
+ * When the application decides to power on VBUS using the chosen GPIO,
+ * it must also set the port power bit in the host port control and status
+ * register (PPWR bit in OTG_FS_HPRT).
+ *
+ * "The application uses this field to control power to this port, and
+ * the core clears this bit on an overcurrent condition."
+ *
+ * Input Parameters:
+ * iface - For future growth to handle multiple USB host interface.
+ * Should be zero.
+ * enable - true: enable VBUS power; false: disable VBUS power
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+void stm32_usbhost_vbusdrive(int iface, bool enable)
+{
+ DEBUGASSERT(iface == 0);
+
+ /* Set the Power Switch by driving the active high enable pin */
+
+ stm32_gpiowrite(GPIO_OTGFS_PWRON, enable);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_setup_overcurrent
+ *
+ * Description:
+ * Setup to receive an interrupt-level callback if an overcurrent
+ * condition is detected.
+ *
+ * Input Parameters:
+ * handler - New overcurrent interrupt handler
+ * arg - The argument provided for the interrupt handler
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success. Otherwise, a negated errno value
+ * is returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+int stm32_setup_overcurrent(xcpt_t handler, void *arg)
+{
+ return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_usbsuspend
+ *
+ * Description:
+ * Board logic must provide the stm32_usbsuspend logic if the USBDEV
+ * driver is used. This function is called whenever the USB enters or
+ * leaves suspend mode. This is an opportunity for the board logic to
+ * shutdown clocks, power, etc. while the USB is suspended.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV
+void stm32_usbsuspend(struct usbdev_s *dev, bool resume)
+{
+ uinfo("resume: %d\n", resume);
+}
+#endif
+
+#endif /* CONFIG_STM32_OTGFS */
diff --git a/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h b/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
index be9c3fac6c..da79f743f6 100644
--- a/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
+++ b/boards/arm/stm32h7/weact-stm32h743/src/weact-stm32h743.h
@@ -36,6 +36,9 @@
/* Configuration ************************************************************/
+#define HAVE_USBDEV 1
+#define HAVE_USBHOST 1
+
/* procfs File System */
#ifdef CONFIG_FS_PROCFS
@@ -46,6 +49,54 @@
# endif
#endif
+/* Can't support USB host or device features if USB OTG FS is not enabled */
+
+#ifndef CONFIG_STM32H7_OTGFS
+# undef HAVE_USBDEV
+# undef HAVE_USBHOST
+#endif
+
+/* Can't support USB device if USB device is not enabled */
+
+#ifndef CONFIG_USBDEV
+# undef HAVE_USBDEV
+#endif
+
+/* Can't support USB host is USB host is not enabled */
+
+#ifndef CONFIG_USBHOST
+# undef HAVE_USBHOST
+#endif
+
+/* Check if we should enable the USB monitor before starting NSH */
+
+#ifndef CONFIG_USBMONITOR
+# undef HAVE_USBMONITOR
+#endif
+
+#ifndef HAVE_USBDEV
+# undef CONFIG_USBDEV_TRACE
+#endif
+
+#ifndef HAVE_USBHOST
+# undef CONFIG_USBHOST_TRACE
+#endif
+
+#if !defined(CONFIG_USBDEV_TRACE) && !defined(CONFIG_USBHOST_TRACE)
+# undef HAVE_USBMONITOR
+#endif
+
+#if !defined(CONFIG_STM32H7_PROGMEM) || !defined(CONFIG_MTD_PROGMEM)
+# undef HAVE_PROGMEM_CHARDEV
+#endif
+
+/* Check if we can support the RTC driver */
+
+#define HAVE_RTC_DRIVER 1
+#if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER)
+# undef HAVE_RTC_DRIVER
+#endif
+
/* LED
*
* The WeAct STM32H743 board has only one Blue LED (E3) controlled by GPIO.