usb: extract ST USB FS peripheral core. [BREAKING CHANGE]
The breaking changes here changes in header location, and changes in driver
name passed down to the usb stack.
Changes affect: stm32f102/f103, stm32l1, and some f3 parts
* instead of the confusingly generic "usb" use the name "st_usbfs" for the USB
Full speed peripheral ST provides in a variety of their stm32 products.
Include directives should change as:
#include <libopencm3/stm32/usb.h> => <libopencm3/stm32/st_usbfs.h>
* instead of the confusingly specific "f103" name for the driver, use
"st_usbfs_v1" [BREAKING_CHANGE]
Instead of:
usbd_init(&stm32f103_usb_driver, .....) ==>
usbd_init(&st_usbfs_v1_usb_driver, .....) ==>
The purpose of these changes is to reduce some confusion around naming, but
primarily to prepare for the "v2" peripheral available on stm32f0/l0 and some
f3 devices.
Work by Frantisek Burian, Kuldeep Singh Dhaka, Robin Kreis, fenugrec and zyp
on irc, and all those forgotten.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/** @defgroup adc_defines USB Defines
|
||||
/** @defgroup usb_defines USB Defines
|
||||
|
||||
@brief <b>Defined Constants and Types for the STM32F1xx USB Module</b>
|
||||
@brief <b>Defined Constants and Types for the STM32F* USB drivers</b>
|
||||
|
||||
@ingroup STM32F1xx_defines
|
||||
@ingroup STM32Fx_defines
|
||||
|
||||
@version 1.0.0
|
||||
|
||||
@@ -32,15 +32,28 @@ LGPL License Terms @ref lgpl_license
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY !
|
||||
* Use top-level <libopencm3/stm32/st_usbfs.h>
|
||||
*/
|
||||
|
||||
/**@{*/
|
||||
|
||||
#ifndef LIBOPENCM3_USB_H
|
||||
#define LIBOPENCM3_USB_H
|
||||
/** @cond */
|
||||
#ifdef LIBOPENCM3_ST_USBFS_H
|
||||
/** @endcond */
|
||||
#ifndef LIBOPENCM3_ST_USBFS_COMMON_H
|
||||
#define LIBOPENCM3_ST_USBFS_COMMON_H
|
||||
|
||||
#include <libopencm3/cm3/common.h>
|
||||
#include <libopencm3/stm32/memorymap.h>
|
||||
#include <libopencm3/stm32/tools.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* --- USB general registers ----------------------------------------------- */
|
||||
|
||||
/* USB Control register */
|
||||
@@ -54,14 +67,14 @@ LGPL License Terms @ref lgpl_license
|
||||
/* USB Buffer table address register */
|
||||
#define USB_BTABLE_REG (&MMIO32(USB_DEV_FS_BASE + 0x50))
|
||||
|
||||
/* Link Power Management register */
|
||||
#define USB_LPMCSR_REG (&MMIO32(USB_DEV_FS_BASE + 0x54))
|
||||
/* Battery Charge Detection register */
|
||||
#define USB_BCDR_REG (&MMIO32(USB_DEV_FS_BASE + 0x58))
|
||||
|
||||
/* USB EP register */
|
||||
#define USB_EP_REG(EP) (&MMIO32(USB_DEV_FS_BASE) + (EP))
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register values */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* --- USB control register masks / bits ----------------------------------- */
|
||||
|
||||
/* Interrupt mask bits, set to 1 to enable interrupt generation */
|
||||
@@ -75,8 +88,6 @@ LGPL License Terms @ref lgpl_license
|
||||
#define USB_CNTR_ESOFM 0x0100
|
||||
|
||||
/* Request/Force bits */
|
||||
#define USB_CNTR_L1REQM 0x0080 /* F0 port */
|
||||
#define USB_CNTR_L1RESUME 0x0020 /* F0 port */
|
||||
#define USB_CNTR_RESUME 0x0010 /* Resume request */
|
||||
#define USB_CNTR_FSUSP 0x0008 /* Force suspend */
|
||||
#define USB_CNTR_LP_MODE 0x0004 /* Low-power mode */
|
||||
@@ -93,7 +104,6 @@ LGPL License Terms @ref lgpl_license
|
||||
#define USB_ISTR_RESET 0x0400 /* USB RESET request */
|
||||
#define USB_ISTR_SOF 0x0200 /* Start Of Frame */
|
||||
#define USB_ISTR_ESOF 0x0100 /* Expected Start Of Frame */
|
||||
#define USB_ISTR_L1REQ 0x0080
|
||||
#define USB_ISTR_DIR 0x0010 /* Direction of transaction */
|
||||
#define USB_ISTR_EP_ID 0x000F /* Endpoint Identifier */
|
||||
|
||||
@@ -108,7 +118,7 @@ LGPL License Terms @ref lgpl_license
|
||||
#define USB_CLR_ISTR_SOF() CLR_REG_BIT(USB_ISTR_REG, USB_ISTR_SOF)
|
||||
#define USB_CLR_ISTR_ESOF() CLR_REG_BIT(USB_ISTR_REG, USB_ISTR_ESOF)
|
||||
|
||||
/* USB Frame Number Register bits ------------------------------------------ */
|
||||
/* --- USB Frame Number Register bits -------------------------------------- */
|
||||
|
||||
#define USB_FNR_RXDP (1 << 15)
|
||||
#define USB_FNR_RXDM (1 << 14)
|
||||
@@ -121,27 +131,12 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
/* --- USB device address register masks / bits ---------------------------- */
|
||||
|
||||
#define USB_DADDR_EF 0x0080
|
||||
#define USB_DADDR_EF (1 << 7)
|
||||
#define USB_DADDR_ADDR 0x007F
|
||||
|
||||
/* --- USB Link Power Management control/status register masks / bits ------ */
|
||||
#define USB_LPMCSR_BESL_SHIFT 4
|
||||
#define USB_LPMCSR_BESL (15 << USB_LPMCSR_BESL_SHIFT)
|
||||
/* USB_BTABLE Values ------------------------------------------------------- */
|
||||
|
||||
#define USB_LPMCSR_REMWAKE (1 << 3)
|
||||
#define USB_LPMCSR_LPMACK (1 << 1)
|
||||
#define USB_LPMCSR_LPMEN (1 << 0)
|
||||
|
||||
/* --- USB Battery Charge Detection register masks / bits ------ */
|
||||
#define USB_BCDR_DPPU (1 << 15)
|
||||
#define USB_BCDR_PS2DET (1 << 7)
|
||||
#define USB_BCDR_SDET (1 << 6)
|
||||
#define USB_BCDR_PDET (1 << 5)
|
||||
#define USB_BCDR_DCDET (1 << 4)
|
||||
#define USB_BCDR_SDEN (1 << 3)
|
||||
#define USB_BCDR_PDEN (1 << 2)
|
||||
#define USB_BCDR_DCDEN (1 << 1)
|
||||
#define USB_BCDR_BCDEN (1 << 0)
|
||||
#define USB_BTABLE_BTABLE 0xFFF8
|
||||
|
||||
/* --- USB device address register manipulators ---------------------------- */
|
||||
|
||||
@@ -240,6 +235,7 @@ LGPL License Terms @ref lgpl_license
|
||||
#define USB_CLR_EP_TX_CTR(EP) \
|
||||
USB_CLR_EP_NTOGGLE_BIT_AND_SET(EP, USB_EP_TX_CTR, USB_EP_RX_CTR)
|
||||
|
||||
|
||||
#define USB_SET_EP_TYPE(EP, TYPE) \
|
||||
SET_REG(USB_EP_REG(EP), \
|
||||
(GET_REG(USB_EP_REG(EP)) & \
|
||||
@@ -277,22 +273,11 @@ LGPL License Terms @ref lgpl_license
|
||||
GET_REG(USB_EP_REG(EP)) & \
|
||||
(USB_EP_NTOGGLE_MSK | USB_EP_RX_DTOG))
|
||||
|
||||
|
||||
/* --- USB BTABLE registers ------------------------------------------------ */
|
||||
|
||||
#define USB_GET_BTABLE GET_REG(USB_BTABLE_REG)
|
||||
|
||||
#define USB_EP_TX_ADDR(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 0) * 2))
|
||||
|
||||
#define USB_EP_TX_COUNT(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 2) * 2))
|
||||
|
||||
#define USB_EP_RX_ADDR(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 4) * 2))
|
||||
|
||||
#define USB_EP_RX_COUNT(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 6) * 2))
|
||||
|
||||
/* --- USB BTABLE manipulators --------------------------------------------- */
|
||||
|
||||
#define USB_GET_EP_TX_ADDR(EP) GET_REG(USB_EP_TX_ADDR(EP))
|
||||
@@ -304,13 +289,14 @@ LGPL License Terms @ref lgpl_license
|
||||
#define USB_SET_EP_RX_ADDR(EP, ADDR) SET_REG(USB_EP_RX_ADDR(EP), ADDR)
|
||||
#define USB_SET_EP_RX_COUNT(EP, COUNT) SET_REG(USB_EP_RX_COUNT(EP), COUNT)
|
||||
|
||||
#define USB_GET_EP_TX_BUFF(EP) \
|
||||
(USB_PMA_BASE + (uint8_t *)(USB_GET_EP_TX_ADDR(EP) * 2))
|
||||
|
||||
#define USB_GET_EP_RX_BUFF(EP) \
|
||||
(USB_PMA_BASE + (uint8_t *)(USB_GET_EP_RX_ADDR(EP) * 2))
|
||||
|
||||
#endif
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif
|
||||
/** @cond */
|
||||
#else
|
||||
#error "st_usbfs_common.h should not be included explicitly, only via st_usbfs.h"
|
||||
#endif
|
||||
/** @endcond */
|
||||
|
||||
67
include/libopencm3/stm32/common/st_usbfs_v1.h
Normal file
67
include/libopencm3/stm32/common/st_usbfs_v1.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/** @addtogroup usb_defines
|
||||
*/
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY !
|
||||
* Use top-level <libopencm3/stm32/st_usbfs.h>
|
||||
*
|
||||
* Additional definitions for F1, F3, L1 devices:
|
||||
* -F102, F103 (RM0008)
|
||||
* -F302x{B,C}; *NOT* F302x{6,8,D,E} !! (USB_BTABLE access issues) (RM0365)
|
||||
* -F303x{B,C}; *NOT* F303x{D,E} !! (USB_BTABLE access issues) (RM0316)
|
||||
* -F37x (RM0313)
|
||||
* -L1xx (RM0038)
|
||||
*/
|
||||
|
||||
/** @cond */
|
||||
#ifdef LIBOPENCM3_ST_USBFS_H
|
||||
/** @endcond */
|
||||
#ifndef LIBOPENCM3_ST_USBFS_V1_H
|
||||
#define LIBOPENCM3_ST_USBFS_V1_H
|
||||
|
||||
#include <libopencm3/stm32/common/st_usbfs_common.h>
|
||||
|
||||
/* --- USB BTABLE Registers ------------------------------------------------ */
|
||||
|
||||
#define USB_EP_TX_ADDR(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 0) * 2))
|
||||
|
||||
#define USB_EP_TX_COUNT(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 2) * 2))
|
||||
|
||||
#define USB_EP_RX_ADDR(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 4) * 2))
|
||||
|
||||
#define USB_EP_RX_COUNT(EP) \
|
||||
((uint32_t *)(USB_PMA_BASE + (USB_GET_BTABLE + EP * 8 + 6) * 2))
|
||||
|
||||
/* --- USB BTABLE manipulators --------------------------------------------- */
|
||||
|
||||
#define USB_GET_EP_TX_BUFF(EP) \
|
||||
(USB_PMA_BASE + (uint8_t *)(USB_GET_EP_TX_ADDR(EP) * 2))
|
||||
|
||||
#define USB_GET_EP_RX_BUFF(EP) \
|
||||
(USB_PMA_BASE + (uint8_t *)(USB_GET_EP_RX_ADDR(EP) * 2))
|
||||
|
||||
#endif
|
||||
/** @cond */
|
||||
#else
|
||||
#error "st_usbfs_v1.h should not be included directly, only via st_usbfs.h"
|
||||
#endif
|
||||
/** @endcond */
|
||||
|
||||
27
include/libopencm3/stm32/f1/st_usbfs.h
Normal file
27
include/libopencm3/stm32/f1/st_usbfs.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY !
|
||||
* Use top-level <libopencm3/stm32/st_usbfs.h>
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENCM3_ST_USBFS_H
|
||||
# error Do not include directly !
|
||||
#else
|
||||
|
||||
#include <libopencm3/stm32/common/st_usbfs_v1.h>
|
||||
|
||||
#endif
|
||||
27
include/libopencm3/stm32/f3/st_usbfs.h
Normal file
27
include/libopencm3/stm32/f3/st_usbfs.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY !
|
||||
* Use top-level <libopencm3/stm32/st_usbfs.h>
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENCM3_ST_USBFS_H
|
||||
# error Do not include directly !
|
||||
#else
|
||||
|
||||
#include <libopencm3/stm32/common/st_usbfs_v1.h>
|
||||
|
||||
#endif
|
||||
27
include/libopencm3/stm32/l1/st_usbfs.h
Normal file
27
include/libopencm3/stm32/l1/st_usbfs.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY !
|
||||
* Use top-level <libopencm3/stm32/st_usbfs.h>
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENCM3_ST_USBFS_H
|
||||
# error Do not include directly !
|
||||
#else
|
||||
|
||||
#include <libopencm3/stm32/common/st_usbfs_v1.h>
|
||||
|
||||
#endif
|
||||
36
include/libopencm3/stm32/st_usbfs.h
Normal file
36
include/libopencm3/stm32/st_usbfs.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* This provides unification of USB code for supported STM32F subfamilies */
|
||||
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENCM3_ST_USBFS_H
|
||||
#define LIBOPENCM3_ST_USBFS_H
|
||||
|
||||
#include <libopencm3/cm3/common.h>
|
||||
#include <libopencm3/stm32/memorymap.h>
|
||||
|
||||
#if defined(STM32F1)
|
||||
# include <libopencm3/stm32/f1/st_usbfs.h>
|
||||
#elif defined(STM32F3)
|
||||
# include <libopencm3/stm32/f3/st_usbfs.h>
|
||||
#elif defined(STM32L1)
|
||||
# include <libopencm3/stm32/l1/st_usbfs.h>
|
||||
#else
|
||||
# error "STM32 family not defined or not supported."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -52,7 +52,7 @@ enum usbd_request_return_codes {
|
||||
typedef struct _usbd_driver usbd_driver;
|
||||
typedef struct _usbd_device usbd_device;
|
||||
|
||||
extern const usbd_driver stm32f103_usb_driver;
|
||||
extern const usbd_driver st_usbfs_v1_usb_driver;
|
||||
extern const usbd_driver stm32f107_usb_driver;
|
||||
extern const usbd_driver stm32f207_usb_driver;
|
||||
#define otgfs_usb_driver stm32f107_usb_driver
|
||||
|
||||
Reference in New Issue
Block a user