Some handover fixes

This commit is contained in:
Michal Moskal 2016-11-24 13:43:53 -06:00
parent d54cff52e7
commit b747a81b83
4 changed files with 23 additions and 5 deletions

1
.gdbinit Normal file
View file

@ -0,0 +1 @@
target extended-remote localhost:3333

View file

@ -130,6 +130,7 @@ typedef struct {
uint32_t USB_Read(void *pData, uint32_t length, uint32_t ep); uint32_t USB_Read(void *pData, uint32_t length, uint32_t ep);
uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num); uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num);
uint32_t USB_WriteCore(const void *pData, uint32_t length, uint8_t ep_num, bool handoverMode);
void USB_ReadBlocking(void *dst, uint32_t length, uint32_t ep, PacketBuffer *cache); void USB_ReadBlocking(void *dst, uint32_t length, uint32_t ep, PacketBuffer *cache);
uint32_t USB_ReadCore(void *pData, uint32_t length, uint32_t ep, PacketBuffer *cache); uint32_t USB_ReadCore(void *pData, uint32_t length, uint32_t ep, PacketBuffer *cache);
bool USB_Ok(void); bool USB_Ok(void);

View file

@ -443,6 +443,10 @@ void USB_ReadBlocking(void *dst, uint32_t length, uint32_t ep, PacketBuffer *cac
} }
uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num) { uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num) {
return USB_WriteCore(pData, length, ep_num, false);
}
uint32_t USB_WriteCore(const void *pData, uint32_t length, uint8_t ep_num, bool handoverMode) {
Usb *pUsb = pCdc.pUsb; Usb *pUsb = pCdc.pUsb;
uint32_t data_address; uint32_t data_address;
@ -450,6 +454,7 @@ uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num) {
/* Check for requirement for multi-packet or auto zlp */ /* Check for requirement for multi-packet or auto zlp */
if (length >= (1 << (epdesc->DeviceDescBank[1].PCKSIZE.bit.SIZE + 3))) { if (length >= (1 << (epdesc->DeviceDescBank[1].PCKSIZE.bit.SIZE + 3))) {
assert(!handoverMode);
/* Update the EP data address */ /* Update the EP data address */
data_address = (uint32_t)pData; data_address = (uint32_t)pData;
// data must be in RAM! // data must be in RAM!
@ -457,6 +462,8 @@ uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num) {
// always disable AUTO_ZLP on MSC channel, otherwise enable // always disable AUTO_ZLP on MSC channel, otherwise enable
epdesc->DeviceDescBank[1].PCKSIZE.bit.AUTO_ZLP = ep_num == USB_EP_MSC_IN ? false : true; epdesc->DeviceDescBank[1].PCKSIZE.bit.AUTO_ZLP = ep_num == USB_EP_MSC_IN ? false : true;
} else if (handoverMode) {
data_address = (uint32_t)pData;
} else { } else {
/* Copy to local buffer */ /* Copy to local buffer */
memcpy(endpointCache[ep_num].buf, pData, length); memcpy(endpointCache[ep_num].buf, pData, length);
@ -478,8 +485,8 @@ uint32_t USB_Write(const void *pData, uint32_t length, uint8_t ep_num) {
/* Wait for transfer to complete */ /* Wait for transfer to complete */
while (!(pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1)) { while (!(pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1)) {
if (ep_num && !USB_Ok()) // if (ep_num && !USB_Ok())
return -1; // return -1;
} }
return length; return length;

View file

@ -695,6 +695,12 @@ static void udi_msc_sbc_trans(bool b_read) {
USB_Write(block_buffer, UDI_MSC_BLOCK_SIZE, USB_EP_MSC_IN); USB_Write(block_buffer, UDI_MSC_BLOCK_SIZE, USB_EP_MSC_IN);
} else { } else {
USB_ReadBlocking(block_buffer, UDI_MSC_BLOCK_SIZE, USB_EP_MSC_OUT, 0); USB_ReadBlocking(block_buffer, UDI_MSC_BLOCK_SIZE, USB_EP_MSC_OUT, 0);
#if 0
check_uf2_handover(block_buffer, udi_msc_nb_block - i - 1, USB_EP_MSC_IN,
USB_EP_MSC_OUT, udi_msc_cbw.dCBWTag);
#endif
write_block(udi_msc_addr + i, block_buffer, false); write_block(udi_msc_addr + i, block_buffer, false);
} }
udi_msc_csw.dCSWDataResidue -= UDI_MSC_BLOCK_SIZE; udi_msc_csw.dCSWDataResidue -= UDI_MSC_BLOCK_SIZE;
@ -724,7 +730,7 @@ static void process_handover_initial(UF2_HandoverArgs *handover, PacketBuffer *h
// read-write remaining blocks // read-write remaining blocks
handover_flash(handover, handoverCache); handover_flash(handover, handoverCache);
// send USB response, as the user space isn't gonna do it // send USB response, as the user space isn't gonna do it
USB_Write((void *)&csw, sizeof(csw), handover->ep_in); USB_WriteCore((void *)&csw, sizeof(csw), handover->ep_in, true);
} }
static void process_handover(UF2_HandoverArgs *handover, PacketBuffer *handoverCache) { static void process_handover(UF2_HandoverArgs *handover, PacketBuffer *handoverCache) {
@ -761,7 +767,7 @@ static void process_handover(UF2_HandoverArgs *handover, PacketBuffer *handoverC
break; break;
} }
USB_Write((void *)&csw, sizeof(csw), handover->ep_in); USB_WriteCore((void *)&csw, sizeof(csw), handover->ep_in, true);
} }
static void handover(UF2_HandoverArgs *args) { static void handover(UF2_HandoverArgs *args) {
@ -769,7 +775,10 @@ static void handover(UF2_HandoverArgs *args) {
// interrupt handlers from user space // interrupt handlers from user space
SCB->VTOR = 0; SCB->VTOR = 0;
PacketBuffer cache; USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_MASK;
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_MASK;
PacketBuffer cache = {0};
// They may have 0x80 bit set // They may have 0x80 bit set
args->ep_in &= 0xf; args->ep_in &= 0xf;