Some handover fixes
This commit is contained in:
parent
d54cff52e7
commit
b747a81b83
4 changed files with 23 additions and 5 deletions
1
.gdbinit
Normal file
1
.gdbinit
Normal file
|
|
@ -0,0 +1 @@
|
|||
target extended-remote localhost:3333
|
||||
|
|
@ -130,6 +130,7 @@ typedef struct {
|
|||
|
||||
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_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);
|
||||
uint32_t USB_ReadCore(void *pData, uint32_t length, uint32_t ep, PacketBuffer *cache);
|
||||
bool USB_Ok(void);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
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;
|
||||
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 */
|
||||
if (length >= (1 << (epdesc->DeviceDescBank[1].PCKSIZE.bit.SIZE + 3))) {
|
||||
assert(!handoverMode);
|
||||
/* Update the EP data address */
|
||||
data_address = (uint32_t)pData;
|
||||
// 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
|
||||
epdesc->DeviceDescBank[1].PCKSIZE.bit.AUTO_ZLP = ep_num == USB_EP_MSC_IN ? false : true;
|
||||
} else if (handoverMode) {
|
||||
data_address = (uint32_t)pData;
|
||||
} else {
|
||||
/* Copy to local buffer */
|
||||
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 */
|
||||
while (!(pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1)) {
|
||||
if (ep_num && !USB_Ok())
|
||||
return -1;
|
||||
// if (ep_num && !USB_Ok())
|
||||
// return -1;
|
||||
}
|
||||
|
||||
return length;
|
||||
|
|
|
|||
15
src/msc.c
15
src/msc.c
|
|
@ -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);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
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
|
||||
handover_flash(handover, handoverCache);
|
||||
// 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) {
|
||||
|
|
@ -761,7 +767,7 @@ static void process_handover(UF2_HandoverArgs *handover, PacketBuffer *handoverC
|
|||
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) {
|
||||
|
|
@ -769,7 +775,10 @@ static void handover(UF2_HandoverArgs *args) {
|
|||
// interrupt handlers from user space
|
||||
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
|
||||
args->ep_in &= 0xf;
|
||||
|
|
|
|||
Loading…
Reference in a new issue