1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

update for USB, USB High Speed software, for betatest, need some improvment. USBCV not passed, USB3.0 passed

This commit is contained in:
Jean-Christophe 2012-09-06 16:44:29 +02:00 committed by Cristian Maglie
parent 656b83b1a7
commit 22c828def0
4 changed files with 64 additions and 55 deletions

View File

@ -19,7 +19,7 @@
#ifdef CDC_ENABLED
#define CDC_SERIAL_BUFFER_SIZE 64
#define CDC_SERIAL_BUFFER_SIZE 512
/* For information purpose only since RTS is not always handled by the terminal application */
#define CDC_LINESTATE_DTR 0x01 // Data Terminal Ready
@ -45,7 +45,13 @@ typedef struct
uint8_t lineState;
} LineInfo;
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
static volatile LineInfo _usbLineInfo = {
57600, // dWDTERate
0x00, // bCharFormat
0x00, // bParityType
0x08, // bDataBits
0x00 // lineState
};
_Pragma("pack(1)")
static const CDCDescriptor _cdcInterface =
@ -62,8 +68,8 @@ static const CDCDescriptor _cdcInterface =
// CDC data interface
D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x200,0),
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x200,0)
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512,0),
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,512,0)
};
_Pragma("pack()")
@ -228,7 +234,6 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
if (r > 0)
{
USBD_Flush(CDC_TX);
return r;
} else
{

View File

@ -26,9 +26,9 @@ static const uint32_t EndPoints[] =
EP_TYPE_CONTROL,
#ifdef CDC_ENABLED
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
#endif
#ifdef HID_ENABLED
@ -153,45 +153,42 @@ uint32_t USBD_Recv(uint32_t ep)
}
// Space in send EP
uint32_t USBD_SendSpace(uint32_t ep)
{
LockEP lock(ep);
if (!UDD_ReadWriteAllowed(ep & 0xF))
return 0;
return 64 - UDD_FifoByteCount(ep & 0xF);
}
//uint32_t USBD_SendSpace(uint32_t ep)
//{
//LockEP lock(ep);
//// if (!UDD_ReadWriteAllowed(ep & 0xF))
////{
////printf("pb "); // UOTGHS->UOTGHS_DEVEPTISR[%d]=0x%X\n\r", ep, UOTGHS->UOTGHS_DEVEPTISR[ep]);
////return 0;
////}
//if(ep==0) return 64 - UDD_FifoByteCount(ep & 0xF); // EP0_SIZE jcb
//else return 512 - UDD_FifoByteCount(ep & 0xF); // EPX_SIZE jcb
//}
// Blocking Send of data to an endpoint
uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
{
if (!_usbConfiguration)
return -1;
uint32_t n;
int r = len;
const uint8_t* data = (const uint8_t*)d;
uint8_t timeout = 250; // 250ms timeout on send? TODO
if (!_usbConfiguration)
{
printf("pb conf\n\r");
return -1;
}
while (len)
{
uint8_t n = USBD_SendSpace(ep);
if (n == 0)
{
if (!(--timeout))
return -1;
delay(1);
continue;
}
if(ep==0) n= EP0_SIZE;
else n = EPX_SIZE;
if (n > len)
n = len;
len -= n;
UDD_Send(ep & 0xF, data, n);
//if (!UDD_ReadWriteAllowed(ep & 0xF) || ((len == 0) && (ep & TRANSFER_RELEASE))){ // Release full buffer
//UDD_ReleaseTX(ep & 0xF);
//}
}
}
//TXLED1; // light the TX LED
//TxLEDPulse = TX_RX_LED_PULSE_MS;
return r;
@ -345,15 +342,24 @@ static bool USBD_SendDescriptor(Setup& setup)
else if (USB_STRING_DESCRIPTOR_TYPE == t)
{
TRACE_CORE(puts("=> USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n");)
if (setup.wValueL == 0)
if (setup.wValueL == 0) {
desc_addr = (const uint8_t*)&STRING_LANGUAGE;
else if (setup.wValueL == IPRODUCT)
printf("St1=%d\n\r", *desc_addr);
}
else if (setup.wValueL == IPRODUCT) {
desc_addr = (const uint8_t*)&STRING_IPRODUCT;
else if (setup.wValueL == IMANUFACTURER)
printf("St2=%d\n\r", *desc_addr);
}
else if (setup.wValueL == IMANUFACTURER) {
desc_addr = (const uint8_t*)&STRING_IMANUFACTURER;
printf("St3=%d\n\r", *desc_addr);
}
else {
return false;
}
if( *desc_addr > setup.wLength ) {
desc_length = setup.wLength;
}
}
else if (USB_DEVICE_QUALIFIER == t)
{
@ -386,10 +392,13 @@ static bool USBD_SendDescriptor(Setup& setup)
return true;
}
//unsigned int iii=0;
// Endpoint 0 interrupt
static void USB_ISR(void)
{
// End of Reset
// printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb
// if( iii++ > 1500 ) while(1); // jcb
// End of bus reset
if (Is_udd_reset())
{
TRACE_CORE(printf(">>> End of Reset\r\n");)
@ -422,14 +431,13 @@ static void USB_ISR(void)
if (Is_udd_sof())
{
udd_ack_sof();
// USBD_Flush(CDC_TX);
// USBD_Flush(CDC_TX); // jcb
}
#endif
// EP 0 Interrupt
if (Is_udd_endpoint_interrupt(0))
if (Is_udd_endpoint_interrupt(0) )
{
if (!UDD_ReceivedSetupInt())
{
return;

View File

@ -34,7 +34,7 @@
#define MAX_ENDPOINTS 10
#define EP0 0
#define EP0_SIZE 64
#define EPX_SIZE 1024
#define EPX_SIZE 512
#define EP_SINGLE_64 (0x32UL) // EP0
#define EP_DOUBLE_64 (0x36UL) // Other endpoints
@ -116,7 +116,7 @@
//! Get maximal number of banks of endpoints
#define udd_get_endpoint_bank_max_nbr(ep) ((ep == 0) ? 1 : (( ep <= 2) ? 3 : 2))
//! Get maximal size of endpoint (3X, 1024/64)
#define udd_get_endpoint_size_max(ep) (((ep) == 0) ? 64 : 1024)
#define udd_get_endpoint_size_max(ep) (((ep) == 0) ? 64 : 512) // for bulk
//! Get DMA support of endpoints
#define Is_udd_endpoint_dma_supported(ep) ((((ep) >= 1) && ((ep) <= 6)) ? true : false)
//! Get High Band Width support of endpoints

View File

@ -115,7 +115,7 @@ void UDD_Attach(void)
// Enable USB line events
udd_enable_reset_interrupt();
udd_enable_sof_interrupt();
// udd_enable_sof_interrupt();
cpu_irq_restore(flags);
}
@ -139,6 +139,7 @@ void UDD_InitEP( uint32_t ul_ep_nb, uint32_t ul_ep_cfg )
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);)
while(1);
}
}
@ -156,6 +157,7 @@ void UDD_InitEndpoints(const uint32_t* eps_table, const uint32_t ul_eps_table_si
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);)
while(1);
}
}
}
@ -215,6 +217,8 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len)
TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (1): ep=%lu ul_send_fifo_ptr=%lu len=%lu\r\n", ep, ul_send_fifo_ptr[ep], len);)
while( UOTGHS_DEVEPTISR_TXINI != (UOTGHS->UOTGHS_DEVEPTISR[ep] & UOTGHS_DEVEPTISR_TXINI )) {}
if (ep == EP0)
{
if (ul_send_fifo_ptr[ep] + len > EP0_SIZE)
@ -222,34 +226,26 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len)
}
else
{
if (ul_send_fifo_ptr[ep] + len > EPX_SIZE)
len = EPX_SIZE - ul_send_fifo_ptr[ep];
ul_send_fifo_ptr[ep] = 0;
}
for (i = 0, ptr_dest += ul_send_fifo_ptr[ep]; i < len; ++i)
*ptr_dest++ = *ptr_src++;
ul_send_fifo_ptr[ep] += i;
if (ep == EP0)
{
TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (2): ep=%lu ptr_dest=%lu maxlen=%d\r\n", ep, ul_send_fifo_ptr[ep], EP0_SIZE);)
if (ul_send_fifo_ptr[ep] == EP0_SIZE)
{
UDD_ClearIN(); // Fifo is full, release this packet
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
}
UDD_ClearIN(); // Fifo is full, release this packet // UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_TXINIC;
}
}
else
{
if (ul_send_fifo_ptr[ep] == EPX_SIZE)
{
UDD_ClearIN(); // Fifo is full, release this packet
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
}
UOTGHS->UOTGHS_DEVEPTICR[ep] = UOTGHS_DEVEPTICR_TXINIC;
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
}
return len;
}