mirror of https://github.com/ARMmbed/mbed-os.git
Improve LPC1768 USB stability
Make the following changes to improve stability: -When disconnecting set address to disabled to prevent nacks -Clear EP_SLOW one and only once for every interrupt where it is set_address -Disable and clear control endpoint interrupts when disconnectingfeature-hal-spec-usb-device
parent
7e0a3fd8ec
commit
b9f004fc87
|
@ -161,11 +161,11 @@ static uint8_t SIEgetDeviceStatus(void)
|
||||||
return SIEReadData(SIE_CMD_GET_DEVICE_STATUS);
|
return SIEReadData(SIE_CMD_GET_DEVICE_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SIEsetAddress(uint8_t address)
|
void SIEsetAddress(uint8_t address, bool enable=true)
|
||||||
{
|
{
|
||||||
// Write SIE device address register
|
// Write SIE device address register
|
||||||
SIECommand(SIE_CMD_SET_ADDRESS);
|
SIECommand(SIE_CMD_SET_ADDRESS);
|
||||||
SIEWriteData((address & 0x7f) | SIE_DSA_DEV_EN);
|
SIEWriteData((address & 0x7f) | (enable ? SIE_DSA_DEV_EN : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t SIEselectEndpoint(uint8_t endpoint)
|
static uint8_t SIEselectEndpoint(uint8_t endpoint)
|
||||||
|
@ -402,8 +402,8 @@ void USBPhyHw::init(USBPhyEvents *events)
|
||||||
|
|
||||||
// Enable interrupts for device events and EP0
|
// Enable interrupts for device events and EP0
|
||||||
LPC_USB->USBDevIntEn = EP_SLOW | DEV_STAT | FRAME;
|
LPC_USB->USBDevIntEn = EP_SLOW | DEV_STAT | FRAME;
|
||||||
enableEndpointEvent(EP0IN);
|
|
||||||
enableEndpointEvent(EP0OUT);
|
NVIC_EnableIRQ(USB_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBPhyHw::deinit()
|
void USBPhyHw::deinit()
|
||||||
|
@ -422,14 +422,28 @@ bool USBPhyHw::powered()
|
||||||
|
|
||||||
void USBPhyHw::connect(void)
|
void USBPhyHw::connect(void)
|
||||||
{
|
{
|
||||||
NVIC_EnableIRQ(USB_IRQn);
|
enableEndpointEvent(EP0IN);
|
||||||
|
enableEndpointEvent(EP0OUT);
|
||||||
|
|
||||||
// Connect USB device
|
// Connect USB device
|
||||||
SIEconnect();
|
SIEconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBPhyHw::disconnect(void)
|
void USBPhyHw::disconnect(void)
|
||||||
{
|
{
|
||||||
NVIC_DisableIRQ(USB_IRQn);
|
disableEndpointEvent(EP0IN);
|
||||||
|
disableEndpointEvent(EP0OUT);
|
||||||
|
|
||||||
|
if (LPC_USB->USBEpIntSt & EP(EP0IN)) {
|
||||||
|
selectEndpointClearInterrupt(EP0IN);
|
||||||
|
}
|
||||||
|
if (LPC_USB->USBEpIntSt & EP(EP0OUT)) {
|
||||||
|
selectEndpointClearInterrupt(EP0OUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn off USB nacking
|
||||||
|
SIEsetAddress(0, false);
|
||||||
|
|
||||||
// Disconnect USB device
|
// Disconnect USB device
|
||||||
SIEdisconnect();
|
SIEdisconnect();
|
||||||
}
|
}
|
||||||
|
@ -696,7 +710,6 @@ void USBPhyHw::process(void)
|
||||||
// case of OUT as SETUP clobbers the OUT data).
|
// case of OUT as SETUP clobbers the OUT data).
|
||||||
if (LPC_USB->USBEpIntSt & EP(EP0IN)) {
|
if (LPC_USB->USBEpIntSt & EP(EP0IN)) {
|
||||||
selectEndpointClearInterrupt(EP0IN);
|
selectEndpointClearInterrupt(EP0IN);
|
||||||
LPC_USB->USBDevIntClr = EP_SLOW;
|
|
||||||
events->ep0_in();
|
events->ep0_in();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,7 +721,6 @@ void USBPhyHw::process(void)
|
||||||
} else {
|
} else {
|
||||||
events->ep0_out();
|
events->ep0_out();
|
||||||
}
|
}
|
||||||
LPC_USB->USBDevIntClr = EP_SLOW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO - should probably process in the reverse order
|
//TODO - should probably process in the reverse order
|
||||||
|
@ -717,7 +729,6 @@ void USBPhyHw::process(void)
|
||||||
if (LPC_USB->USBEpIntSt & EP(endpoint)) {
|
if (LPC_USB->USBEpIntSt & EP(endpoint)) {
|
||||||
selectEndpointClearInterrupt(endpoint);
|
selectEndpointClearInterrupt(endpoint);
|
||||||
epComplete |= EP(endpoint);
|
epComplete |= EP(endpoint);
|
||||||
LPC_USB->USBDevIntClr = EP_SLOW;
|
|
||||||
if (IN_EP(endpoint)) {
|
if (IN_EP(endpoint)) {
|
||||||
events->in(endpoint);
|
events->in(endpoint);
|
||||||
} else {
|
} else {
|
||||||
|
@ -726,6 +737,8 @@ void USBPhyHw::process(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LPC_USB->USBDevIntClr = EP_SLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
NVIC_ClearPendingIRQ(USB_IRQn);
|
NVIC_ClearPendingIRQ(USB_IRQn);
|
||||||
|
|
Loading…
Reference in New Issue