update stm32 dcd stall control endpoint
This commit is contained in:
@@ -41,6 +41,7 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# flash target using on-board stlink
|
# flash target using on-board stlink or jlink
|
||||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||||
$(STM32Prog) --connect port=swd --write $< --go
|
$(STM32Prog) --connect port=swd --write $< --go
|
||||||
|
#JLinkExe
|
||||||
@@ -45,8 +45,6 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#define LED_STATE_ON 1
|
|
||||||
|
|
||||||
void board_init(void)
|
void board_init(void)
|
||||||
{
|
{
|
||||||
// Init the LED on PD14
|
// Init the LED on PD14
|
||||||
|
|||||||
@@ -310,36 +310,46 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||||
|
|
||||||
if(dir == TUSB_DIR_IN) {
|
if(dir == TUSB_DIR_IN) {
|
||||||
// Stop transmitting packets and NAK IN xfers.
|
// Only disable currently enabled non-control endpoint
|
||||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
|
if ( (epnum == 0) || !(in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPENA) ){
|
||||||
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_INEPNE) == 0);
|
in_ep[epnum].DIEPCTL |= (USB_OTG_DIEPCTL_SNAK | USB_OTG_DIEPCTL_STALL);
|
||||||
|
}else {
|
||||||
|
// Stop transmitting packets and NAK IN xfers.
|
||||||
|
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
|
||||||
|
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_INEPNE) == 0);
|
||||||
|
|
||||||
// Disable the endpoint. Note that both SNAK and STALL are set here.
|
// Disable the endpoint. Note that both SNAK and STALL are set here.
|
||||||
in_ep[epnum].DIEPCTL |= (USB_OTG_DIEPCTL_SNAK | USB_OTG_DIEPCTL_STALL | \
|
in_ep[epnum].DIEPCTL |= (USB_OTG_DIEPCTL_SNAK | USB_OTG_DIEPCTL_STALL | \
|
||||||
USB_OTG_DIEPCTL_EPDIS);
|
USB_OTG_DIEPCTL_EPDIS);
|
||||||
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_EPDISD_Msk) == 0);
|
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_EPDISD_Msk) == 0);
|
||||||
in_ep[epnum].DIEPINT = USB_OTG_DIEPINT_EPDISD;
|
in_ep[epnum].DIEPINT = USB_OTG_DIEPINT_EPDISD;
|
||||||
|
}
|
||||||
|
|
||||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||||
USB_OTG_FS->GRSTCTL |= ((epnum - 1) << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
USB_OTG_FS->GRSTCTL |= ((epnum - 1) << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
||||||
USB_OTG_FS->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
|
USB_OTG_FS->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
|
||||||
while((USB_OTG_FS->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
|
while((USB_OTG_FS->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
|
||||||
} else {
|
} else {
|
||||||
// Asserting GONAK is required to STALL an OUT endpoint.
|
// Only disable currently enabled non-control endpoint
|
||||||
// Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt
|
if ( (epnum == 0) || !(out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_EPENA) ){
|
||||||
// anyway, and it can't be cleared by user code. If this while loop never
|
out_ep[epnum].DOEPCTL |= USB_OTG_DIEPCTL_STALL;
|
||||||
// finishes, we have bigger problems than just the stack.
|
}else {
|
||||||
dev->DCTL |= USB_OTG_DCTL_SGONAK;
|
// Asserting GONAK is required to STALL an OUT endpoint.
|
||||||
while((USB_OTG_FS->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF_Msk) == 0);
|
// Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt
|
||||||
|
// anyway, and it can't be cleared by user code. If this while loop never
|
||||||
|
// finishes, we have bigger problems than just the stack.
|
||||||
|
dev->DCTL |= USB_OTG_DCTL_SGONAK;
|
||||||
|
while((USB_OTG_FS->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF_Msk) == 0);
|
||||||
|
|
||||||
// Ditto here- disable the endpoint. Note that only STALL and not SNAK
|
// Ditto here- disable the endpoint. Note that only STALL and not SNAK
|
||||||
// is set here.
|
// is set here.
|
||||||
out_ep[epnum].DOEPCTL |= (USB_OTG_DOEPCTL_STALL | USB_OTG_DOEPCTL_EPDIS);
|
out_ep[epnum].DOEPCTL |= (USB_OTG_DOEPCTL_STALL | USB_OTG_DOEPCTL_EPDIS);
|
||||||
while((out_ep[epnum].DOEPINT & USB_OTG_DOEPINT_EPDISD_Msk) == 0);
|
while((out_ep[epnum].DOEPINT & USB_OTG_DOEPINT_EPDISD_Msk) == 0);
|
||||||
out_ep[epnum].DOEPINT = USB_OTG_DOEPINT_EPDISD;
|
out_ep[epnum].DOEPINT = USB_OTG_DOEPINT_EPDISD;
|
||||||
|
|
||||||
// Allow other OUT endpoints to keep receiving.
|
// Allow other OUT endpoints to keep receiving.
|
||||||
dev->DCTL |= USB_OTG_DCTL_CGONAK;
|
dev->DCTL |= USB_OTG_DCTL_CGONAK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
/**************************************************************************/
|
|
||||||
/*!
|
|
||||||
@file hal_nrf5x.c
|
|
||||||
@author hathach
|
|
||||||
|
|
||||||
@section LICENSE
|
|
||||||
|
|
||||||
Software License Agreement (BSD License)
|
|
||||||
|
|
||||||
Copyright (c) 2018, hathach (tinyusb.org)
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. Neither the name of the copyright holders nor the
|
|
||||||
names of its contributors may be used to endorse or promote products
|
|
||||||
derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
|
||||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
|
||||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
This file is part of the tinyusb stack.
|
|
||||||
*/
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
#include "tusb_option.h"
|
|
||||||
|
|
||||||
#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_STM32F4
|
|
||||||
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
|
|
||||||
#include "tusb_hal.h"
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* TUSB HAL
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
bool tusb_hal_init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
tusb_hal_int_enable(0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tusb_hal_int_enable(uint8_t rhport)
|
|
||||||
{
|
|
||||||
(void) rhport;
|
|
||||||
NVIC_EnableIRQ(OTG_FS_IRQn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tusb_hal_int_disable(uint8_t rhport)
|
|
||||||
{
|
|
||||||
(void) rhport;
|
|
||||||
NVIC_DisableIRQ(OTG_FS_IRQn);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user