libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
st_usbfs_v1.c
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2010 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
24#include <libopencm3/usb/usbd.h>
25#include "../usb/usb_private.h"
26#include "common/st_usbfs_core.h"
27
29
30const struct _usbd_driver st_usbfs_v1_usb_driver = {
32 .set_address = st_usbfs_set_address,
33 .ep_setup = st_usbfs_ep_setup,
34 .ep_reset = st_usbfs_endpoints_reset,
35 .ep_stall_set = st_usbfs_ep_stall_set,
36 .ep_stall_get = st_usbfs_ep_stall_get,
37 .ep_nak_set = st_usbfs_ep_nak_set,
38 .ep_write_packet = st_usbfs_ep_write_packet,
39 .ep_read_packet = st_usbfs_ep_read_packet,
40 .poll = st_usbfs_poll,
41};
42
43/** Initialize the USB device controller hardware of the STM32. */
45{
50
51 /* Enable RESET, SUSPEND, RESUME and CTR interrupts. */
54 return &st_usbfs_dev;
55}
56
57void st_usbfs_copy_to_pm(volatile void *vPM, const void *buf, uint16_t len)
58{
59 const uint16_t *lbuf = buf;
60 volatile uint32_t *PM = vPM;
61 for (len = (len + 1) >> 1; len; len--) {
62 *PM++ = *lbuf++;
63 }
64}
65
66/**
67 * Copy a data buffer from packet memory.
68 *
69 * @param buf Source pointer to data buffer.
70 * @param vPM Destination pointer into packet memory.
71 * @param len Number of bytes to copy.
72 */
73void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
74{
75 uint16_t *lbuf = buf;
76 const volatile uint16_t *PM = vPM;
77 uint8_t odd = len & 1;
78
79 for (len >>= 1; len; PM += 2, lbuf++, len--) {
80 *lbuf = *PM;
81 }
82
83 if (odd) {
84 *(uint8_t *) lbuf = *(uint8_t *) PM;
85 }
86}
void rcc_periph_clock_enable(enum rcc_periph_clken clken)
Enable Peripheral Clock in running mode.
@ RCC_USB
Definition: f1/rcc.h:634
#define USB_CNTR_SUSPM
#define USB_CNTR_REG
#define USB_CNTR_RESETM
#define USB_CNTR_WKUPM
#define USB_ISTR_REG
#define USB_CNTR_CTRM
#define USB_BTABLE_REG
struct _usbd_device usbd_device
Definition: usbd.h:53
const struct _usbd_driver st_usbfs_v1_usb_driver
Definition: st_usbfs_v1.c:30
void st_usbfs_poll(usbd_device *dev)
void st_usbfs_ep_nak_set(usbd_device *dev, uint8_t addr, uint8_t nak)
uint16_t st_usbfs_ep_write_packet(usbd_device *dev, uint8_t addr, const void *buf, uint16_t len)
struct _usbd_device st_usbfs_dev
Definition: st_usbfs_core.c:31
void st_usbfs_ep_setup(usbd_device *dev, uint8_t addr, uint8_t type, uint16_t max_size, void(*callback)(usbd_device *usbd_dev, uint8_t ep))
Definition: st_usbfs_core.c:80
uint8_t st_usbfs_ep_stall_get(usbd_device *dev, uint8_t addr)
void st_usbfs_endpoints_reset(usbd_device *dev)
uint16_t st_usbfs_ep_read_packet(usbd_device *dev, uint8_t addr, void *buf, uint16_t len)
void st_usbfs_ep_stall_set(usbd_device *dev, uint8_t addr, uint8_t stall)
void st_usbfs_set_address(usbd_device *dev, uint8_t addr)
Definition: st_usbfs_core.c:33
static usbd_device * st_usbfs_v1_usbd_init(void)
Initialize the USB device controller hardware of the STM32.
Definition: st_usbfs_v1.c:44
void st_usbfs_copy_to_pm(volatile void *vPM, const void *buf, uint16_t len)
Definition: st_usbfs_v1.c:57
void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
Copy a data buffer from packet memory.
Definition: st_usbfs_v1.c:73
#define SET_REG(REG, VAL)
Definition: tools.h:31