libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usb_f207.c
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <string.h>
24#include <libopencm3/usb/usbd.h>
26#include "usb_private.h"
27#include "usb_dwc_common.h"
28
29/* Receive FIFO size in 32-bit words. */
30#define RX_FIFO_SIZE 512
31
33
34static struct _usbd_device usbd_dev;
35
36const struct _usbd_driver stm32f207_usb_driver = {
37 .init = stm32f207_usbd_init,
38 .set_address = dwc_set_address,
39 .ep_setup = dwc_ep_setup,
40 .ep_reset = dwc_endpoints_reset,
41 .ep_stall_set = dwc_ep_stall_set,
42 .ep_stall_get = dwc_ep_stall_get,
43 .ep_nak_set = dwc_ep_nak_set,
44 .ep_write_packet = dwc_ep_write_packet,
45 .ep_read_packet = dwc_ep_read_packet,
46 .poll = dwc_poll,
47 .disconnect = dwc_disconnect,
48 .base_address = USB_OTG_HS_BASE,
49 .set_address_before_status = 1,
50 .rx_fifo_size = RX_FIFO_SIZE,
51};
52
53/** Initialize the USB device controller hardware of the STM32. */
55{
58
60 /* Enable VBUS sensing in device mode and power down the PHY. */
62
63 /* Wait for AHB idle. */
65 /* Do core soft reset. */
68
69 /* Force peripheral only mode. */
71
72 /* Full speed device. */
74
75 /* Restart the PHY clock. */
77
79 usbd_dev.fifo_mem_top = stm32f207_usb_driver.rx_fifo_size;
80
81 /* Unmask interrupts for TX and RX. */
88 OTG_HS_DAINTMSK = 0xF;
90
91 return &usbd_dev;
92}
void rcc_periph_clock_enable(enum rcc_periph_clken clken)
Enable Peripheral Clock in running mode.
@ RCC_OTGHS
Definition: f2/rcc.h:626
const struct _usbd_driver stm32f207_usb_driver
Definition: usb_f207.c:36
struct _usbd_device usbd_device
Definition: usbd.h:53
#define OTG_GUSBCFG_FDMOD
Definition: otg_common.h:125
#define OTG_DIEPMSK_XFRCM
Definition: otg_common.h:270
#define OTG_GINTMSK_IEPINT
Definition: otg_common.h:188
#define OTG_GRSTCTL_AHBIDL
Definition: otg_common.h:130
#define OTG_GINTMSK_RXFLVLM
Definition: otg_common.h:177
#define OTG_GRSTCTL_CSRST
Definition: otg_common.h:139
#define OTG_GAHBCFG_GINT
Definition: otg_common.h:114
#define OTG_GINTMSK_WUIM
Definition: otg_common.h:199
#define OTG_GUSBCFG_PHYSEL
Definition: otg_common.h:127
#define OTG_GCCFG_VBUSBSEN
Definition: otg_common.h:228
#define OTG_DCFG_DSPD
Definition: otg_common.h:251
#define OTG_GINTSTS_MMIS
Definition: otg_common.h:170
#define OTG_GINTMSK_ENUMDNEM
Definition: otg_common.h:184
#define OTG_GUSBCFG_TRDT_MASK
Definition: otg_common.h:122
#define OTG_GCCFG_PWRDWN
Definition: otg_common.h:231
#define OTG_GINTMSK_USBSUSPM
Definition: otg_common.h:182
#define OTG_HS_GRXFSIZ
Definition: otg_hs.h:65
#define OTG_HS_DIEPMSK
Definition: otg_hs.h:92
#define OTG_HS_GAHBCFG
Definition: otg_hs.h:58
#define OTG_HS_GCCFG
Definition: otg_hs.h:68
#define OTG_HS_GINTSTS
Definition: otg_hs.h:61
#define OTG_HS_GINTMSK
Definition: otg_hs.h:62
#define OTG_HS_PCGCCTL
Definition: otg_hs.h:120
#define OTG_HS_GRSTCTL
Definition: otg_hs.h:60
#define OTG_HS_DCFG
Definition: otg_hs.h:89
#define OTG_HS_DAINTMSK
Definition: otg_hs.h:95
#define OTG_HS_GUSBCFG
Definition: otg_hs.h:59
#define USB_OTG_HS_BASE
uint8_t dwc_ep_stall_get(usbd_device *usbd_dev, uint8_t addr)
void dwc_disconnect(usbd_device *usbd_dev, bool disconnected)
void dwc_endpoints_reset(usbd_device *usbd_dev)
uint16_t dwc_ep_write_packet(usbd_device *usbd_dev, uint8_t addr, const void *buf, uint16_t len)
uint16_t dwc_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len)
void dwc_set_address(usbd_device *usbd_dev, uint8_t addr)
void dwc_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak)
void dwc_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall)
void dwc_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size, void(*callback)(usbd_device *usbd_dev, uint8_t ep))
void dwc_poll(usbd_device *usbd_dev)
#define RX_FIFO_SIZE
Definition: usb_f207.c:30
static struct _usbd_device usbd_dev
Definition: usb_f207.c:34
static usbd_device * stm32f207_usbd_init(void)
Initialize the USB device controller hardware of the STM32.
Definition: usb_f207.c:54