这程序网上就有,就是给我的板子用的,我拿过来在我的板子上调试,但是接电脑上电脑一点反应都没有,擦了#include "main.h"//#include "lib_arm920t.h"AT91S_SVC_USBCTL usbEp0;AT91S_SVC_USBIN usbEpIn;AT91S_SVC_USBOUT usbEpOut;AT91S_SVC_USBIN usbEpInt;extern volatile unsigned char currentConfiguration;extern volatile unsigned char currentConnection;volatile unsigned char USBStat=0;volatile unsigned char USBFomerStat=0;//*----------------------------------------------------------------------------//* \fn AT91F_EnableICache//* \brief Enable I Cache//*----------------------------------------------------------------------------/*void AT91F_EnableICache(){ unsigned int ctl; ctl = AT91F_ARM_ReadControl(); ctl |= (1 << 12); AT91F_ARM_WriteControl(ctl);}*/void Delay(int i){while(i--);}void EUSB(){ AT91F_PIO_SetOutput( AT91C_BASE_PIOB,USBPUP) ; }void DUSB(){ AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,USBPUP) ; }//*----------------------------------------------------------------------------//* \fn AT91F_InitDrivers//* \brief This function initialize USART 1, the AIC and AT91S_SVC_USDRIVER driver//*----------------------------------------------------------------------------void AT91F_InitDrivers(){ // ============================= Init USB driver ============================= // Configure PMC AT91F_UDP_CfgPMC(); // Enable UDP peripheral AT91C_BASE_PMC->PMC_SCER |= AT91C_PMC_UDP; // Enable 48 MHz // Open DMA service for each endpoint AT91F_SVC_USBCTL_Open(&usbEp0, AT91C_BASE_UDP); usbEp0.DisptachSetup = AT91F_USB_DispatchRequest; AT91F_SVC_USBIN_Open(&usbEpIn, AT91C_BASE_UDP, 2, 0x40, 2); AT91F_SVC_USBOUT_Open(&usbEpOut, AT91C_BASE_UDP, 1, 0x40, 2); AT91F_SVC_USBIN_Open(&usbEpInt, AT91C_BASE_UDP, 3, 8, 1); // Configure AIC controller to handle USB interrupts AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, // AIC base address AT91C_ID_UDP, // System peripheral ID AT91C_AIC_PRIOR_HIGHEST, // Max priority AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, // Level sensitive AT91F_ASM_UDP_Handler ); // Enable Udp interrupt in AIC AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_UDP); }#define BUFFER_SIZE 1024char pBuffer[BUFFER_SIZE];volatile char flgUsbOpAchieved;void usbReceiveCallBack(AT91PS_SVC_USBOUT pUsbOut){ flgUsbOpAchieved = 1;}void usbSentCallBack(AT91PS_SVC_USBIN pUsbIn){ flgUsbOpAchieved = 1;}void LedRoll()//LED初始化及循环检验{ int i=1; AT91F_DBGU_Printk("LED巡检程序开始 \n\r"); while(i--) { AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED0 ) ; AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED1 ) ; AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED2 ) ; AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED3 ) ; AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED4 ) ; AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED5 ) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED0) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED1 ) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED2 ) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED3 ) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED4 ) ; Delay(500000); AT91F_PIO_ClearOutput( AT91C_BASE_PIOB,LED5 ) ; Delay(500000); } AT91F_DBGU_Printk("LED巡检程序结束 \n\r"); }//Check if usb is connected to host and if go to enable pupunsigned char ChkUSB(){ if(AT91F_PIO_IsInputSet(AT91C_BASE_PIOB,USBCNX)) { USBStat=1; if(USBFomerStat==0) //only change pup when cnx status is changed { AT91F_DBGU_Printk("-I- USB Connect Detected\n\r"); EUSB(); } USBFomerStat=USBStat; return 1; } else { USBStat=0; if(USBFomerStat==1) //only change pup when cnx status is changed { AT91F_DBGU_Printk("-I- USB Disconnect Detected\n\r"); DUSB(); } USBFomerStat=USBStat; return 0; } }int main(){ //char *chGet; //unsigned int messageSize, messageId = 0; //AT91F_EnableICache(); // Init USART 1 console driver AT91F_InitDrivers(); AT91F_DBGU_Printk("\n\n\r-I- ======================================-I\n\r"); AT91F_DBGU_Printk("-I- MUARM Main Program\n\r"); AT91F_DBGU_Printk("-I- Start Main Program Now? (Y/N)\n\r"); //while(!AT91F_DBGU_Get(chGet)||(*chGet!='Y')); AT91F_DBGU_Printk("\n\n\r-I- ======================================-I\n\r"); //InitPIOB(); LedRoll(); AT91F_DBGU_Printk("\n\n\r-I- ======================================\n\r-I- AT91RM9200 basic USB example\n\r-I- --------------------------------------\n\r-I- Please connect the board...\n\r-I- ======================================\n\r"); //Wait for host usb connected while(!ChkUSB()); // Wait for a SET_CONFIGURATION while (currentConfiguration != 1); // Wait for an acknowledged connection while (currentConnection != 3); // Send a welcome message... flgUsbOpAchieved = 0; usbEpIn.Write(&usbEpIn, "\n\n\r-I- USB serial emulation is active, all characters sent will be echo-ed\n\r", 77, usbSentCallBack); while(!flgUsbOpAchieved); while (1) { }}
顺便把我用的电路图和程序给上来,大家看看什么问题AT91PS_SVC_USBCTL AT91F_SVC_USBCTL_Open( AT91PS_SVC_USBCTL pSvcUdp, // \arg Pointer to an USBCTL service previously allocated AT91PS_UDP pUdp) // \arg Pointer to UDP registers{ pSvcUdp->Handler = AT91F_SVC_USBCTL_Handler; pSvcUdp->Read = AT91F_SVC_USBCTL_Read; pSvcUdp->Write = AT91F_SVC_USBCTL_Write; pSvcUdp->DisptachSetup = (AT91PF_SVC_USBCTL_DispatchSetup) 0; pSvcUdp->RWComplete = (AT91PF_SVC_USBCTL_RWComplete) 0; pSvcUdp->pBuffer = (char *) 0; pSvcUdp->bufferSize = 0; pSvcUdp->eot = 0; pSvcUdp->pUdp = pUdp; return pSvcUdp;}//*----------------------------------------------------------------------------//* \fn AT91F_SVC_USBCTL_DataIn//* \brief//*----------------------------------------------------------------------------static void AT91F_SVC_USBCTL_DataIn( AT91PS_SVC_USBCTL pSvcUdp, // \arg Pointer to an USBCTL service AT91PS_UDP pUdp) // \arg Pointer to UDP registers{ char *pBuffer; // If bufferSize == 0 Send a Zero length packet if (pSvcUdp->bufferSize == 0) AT91F_UDP_EpEndOfWr(pUdp, 0); // else initialize DPR else { pBuffer = pSvcUdp->pBuffer; if (pSvcUdp->bufferSize >= 8) { AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); pSvcUdp->bufferSize -= 8; } else while (pSvcUdp->bufferSize--) AT91F_UDP_EpWrite(pUdp, 0, *pBuffer++); pSvcUdp->pBuffer = pBuffer; AT91F_UDP_EpEndOfWr(pUdp, 0); } pSvcUdp->eot = !(pSvcUdp->bufferSize);}//*----------------------------------------------------------------------------//* \fn AT91F_SVC_USBCTL_DataOut//* \brief//*----------------------------------------------------------------------------__inline char AT91F_SVC_USBCTL_DataOut( AT91PS_SVC_USBCTL pSvcUdp, // \arg Pointer to an USBCTL service AT91PS_UDP pUdp, // \arg Pointer to UDP registers unsigned int epCsr) // \arg Value of the UDP_CSR[0] register{ unsigned int bytesReceived; char eor; // Detect end of Receive // Copy bytes received to the client buffer bytesReceived = (epCsr & AT91C_UDP_RXBYTECNT) >> 16; if (bytesReceived > pSvcUdp->bufferSize) bytesReceived = pSvcUdp->bufferSize; pSvcUdp->bufferSize -= bytesReceived; // Check the end of a Control OUT sequence: An incomplete packet stops the Data OUT sequence eor = (bytesReceived < 8); while (bytesReceived--) *(pSvcUdp->pBuffer)++ = AT91F_UDP_EpRead(pUdp, 0); AT91F_UDP_EpClear(pUdp, 0, (AT91C_UDP_RX_DATA_BK0)); return eor;}//*----------------------------------------------------------------------------//* \fn AT91F_SVC_USBCTL_Handler//* \brief//*----------------------------------------------------------------------------void AT91F_SVC_USBCTL_Handler( AT91PS_SVC_USBCTL pSvcUdp) // \arg Pointer to an USBCTL service{ AT91PS_UDP pUdp = pSvcUdp->pUdp; // Pointer to UDP registers unsigned int epCsr = AT91F_UDP_EpStatus(pUdp, 0); // Test if a SETUP packet has been received if (epCsr & AT91C_UDP_RXSETUP) { // Copy the setup packet pSvcUdp->pSetup[0] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[1] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[2] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[3] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[4] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[5] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[6] = AT91F_UDP_EpRead(pUdp, 0); pSvcUdp->pSetup[7] = AT91F_UDP_EpRead(pUdp, 0); // Set the DIR bit before clearing RXSETUP in Control IN sequence if (pSvcUdp->pSetup[0] & 0x80) AT91F_UDP_EpSet(pUdp, 0, AT91C_UDP_DIR); // Clear RXSETUP AT91F_UDP_EpClear(pUdp, 0, AT91C_UDP_RXSETUP); // Notify the dispatcher if (pSvcUdp->DisptachSetup) pSvcUdp->DisptachSetup(pSvcUdp); } // Test if the previous DATA IN packet is achieved else if (epCsr & AT91C_UDP_TXCOMP) { AT91F_UDP_EpClear(pUdp, 0, AT91C_UDP_TXCOMP); // test end of transmission if (pSvcUdp->eot && pSvcUdp->RWComplete) pSvcUdp->RWComplete(pSvcUdp); // else start new packet transfer else AT91F_SVC_USBCTL_DataIn(pSvcUdp, pUdp); } // test if any DATA OUT packet occured else if (epCsr & AT91C_UDP_RX_DATA_BK0) { // Test if this DATA OUT aborts a CONTROL IN sequence if (!(pSvcUdp->eot) && pSvcUdp->RWComplete) pSvcUdp->RWComplete(pSvcUdp); if (AT91F_SVC_USBCTL_DataOut(pSvcUdp, pUdp, epCsr) && pSvcUdp->RWComplete) pSvcUdp->RWComplete(pSvcUdp); } // Test if a STALL has been acknowledged... else if (epCsr & AT91C_UDP_ISOERROR) { // !!!!! Should be: AT91C_UDP_STALLSENT) { AT91F_UDP_EpClear(pUdp, 0, (AT91C_UDP_ISOERROR | AT91C_UDP_FORCESTALL)); }}//*----------------------------------------------------------------------------//* \fn AT91F_SVC_USBCTL_Write//* \brief//*----------------------------------------------------------------------------void AT91F_SVC_USBCTL_Write( AT91PS_SVC_USBCTL pSvcUdp, // \arg Pointer to an USBCTL service const char *pBuffer, // \arg Pointer to the client buffer to send unsigned int bufferSize, // \arg Client buffer size AT91PF_SVC_USBCTL_RWComplete Callback) // \arg Callback to invoke when buffer is Sent{ pSvcUdp->bufferSize = bufferSize; pSvcUdp->pBuffer = (char *)pBuffer; pSvcUdp->RWComplete = Callback; AT91F_SVC_USBCTL_DataIn(pSvcUdp, pSvcUdp->pUdp);}//*----------------------------------------------------------------------------//* \fn AT91F_SVC_USBCTL_Read//* \brief//*----------------------------------------------------------------------------void AT91F_SVC_USBCTL_Read( AT91PS_SVC_USBCTL pSvcUdp, // \arg Pointer to an USBCTL service char *pBuffer, // \arg Pointer to the client buffer to fill unsigned int bufferSize, // \arg Client buffer size AT91PF_SVC_USBCTL_RWComplete Callback) // \arg Callback to invoke when buffer is Full{ if ((bufferSize == 0) && (Callback)) { Callback(pSvcUdp); return; } pSvcUdp->bufferSize = bufferSize; pSvcUdp->pBuffer = pBuffer; pSvcUdp->RWComplete = Callback;}