Skip to content

Commit

Permalink
weact stm32h743vit6 usbconsole fix
Browse files Browse the repository at this point in the history
fix previous problemc
  • Loading branch information
TOMASHEVSKIYIVAN committed Sep 27, 2024
1 parent 4bfa73f commit 6b8f57e
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 1 deletion.
5 changes: 5 additions & 0 deletions boards/arm/stm32h7/weact-stm32h743/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@
#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 */
/****************************************************************************

Check failure on line 346 in boards/arm/stm32h7/weact-stm32h743/include/board.h

View workflow job for this annotation

GitHub Actions / check

Wrong column position or missing blank line before comment
* Public Data
****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32h7/weact-stm32h743/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions boards/arm/stm32h7/weact-stm32h743/src/stm32_ioctl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/****************************************************************************
* 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
* 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 <errno.h>

#include <nuttx/board.h>

#include "weact-stm32h743.h"

#ifdef CONFIG_BOARDCTL_IOCTL

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: board_ioctl
*
* Description:
* 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.
*
* Input Parameters:
* cmd - IOCTL command being requested.
* arg - Arguments for the IOCTL.
*
* 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 board_ioctl(unsigned int cmd, uintptr_t arg)
{
switch (cmd)
{
default:
return -ENOTTY;
}

return OK;
}

#endif /* CONFIG_BOARDCTL_IOCTL */
294 changes: 294 additions & 0 deletions boards/arm/stm32h7/weact-stm32h743/src/stm32_usb.c
Original file line number Diff line number Diff line change
@@ -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 */
Loading

0 comments on commit 6b8f57e

Please sign in to comment.