Hi, all.
I am developing an original USB protocol stack which works as a device with my own TMS320C6745 board. Thank you for much information from this community, my code well handles interrupts and receives host requests such as GET_DESCRIPTOR and SET_ADDRESS by reading FIFO0.
However, my code seems to fail sending information back to a host with FIFO0. The procedure is based on 2.7.1.1.3 of sprufm9h, that is, loading data to FIFO0, setting TXPKTRDY bit, and finally setting DATAEND bit (if need) in the USB EP0 interrupt routine. Altough TXPKTRDY would be cleared automatically according to sprufm9h, with my codes TXPKTRDY is not cleared. As results, host issues RESET because of timeout and the enumeration fails like showing "Unknown device (VID=0x0000, PID=0x0000)".
Could you advise me? I am suspecting that not only the interrupt routine, but also the initialization are wrong.
The whole code is available from here, and the key interrupt routine is USB0_OTG::handle_ep0() in usb0.cpp. The summary of the code is:
if(ep0_state == EP_TX){
Uint16 control_reg(usbRegs->EPCSR[0].TXCSR.PERI_CSR0);
if(control_reg & CSL_USB_OTG_PERI_CSR0_TXPKTRDY_MASK){return;}
Uint16 sent(min(ep0_rw_size, 0x40));
for(int i(0); i < sent / sizeof(Uint32); i++){
usbRegs->FIFO0 = *(Uint32 *)ep0_rw_buf; // type of ep0_rw_buf is Uint8*
ep0_rw_buf += sizeof(Uint32);
}
if(sent & sizeof(Uint16)){
usbRegs->FIFO0 = *(Uint16 *)ep0_rw_buf;
ep0_rw_buf += sizeof(Uint16);
}
if(sent & sizeof(Uint8)){
usbRegs->FIFO0 = *ep0_rw_buf;
ep0_rw_buf += sizeof(Uint8);
}
control_reg |= CSL_USB_OTG_PERI_CSR0_TXPKTRDY_MASK;
if((ep0_rw_size -= sent) == 0){
if(ep0_callback){(*ep0_callback)();} // Do something if callback
control_reg |= CSL_USB_OTG_PERI_CSR0_DATAEND_MASK;
ep0_state = EP_IDLE;
}
usbRegs->EPCSR[0].TXCSR.PERI_CSR0 = control_reg;
}
In addition, unfortunately, I cannot use TI's DSP/BIOS USB module, because my project requires whole source code is open.
Thanks