2011-01-30 19:18:26 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2011-01-30 19:18:26 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-09-25 09:31:19 +00:00
|
|
|
* @file STM32/USBv1/usb_lld.c
|
2011-01-30 19:18:26 +00:00
|
|
|
* @brief STM32 USB subsystem low level driver source.
|
|
|
|
*
|
|
|
|
* @addtogroup USB
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#if HAL_USE_USB || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
#define BTABLE_ADDR 0x0000
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/** @brief USB1 driver identifier.*/
|
|
|
|
#if STM32_USB_USE_USB1 || defined(__DOXYGEN__)
|
|
|
|
USBDriver USBD1;
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief EP0 state.
|
2011-02-14 19:37:40 +00:00
|
|
|
* @note It is an union because IN and OUT endpoints are never used at the
|
|
|
|
* same time for EP0.
|
2011-02-05 09:27:20 +00:00
|
|
|
*/
|
2011-02-14 19:37:40 +00:00
|
|
|
static union {
|
|
|
|
/**
|
|
|
|
* @brief IN EP0 state.
|
|
|
|
*/
|
|
|
|
USBInEndpointState in;
|
|
|
|
/**
|
|
|
|
* @brief OUT EP0 state.
|
|
|
|
*/
|
|
|
|
USBOutEndpointState out;
|
|
|
|
} ep0_state;
|
2011-02-05 09:27:20 +00:00
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Buffer for the EP0 setup packets.
|
|
|
|
*/
|
|
|
|
static uint8_t ep0setup_buffer[8];
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
/**
|
|
|
|
* @brief EP0 initialization structure.
|
|
|
|
*/
|
2011-02-05 09:27:20 +00:00
|
|
|
static const USBEndpointConfig ep0config = {
|
2012-06-16 06:22:39 +00:00
|
|
|
USB_EP_MODE_TYPE_CTRL,
|
2011-03-10 18:54:58 +00:00
|
|
|
_usb_ep0setup,
|
2011-01-30 19:18:26 +00:00
|
|
|
_usb_ep0in,
|
|
|
|
_usb_ep0out,
|
|
|
|
0x40,
|
2011-02-14 19:37:40 +00:00
|
|
|
0x40,
|
|
|
|
&ep0_state.in,
|
2012-06-16 06:22:39 +00:00
|
|
|
&ep0_state.out,
|
|
|
|
ep0setup_buffer
|
2011-01-30 19:18:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-02-13 20:55:57 +00:00
|
|
|
/**
|
|
|
|
* @brief Resets the packet memory allocator.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*/
|
2012-06-16 14:08:20 +00:00
|
|
|
static void usb_pm_reset(USBDriver *usbp) {
|
2011-02-15 09:16:17 +00:00
|
|
|
|
|
|
|
/* The first 64 bytes are reserved for the descriptors table. The effective
|
|
|
|
available RAM for endpoint buffers is just 448 bytes.*/
|
2011-02-13 20:55:57 +00:00
|
|
|
usbp->pmnext = 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resets the packet memory allocator.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] size size of the packet buffer to allocate
|
|
|
|
*/
|
2012-06-16 14:08:20 +00:00
|
|
|
static uint32_t usb_pm_alloc(USBDriver *usbp, size_t size) {
|
2011-02-15 09:16:17 +00:00
|
|
|
uint32_t next;
|
|
|
|
|
|
|
|
next = usbp->pmnext;
|
2011-02-13 20:55:57 +00:00
|
|
|
usbp->pmnext += size;
|
2012-06-16 14:08:20 +00:00
|
|
|
chDbgAssert(usbp->pmnext <= USB_PMA_SIZE, "usb_pm_alloc(), #1", "PMA overflow");
|
2011-02-13 20:55:57 +00:00
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Reads from a dedicated packet buffer.
|
|
|
|
*
|
2012-06-16 14:08:20 +00:00
|
|
|
* @param[in] udp pointer to a @p stm32_usb_descriptor_t
|
2012-06-16 06:22:39 +00:00
|
|
|
* @param[out] buf buffer where to copy the packet data
|
|
|
|
* @param[in] n maximum number of bytes to copy. This value must
|
|
|
|
* not exceed the maximum packet size for this endpoint.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2012-06-16 14:08:20 +00:00
|
|
|
static void usb_packet_read_to_buffer(stm32_usb_descriptor_t *udp,
|
|
|
|
uint8_t *buf, size_t n) {
|
|
|
|
uint32_t *pmap= USB_ADDR2PTR(udp->RXADDR0);
|
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
n = (n + 1) / 2;
|
|
|
|
while (n > 0) {
|
2012-06-16 14:08:20 +00:00
|
|
|
/* Note, this line relies on the Cortex-M3/M4 ability to perform
|
|
|
|
unaligned word accesses.*/
|
2012-06-16 06:22:39 +00:00
|
|
|
*(uint16_t *)buf = (uint16_t)*pmap++;
|
|
|
|
buf += 2;
|
|
|
|
n--;
|
|
|
|
}
|
2012-06-16 14:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads from a dedicated packet buffer.
|
|
|
|
*
|
|
|
|
* @param[in] udp pointer to a @p stm32_usb_descriptor_t
|
|
|
|
* @param[in] iqp pointer to an @p InputQueue object
|
|
|
|
* @param[in] n maximum number of bytes to copy. This value must
|
|
|
|
* not exceed the maximum packet size for this endpoint.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
static void usb_packet_read_to_queue(stm32_usb_descriptor_t *udp,
|
|
|
|
InputQueue *iqp, size_t n) {
|
2012-06-16 15:04:12 +00:00
|
|
|
size_t nhw;
|
|
|
|
uint32_t *pmap= USB_ADDR2PTR(udp->RXADDR0);
|
|
|
|
|
|
|
|
nhw = n / 2;
|
|
|
|
while (nhw > 0) {
|
2012-06-17 05:04:51 +00:00
|
|
|
uint32_t w;
|
|
|
|
|
2012-06-16 15:04:12 +00:00
|
|
|
w = *pmap++;
|
|
|
|
*iqp->q_wrptr++ = (uint8_t)w;
|
|
|
|
if (iqp->q_wrptr >= iqp->q_top)
|
|
|
|
iqp->q_wrptr = iqp->q_buffer;
|
|
|
|
*iqp->q_wrptr++ = (uint8_t)(w >> 8);
|
|
|
|
if (iqp->q_wrptr >= iqp->q_top)
|
|
|
|
iqp->q_wrptr = iqp->q_buffer;
|
|
|
|
nhw--;
|
|
|
|
}
|
|
|
|
/* Last byte for odd numbers.*/
|
|
|
|
if ((n & 1) != 0) {
|
2012-06-17 05:04:51 +00:00
|
|
|
*iqp->q_wrptr++ = (uint8_t)*pmap;
|
2012-06-16 15:04:12 +00:00
|
|
|
if (iqp->q_wrptr >= iqp->q_top)
|
|
|
|
iqp->q_wrptr = iqp->q_buffer;
|
|
|
|
}
|
|
|
|
|
2012-06-17 06:53:49 +00:00
|
|
|
/* Updating queue.*/
|
|
|
|
chSysLockFromIsr();
|
2012-06-16 15:04:12 +00:00
|
|
|
iqp->q_counter += n;
|
2012-06-17 06:53:49 +00:00
|
|
|
while (notempty(&iqp->q_waiting))
|
|
|
|
chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK;
|
|
|
|
chSysUnlockFromIsr();
|
2012-06-16 06:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Writes to a dedicated packet buffer.
|
|
|
|
*
|
2012-06-16 14:08:20 +00:00
|
|
|
* @param[in] udp pointer to a @p stm32_usb_descriptor_t
|
2012-06-16 06:22:39 +00:00
|
|
|
* @param[in] buf buffer where to fetch the packet data
|
|
|
|
* @param[in] n maximum number of bytes to copy. This value must
|
|
|
|
* not exceed the maximum packet size for this endpoint.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2012-06-16 14:08:20 +00:00
|
|
|
static void usb_packet_write_from_buffer(stm32_usb_descriptor_t *udp,
|
|
|
|
const uint8_t *buf,
|
|
|
|
size_t n) {
|
|
|
|
uint32_t *pmap = USB_ADDR2PTR(udp->TXADDR0);
|
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
udp->TXCOUNT0 = (uint16_t)n;
|
|
|
|
n = (n + 1) / 2;
|
|
|
|
while (n > 0) {
|
2012-06-16 14:08:20 +00:00
|
|
|
/* Note, this line relies on the Cortex-M3/M4 ability to perform
|
|
|
|
unaligned word accesses.*/
|
2012-06-16 06:22:39 +00:00
|
|
|
*pmap++ = *(uint16_t *)buf;
|
|
|
|
buf += 2;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 05:04:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Writes to a dedicated packet buffer.
|
|
|
|
*
|
|
|
|
* @param[in] udp pointer to a @p stm32_usb_descriptor_t
|
|
|
|
* @param[in] buf buffer where to fetch the packet data
|
|
|
|
* @param[in] n maximum number of bytes to copy. This value must
|
|
|
|
* not exceed the maximum packet size for this endpoint.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
static void usb_packet_write_from_queue(stm32_usb_descriptor_t *udp,
|
|
|
|
OutputQueue *oqp, size_t n) {
|
|
|
|
size_t nhw;
|
|
|
|
uint32_t *pmap = USB_ADDR2PTR(udp->TXADDR0);
|
|
|
|
|
|
|
|
udp->TXCOUNT0 = (uint16_t)n;
|
|
|
|
nhw = n / 2;
|
|
|
|
while (nhw > 0) {
|
|
|
|
uint32_t w;
|
|
|
|
|
|
|
|
w = (uint32_t)*oqp->q_rdptr++;
|
|
|
|
if (oqp->q_rdptr >= oqp->q_top)
|
|
|
|
oqp->q_rdptr = oqp->q_buffer;
|
|
|
|
w |= (uint32_t)*oqp->q_rdptr++ << 8;
|
|
|
|
if (oqp->q_rdptr >= oqp->q_top)
|
|
|
|
oqp->q_rdptr = oqp->q_buffer;
|
|
|
|
*pmap++ = w;
|
|
|
|
nhw--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Last byte for odd numbers.*/
|
|
|
|
if ((n & 1) != 0) {
|
|
|
|
*pmap = (uint32_t)*oqp->q_rdptr++;
|
|
|
|
if (oqp->q_rdptr >= oqp->q_top)
|
|
|
|
oqp->q_rdptr = oqp->q_buffer;
|
|
|
|
}
|
2012-06-17 06:53:49 +00:00
|
|
|
|
|
|
|
/* Updating queue. Note, the lock is done in this unusual way because this
|
|
|
|
function can be called from both ISR and thread context so the kind
|
|
|
|
of lock function to be invoked cannot be decided beforehand.*/
|
|
|
|
port_lock();
|
|
|
|
dbg_enter_lock();
|
|
|
|
|
|
|
|
oqp->q_counter += n;
|
|
|
|
while (notempty(&oqp->q_waiting))
|
|
|
|
chSchReadyI(fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_OK;
|
|
|
|
|
|
|
|
dbg_leave_lock();
|
|
|
|
port_unlock();
|
2012-06-17 05:04:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if STM32_USB_USE_USB1 || defined(__DOXYGEN__)
|
|
|
|
/**
|
|
|
|
* @brief USB high priority interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2011-07-23 16:32:03 +00:00
|
|
|
CH_IRQ_HANDLER(Vector8C) {
|
2011-01-30 19:18:26 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USB low priority interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2011-07-23 16:32:03 +00:00
|
|
|
CH_IRQ_HANDLER(Vector90) {
|
2011-01-30 19:18:26 +00:00
|
|
|
uint32_t istr;
|
2011-02-06 09:51:16 +00:00
|
|
|
size_t n;
|
2011-01-30 19:18:26 +00:00
|
|
|
USBDriver *usbp = &USBD1;
|
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
|
|
|
istr = STM32_USB->ISTR;
|
|
|
|
|
|
|
|
/* USB bus reset condition handling.*/
|
|
|
|
if (istr & ISTR_RESET) {
|
|
|
|
_usb_reset(usbp);
|
2011-03-10 18:54:58 +00:00
|
|
|
_usb_isr_invoke_event_cb(usbp, USB_EVENT_RESET);
|
2011-01-30 19:18:26 +00:00
|
|
|
STM32_USB->ISTR = ~ISTR_RESET;
|
|
|
|
}
|
|
|
|
|
2011-02-15 18:44:29 +00:00
|
|
|
/* USB bus SUSPEND condition handling.*/
|
|
|
|
if (istr & ISTR_SUSP) {
|
|
|
|
STM32_USB->CNTR |= CNTR_FSUSP;
|
2011-03-10 18:54:58 +00:00
|
|
|
_usb_isr_invoke_event_cb(usbp, USB_EVENT_SUSPEND);
|
2011-02-15 18:44:29 +00:00
|
|
|
#if STM32_USB_LOW_POWER_ON_SUSPEND
|
|
|
|
STM32_USB->CNTR |= CNTR_LP_MODE;
|
|
|
|
#endif
|
|
|
|
STM32_USB->ISTR = ~ISTR_SUSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USB bus WAKEUP condition handling.*/
|
|
|
|
if (istr & ISTR_WKUP) {
|
|
|
|
uint32_t fnr = STM32_USB->FNR;
|
|
|
|
if (!(fnr & FNR_RXDP)) {
|
|
|
|
STM32_USB->CNTR &= ~CNTR_FSUSP;
|
2011-03-10 18:54:58 +00:00
|
|
|
_usb_isr_invoke_event_cb(usbp, USB_EVENT_WAKEUP);
|
2011-02-15 18:44:29 +00:00
|
|
|
}
|
|
|
|
#if STM32_USB_LOW_POWER_ON_SUSPEND
|
|
|
|
else {
|
|
|
|
/* Just noise, going back in SUSPEND mode, reference manual 22.4.5,
|
|
|
|
table 169.*/
|
|
|
|
STM32_USB->CNTR |= CNTR_LP_MODE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
STM32_USB->ISTR = ~ISTR_WKUP;
|
|
|
|
}
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
/* SOF handling.*/
|
|
|
|
if (istr & ISTR_SOF) {
|
2011-03-10 18:54:58 +00:00
|
|
|
_usb_isr_invoke_sof_cb(usbp);
|
2011-01-30 19:18:26 +00:00
|
|
|
STM32_USB->ISTR = ~ISTR_SOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Endpoint events handling.*/
|
|
|
|
while (istr & ISTR_CTR) {
|
|
|
|
uint32_t ep;
|
|
|
|
uint32_t epr = STM32_USB->EPR[ep = istr & ISTR_EP_ID_MASK];
|
2011-02-14 19:37:40 +00:00
|
|
|
const USBEndpointConfig *epcp = usbp->epc[ep];
|
2011-01-30 19:18:26 +00:00
|
|
|
|
|
|
|
if (epr & EPR_CTR_TX) {
|
|
|
|
/* IN endpoint, transmission.*/
|
|
|
|
EPR_CLEAR_CTR_TX(ep);
|
2012-06-16 06:22:39 +00:00
|
|
|
|
|
|
|
n = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT0;
|
|
|
|
epcp->in_state->mode.linear.txbuf += n;
|
|
|
|
epcp->in_state->txcnt += n;
|
|
|
|
epcp->in_state->txsize -= n;
|
|
|
|
if (epcp->in_state->txsize > 0) {
|
|
|
|
/* Transfer not completed, there are more packets to send.*/
|
|
|
|
if (epcp->in_state->txsize > epcp->in_maxsize)
|
|
|
|
n = epcp->in_maxsize;
|
|
|
|
else
|
|
|
|
n = epcp->in_state->txsize;
|
2012-06-17 06:53:49 +00:00
|
|
|
|
|
|
|
if (epcp->in_state->txqueued)
|
|
|
|
usb_packet_write_from_queue(USB_GET_DESCRIPTOR(ep),
|
|
|
|
epcp->in_state->mode.queue.txqueue,
|
|
|
|
n);
|
|
|
|
else
|
|
|
|
usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
|
|
|
|
epcp->in_state->mode.linear.txbuf,
|
|
|
|
n);
|
2012-06-17 05:04:51 +00:00
|
|
|
chSysLockFromIsr();
|
2012-06-16 06:22:39 +00:00
|
|
|
usb_lld_start_in(usbp, ep);
|
2012-06-17 05:04:51 +00:00
|
|
|
chSysUnlockFromIsr();
|
2011-02-06 09:51:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-16 06:22:39 +00:00
|
|
|
/* Transfer completed, invokes the callback.*/
|
|
|
|
_usb_isr_invoke_in_cb(usbp, ep);
|
2011-02-06 09:51:16 +00:00
|
|
|
}
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
if (epr & EPR_CTR_RX) {
|
|
|
|
EPR_CLEAR_CTR_RX(ep);
|
2011-02-06 09:51:16 +00:00
|
|
|
/* OUT endpoint, receive.*/
|
2011-03-10 18:54:58 +00:00
|
|
|
if (epr & EPR_SETUP) {
|
|
|
|
/* Setup packets handling, setup packets are handled using a
|
|
|
|
specific callback.*/
|
|
|
|
_usb_isr_invoke_setup_cb(usbp, ep);
|
|
|
|
}
|
2011-02-06 09:51:16 +00:00
|
|
|
else {
|
2012-06-16 14:08:20 +00:00
|
|
|
stm32_usb_descriptor_t *udp = USB_GET_DESCRIPTOR(ep);
|
|
|
|
n = (size_t)udp->RXCOUNT0 & RXCOUNT_COUNT_MASK;
|
|
|
|
|
2012-06-17 06:53:49 +00:00
|
|
|
/* Reads the packet into the defined buffer.*/
|
|
|
|
if (epcp->out_state->rxqueued)
|
|
|
|
usb_packet_read_to_queue(udp,
|
|
|
|
epcp->out_state->mode.queue.rxqueue,
|
|
|
|
n);
|
|
|
|
else
|
|
|
|
usb_packet_read_to_buffer(udp,
|
|
|
|
epcp->out_state->mode.linear.rxbuf,
|
|
|
|
n);
|
2012-06-16 14:08:20 +00:00
|
|
|
|
|
|
|
/* Transaction data updated.*/
|
2012-06-16 06:22:39 +00:00
|
|
|
epcp->out_state->mode.linear.rxbuf += n;
|
|
|
|
epcp->out_state->rxcnt += n;
|
|
|
|
epcp->out_state->rxsize -= n;
|
|
|
|
epcp->out_state->rxpkts -= 1;
|
2011-03-10 18:54:58 +00:00
|
|
|
if (epcp->out_state->rxpkts > 0) {
|
|
|
|
/* Transfer not completed, there are more packets to receive.*/
|
|
|
|
EPR_SET_STAT_RX(ep, EPR_STAT_RX_VALID);
|
2011-02-06 09:51:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-03-10 18:54:58 +00:00
|
|
|
/* Transfer completed, invokes the callback.*/
|
|
|
|
_usb_isr_invoke_out_cb(usbp, ep);
|
2011-02-06 09:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
istr = STM32_USB->ISTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Low level USB driver initialization.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_init(void) {
|
|
|
|
|
|
|
|
/* Driver initialization.*/
|
|
|
|
usbObjectInit(&USBD1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configures and activates the USB peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_start(USBDriver *usbp) {
|
|
|
|
|
2011-02-06 09:51:16 +00:00
|
|
|
if (usbp->state == USB_STOP) {
|
2011-01-30 19:18:26 +00:00
|
|
|
/* Clock activation.*/
|
|
|
|
#if STM32_USB_USE_USB1
|
|
|
|
if (&USBD1 == usbp) {
|
|
|
|
/* USB clock enabled.*/
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUSB(FALSE);
|
2011-01-30 19:18:26 +00:00
|
|
|
/* Powers up the transceiver while holding the USB in reset state.*/
|
|
|
|
STM32_USB->CNTR = CNTR_FRES;
|
|
|
|
/* Enabling the USB IRQ vectors, this also gives enough time to allow
|
|
|
|
the transceiver power up (1uS).*/
|
2011-12-21 18:49:04 +00:00
|
|
|
nvicEnableVector(19,
|
2011-01-30 19:18:26 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_USB_USB1_HP_IRQ_PRIORITY));
|
2011-12-21 18:49:04 +00:00
|
|
|
nvicEnableVector(20,
|
2011-01-30 19:18:26 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_USB_USB1_LP_IRQ_PRIORITY));
|
2011-02-14 19:45:28 +00:00
|
|
|
/* Releases the USB reset.*/
|
|
|
|
STM32_USB->CNTR = 0;
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-02-14 19:37:40 +00:00
|
|
|
/* Reset procedure enforced on driver start.*/
|
|
|
|
_usb_reset(usbp);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
/* Configuration.*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deactivates the USB peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_stop(USBDriver *usbp) {
|
|
|
|
|
|
|
|
/* If in ready state then disables the USB clock.*/
|
2011-02-06 09:51:16 +00:00
|
|
|
if (usbp->state == USB_STOP) {
|
2011-09-16 17:38:22 +00:00
|
|
|
#if STM32_USB_USE_USB1
|
2011-01-30 19:18:26 +00:00
|
|
|
if (&USBD1 == usbp) {
|
2011-12-21 18:49:04 +00:00
|
|
|
nvicDisableVector(19);
|
|
|
|
nvicDisableVector(20);
|
2011-02-14 19:37:40 +00:00
|
|
|
STM32_USB->CNTR = CNTR_PDWN | CNTR_FRES;
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUSB(FALSE);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USB low level reset routine.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_reset(USBDriver *usbp) {
|
|
|
|
uint32_t cntr;
|
|
|
|
|
2011-02-14 19:45:28 +00:00
|
|
|
/* Post reset initialization.*/
|
|
|
|
STM32_USB->BTABLE = 0;
|
2011-01-30 19:18:26 +00:00
|
|
|
STM32_USB->ISTR = 0;
|
|
|
|
STM32_USB->DADDR = DADDR_EF;
|
2011-02-15 18:44:29 +00:00
|
|
|
cntr = /*CNTR_ESOFM | */ CNTR_RESETM | CNTR_SUSPM |
|
|
|
|
CNTR_WKUPM | /*CNTR_ERRM | CNTR_PMAOVRM |*/ CNTR_CTRM;
|
2011-01-30 19:18:26 +00:00
|
|
|
/* The SOF interrupt is only enabled if a callback is defined for
|
|
|
|
this service because it is an high rate source.*/
|
2011-02-06 09:51:16 +00:00
|
|
|
if (usbp->config->sof_cb != NULL)
|
2011-01-30 19:18:26 +00:00
|
|
|
cntr |= CNTR_SOFM;
|
|
|
|
STM32_USB->CNTR = cntr;
|
2011-02-05 09:27:20 +00:00
|
|
|
|
2011-02-13 20:55:57 +00:00
|
|
|
/* Resets the packet memory allocator.*/
|
2012-06-16 14:08:20 +00:00
|
|
|
usb_pm_reset(usbp);
|
2011-02-13 20:55:57 +00:00
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
/* EP0 initialization.*/
|
2011-02-14 19:37:40 +00:00
|
|
|
usbp->epc[0] = &ep0config;
|
2011-02-05 09:27:20 +00:00
|
|
|
usb_lld_init_endpoint(usbp, 0);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the USB address.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2011-02-06 09:51:16 +00:00
|
|
|
void usb_lld_set_address(USBDriver *usbp) {
|
2011-01-30 19:18:26 +00:00
|
|
|
|
2011-02-06 09:51:16 +00:00
|
|
|
STM32_USB->DADDR = (uint32_t)(usbp->address) | DADDR_EF;
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables an endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2011-02-05 09:27:20 +00:00
|
|
|
void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
|
2011-02-08 06:29:27 +00:00
|
|
|
uint16_t nblocks, epr;
|
2011-01-30 19:18:26 +00:00
|
|
|
stm32_usb_descriptor_t *dp;
|
2011-02-14 19:37:40 +00:00
|
|
|
const USBEndpointConfig *epcp = usbp->epc[ep];
|
2011-01-30 19:18:26 +00:00
|
|
|
|
2011-02-08 06:29:27 +00:00
|
|
|
/* Setting the endpoint type.*/
|
2011-02-12 19:52:43 +00:00
|
|
|
switch (epcp->ep_mode & USB_EP_MODE_TYPE) {
|
|
|
|
case USB_EP_MODE_TYPE_ISOC:
|
2011-02-08 06:29:27 +00:00
|
|
|
epr = EPR_EP_TYPE_ISO;
|
|
|
|
break;
|
2011-02-12 19:52:43 +00:00
|
|
|
case USB_EP_MODE_TYPE_BULK:
|
2011-02-08 06:29:27 +00:00
|
|
|
epr = EPR_EP_TYPE_BULK;
|
|
|
|
break;
|
2011-02-12 19:52:43 +00:00
|
|
|
case USB_EP_MODE_TYPE_INTR:
|
2011-02-08 06:29:27 +00:00
|
|
|
epr = EPR_EP_TYPE_INTERRUPT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
epr = EPR_EP_TYPE_CONTROL;
|
|
|
|
}
|
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
/* IN endpoint initially in NAK mode.*/
|
2011-03-10 18:54:58 +00:00
|
|
|
if (epcp->in_cb != NULL)
|
2011-02-08 06:29:27 +00:00
|
|
|
epr |= EPR_STAT_TX_NAK;
|
|
|
|
|
2012-06-16 06:22:39 +00:00
|
|
|
/* OUT endpoint initially in NAK mode.*/
|
|
|
|
if (epcp->out_cb != NULL)
|
|
|
|
epr |= EPR_STAT_RX_NAK;
|
2011-02-08 06:29:27 +00:00
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
/* EPxR register setup.*/
|
2011-02-08 06:29:27 +00:00
|
|
|
EPR_SET(ep, epr | ep);
|
|
|
|
EPR_TOGGLE(ep, epr);
|
2011-01-30 19:18:26 +00:00
|
|
|
|
|
|
|
/* Endpoint size and address initialization.*/
|
2011-02-06 09:51:16 +00:00
|
|
|
if (epcp->out_maxsize > 62)
|
|
|
|
nblocks = (((((epcp->out_maxsize - 1) | 0x1f) + 1) / 32) << 10) |
|
2011-02-05 09:27:20 +00:00
|
|
|
0x8000;
|
2011-01-30 19:18:26 +00:00
|
|
|
else
|
2011-02-06 09:51:16 +00:00
|
|
|
nblocks = ((((epcp->out_maxsize - 1) | 1) + 1) / 2) << 10;
|
2011-01-30 19:18:26 +00:00
|
|
|
dp = USB_GET_DESCRIPTOR(ep);
|
2011-10-30 07:45:46 +00:00
|
|
|
dp->TXCOUNT0 = 0;
|
|
|
|
dp->RXCOUNT0 = nblocks;
|
2012-06-16 14:08:20 +00:00
|
|
|
dp->TXADDR0 = usb_pm_alloc(usbp, epcp->in_maxsize);
|
|
|
|
dp->RXADDR0 = usb_pm_alloc(usbp, epcp->out_maxsize);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disables all the active endpoints except the endpoint zero.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_disable_endpoints(USBDriver *usbp) {
|
|
|
|
unsigned i;
|
|
|
|
|
2011-02-15 09:16:17 +00:00
|
|
|
/* Resets the packet memory allocator.*/
|
2012-06-16 14:08:20 +00:00
|
|
|
usb_pm_reset(usbp);
|
2011-02-15 09:16:17 +00:00
|
|
|
|
|
|
|
/* Disabling all endpoints.*/
|
2011-01-30 19:18:26 +00:00
|
|
|
for (i = 1; i <= USB_ENDOPOINTS_NUMBER; i++) {
|
|
|
|
EPR_TOGGLE(i, 0);
|
|
|
|
EPR_SET(i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-06 09:51:16 +00:00
|
|
|
* @brief Returns the status of an OUT endpoint.
|
2011-01-30 19:18:26 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
2011-02-28 18:44:46 +00:00
|
|
|
* @return The endpoint status.
|
|
|
|
* @retval EP_STATUS_DISABLED The endpoint is not active.
|
|
|
|
* @retval EP_STATUS_STALLED The endpoint is stalled.
|
|
|
|
* @retval EP_STATUS_ACTIVE The endpoint is active.
|
2011-01-30 19:18:26 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2011-02-06 09:51:16 +00:00
|
|
|
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep) {
|
2011-01-30 19:18:26 +00:00
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
(void)usbp;
|
2011-02-06 09:51:16 +00:00
|
|
|
switch (STM32_USB->EPR[ep] & EPR_STAT_RX_MASK) {
|
|
|
|
case EPR_STAT_RX_DIS:
|
2011-01-30 19:18:26 +00:00
|
|
|
return EP_STATUS_DISABLED;
|
2011-02-06 09:51:16 +00:00
|
|
|
case EPR_STAT_RX_STALL:
|
2011-01-30 19:18:26 +00:00
|
|
|
return EP_STATUS_STALLED;
|
|
|
|
default:
|
|
|
|
return EP_STATUS_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-06 09:51:16 +00:00
|
|
|
* @brief Returns the status of an IN endpoint.
|
2011-01-30 19:18:26 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
2011-02-28 18:44:46 +00:00
|
|
|
* @return The endpoint status.
|
|
|
|
* @retval EP_STATUS_DISABLED The endpoint is not active.
|
|
|
|
* @retval EP_STATUS_STALLED The endpoint is stalled.
|
|
|
|
* @retval EP_STATUS_ACTIVE The endpoint is active.
|
2011-01-30 19:18:26 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2011-02-06 09:51:16 +00:00
|
|
|
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep) {
|
2011-01-30 19:18:26 +00:00
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
(void)usbp;
|
2011-02-06 09:51:16 +00:00
|
|
|
switch (STM32_USB->EPR[ep] & EPR_STAT_TX_MASK) {
|
|
|
|
case EPR_STAT_TX_DIS:
|
2011-01-30 19:18:26 +00:00
|
|
|
return EP_STATUS_DISABLED;
|
2011-02-06 09:51:16 +00:00
|
|
|
case EPR_STAT_TX_STALL:
|
2011-01-30 19:18:26 +00:00
|
|
|
return EP_STATUS_STALLED;
|
|
|
|
default:
|
|
|
|
return EP_STATUS_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-10 18:54:58 +00:00
|
|
|
/**
|
|
|
|
* @brief Reads a setup packet from the dedicated packet buffer.
|
|
|
|
* @details This function must be invoked in the context of the @p setup_cb
|
|
|
|
* callback in order to read the received setup packet.
|
|
|
|
* @pre In order to use this function the endpoint must have been
|
|
|
|
* initialized as a control endpoint.
|
|
|
|
* @post The endpoint is ready to accept another packet.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
* @param[out] buf buffer where to copy the packet data
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
|
|
|
|
uint32_t *pmap;
|
|
|
|
stm32_usb_descriptor_t *udp;
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
(void)usbp;
|
|
|
|
udp = USB_GET_DESCRIPTOR(ep);
|
2011-11-03 18:06:39 +00:00
|
|
|
pmap = USB_ADDR2PTR(udp->RXADDR0);
|
2011-03-10 18:54:58 +00:00
|
|
|
for (n = 0; n < 4; n++) {
|
|
|
|
*(uint16_t *)buf = (uint16_t)*pmap++;
|
|
|
|
buf += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:36:49 +00:00
|
|
|
/**
|
2012-06-16 06:22:39 +00:00
|
|
|
* @brief Prepares for a receive operation.
|
2011-02-09 16:36:49 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2012-06-17 07:49:08 +00:00
|
|
|
void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) {
|
2012-06-16 06:22:39 +00:00
|
|
|
USBOutEndpointState *osp = usbp->epc[ep]->out_state;
|
2011-02-09 16:36:49 +00:00
|
|
|
|
2012-06-17 07:49:08 +00:00
|
|
|
/* Transfer initialization.*/
|
|
|
|
if (osp->rxsize == 0) /* Special case for zero sized packets.*/
|
|
|
|
osp->rxpkts = 1;
|
|
|
|
else
|
|
|
|
osp->rxpkts = (uint16_t)((osp->rxsize + usbp->epc[ep]->out_maxsize - 1) /
|
|
|
|
usbp->epc[ep]->out_maxsize);
|
2011-02-09 16:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-16 06:22:39 +00:00
|
|
|
* @brief Prepares for a transmit operation.
|
2011-02-09 16:36:49 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
2012-06-16 06:22:39 +00:00
|
|
|
* @param[in] buf buffer where to fetch the data to be transmitted
|
|
|
|
* @param[in] n maximum number of bytes to copy
|
2011-02-09 16:36:49 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2012-06-17 07:49:08 +00:00
|
|
|
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
|
|
|
|
size_t n;
|
2011-02-14 19:37:40 +00:00
|
|
|
USBInEndpointState *isp = usbp->epc[ep]->in_state;
|
2011-02-06 09:51:16 +00:00
|
|
|
|
2012-06-17 05:04:51 +00:00
|
|
|
/* Transfer initialization.*/
|
2012-06-17 07:49:08 +00:00
|
|
|
n = isp->txsize;
|
2012-06-17 05:04:51 +00:00
|
|
|
if (n > (size_t)usbp->epc[ep]->in_maxsize)
|
|
|
|
n = (size_t)usbp->epc[ep]->in_maxsize;
|
2012-06-17 06:53:49 +00:00
|
|
|
|
2012-06-17 07:49:08 +00:00
|
|
|
if (isp->txqueued)
|
|
|
|
usb_packet_write_from_queue(USB_GET_DESCRIPTOR(ep),
|
|
|
|
isp->mode.queue.txqueue, n);
|
|
|
|
else
|
|
|
|
usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
|
|
|
|
isp->mode.linear.txbuf, n);
|
2011-10-23 11:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Starts a receive operation on an OUT endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_start_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2012-06-17 06:53:49 +00:00
|
|
|
(void)usbp;
|
2011-10-23 11:39:45 +00:00
|
|
|
|
|
|
|
EPR_SET_STAT_RX(ep, EPR_STAT_RX_VALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Starts a transmit operation on an IN endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2012-06-17 06:53:49 +00:00
|
|
|
(void)usbp;
|
2011-10-23 11:39:45 +00:00
|
|
|
|
|
|
|
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an OUT endpoint in the stalled state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
(void)usbp;
|
2011-10-23 11:39:45 +00:00
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
EPR_SET_STAT_RX(ep, EPR_STAT_RX_STALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-06 09:51:16 +00:00
|
|
|
* @brief Brings an IN endpoint in the stalled state.
|
2011-01-30 19:18:26 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2011-02-06 09:51:16 +00:00
|
|
|
void usb_lld_stall_in(USBDriver *usbp, usbep_t ep) {
|
2011-01-30 19:18:26 +00:00
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
(void)usbp;
|
2011-10-30 20:57:37 +00:00
|
|
|
|
2011-02-06 09:51:16 +00:00
|
|
|
EPR_SET_STAT_TX(ep, EPR_STAT_TX_STALL);
|
2011-01-30 19:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an OUT endpoint in the active state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_clear_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2011-02-05 09:27:20 +00:00
|
|
|
(void)usbp;
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
/* Makes sure to not put to NAK an endpoint that is already
|
|
|
|
transferring.*/
|
|
|
|
if ((STM32_USB->EPR[ep] & EPR_STAT_RX_MASK) != EPR_STAT_RX_VALID)
|
|
|
|
EPR_SET_STAT_TX(ep, EPR_STAT_RX_NAK);
|
|
|
|
}
|
|
|
|
|
2011-02-06 09:51:16 +00:00
|
|
|
/**
|
|
|
|
* @brief Brings an IN endpoint in the active state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_clear_in(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
|
|
|
(void)usbp;
|
|
|
|
|
|
|
|
/* Makes sure to not put to NAK an endpoint that is already
|
|
|
|
transferring.*/
|
|
|
|
if ((STM32_USB->EPR[ep] & EPR_STAT_TX_MASK) != EPR_STAT_TX_VALID)
|
|
|
|
EPR_SET_STAT_TX(ep, EPR_STAT_TX_NAK);
|
|
|
|
}
|
|
|
|
|
2011-01-30 19:18:26 +00:00
|
|
|
#endif /* HAL_USE_USB */
|
|
|
|
|
|
|
|
/** @} */
|