Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "usbhost_inc.h" 00003 00004 void print_clock() 00005 { 00006 int Fin = 12000000; // 12MHz XTAL 00007 00008 printf("PLL Registers:\r\n"); 00009 printf(" - PLL0STAT = 0x%08X\r\n", LPC_SC->PLL0STAT); 00010 printf(" - CLKCFG = 0x%08X\r\n", LPC_SC->CCLKCFG); 00011 printf(" - USBCLKCFG = 0x%08X\r\n", LPC_SC->USBCLKCFG); 00012 00013 int M = (LPC_SC->PLL0STAT & 0x7FFF) + 1; 00014 int N = ((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1; 00015 int CCLKDIV = LPC_SC->CCLKCFG + 1; 00016 int USBDIV = LPC_SC->USBCLKCFG + 1; 00017 00018 printf("Clock Variables:\r\n"); 00019 printf(" - Fin = %d\r\n", Fin); 00020 printf(" - M = %d\r\n", M); 00021 printf(" - N = %d\r\n", N); 00022 printf(" - CCLKDIV = %d\r\n", CCLKDIV); 00023 printf(" - USBCLKDIV = %d\r\n", USBDIV); 00024 00025 int Fcco = (2 * M * 12000000) / N; 00026 int CCLK = Fcco / CCLKDIV; 00027 00028 printf("Clock Results:\r\n"); 00029 printf(" - Fcco = %d\r\n", Fcco); 00030 printf(" - CCLK = %d\r\n", CCLK); 00031 printf(" - USB Clock = %d\r\n", Fcco / USBDIV); 00032 printf("System clock: %d\r\n", SystemCoreClock); 00033 } 00034 00035 /* 00036 ************************************************************************************************************** 00037 * COPYING A FILE 00038 * 00039 * Description: This function is used by the user to copy a file 00040 * 00041 * Arguments : None 00042 * 00043 * Returns : None 00044 * 00045 ************************************************************************************************************** 00046 */ 00047 00048 #define FILENAME_R "input.txt" 00049 #define FILENAME_W "output.txt" 00050 #define MAX_BUFFER_SIZE (4000) 00051 void Main_Copy (void) 00052 { 00053 USB_INT32S fdr; 00054 USB_INT32S fdw; 00055 USB_INT32U bytes_read; 00056 00057 00058 fdr = FILE_Open((char *)FILENAME_R, RDONLY); 00059 if (fdr > 0) { 00060 fdw = FILE_Open((char *)FILENAME_W, RDWR); 00061 if (fdw > 0) { 00062 PRINT_Log("Copying from %s to %s...\r\n", FILENAME_R, FILENAME_W); 00063 do { 00064 bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE); 00065 FILE_Write(fdw, UserBuffer, bytes_read); 00066 PRINT_Log("."); 00067 } while (bytes_read); 00068 PRINT_Log("\r\n"); 00069 FILE_Close(fdw); 00070 } else { 00071 PRINT_Log("Could not open file %s\r\n", FILENAME_W); 00072 return; 00073 } 00074 FILE_Close(fdr); 00075 PRINT_Log("Copy completed\r\n"); 00076 } else { 00077 PRINT_Log("Could not open file %s\r\n", FILENAME_R); 00078 return; 00079 } 00080 } 00081 00082 int main() 00083 { 00084 USB_INT32S rc; 00085 USB_INT32U numBlks, blkSize; 00086 USB_INT08U inquiryResult[INQUIRY_LENGTH]; 00087 00088 print_clock(); 00089 // UART_Init(115200); /* Initialize the serial port to view the log messages */ 00090 Host_Init(); /* Initialize the host controller */ 00091 rc = Host_EnumDev(); /* Enumerate the device connected */ 00092 if (rc == OK) { 00093 /* Initialize the mass storage and scsi interfaces */ 00094 rc = MS_Init( &blkSize, &numBlks, inquiryResult ); 00095 if (rc == OK) { 00096 rc = FAT_Init(); /* Initialize the FAT16 file system */ 00097 if (rc == OK) { 00098 Main_Copy(); /* Call the application */ 00099 } else { 00100 printf("ERROR %d in FAT_Init()\r\n", rc); 00101 while ( 1 ); 00102 // return (0); 00103 } 00104 printf("All OK in main()\r\n"); 00105 } else { 00106 printf("ERROR %d in MS_Init()\r\n", rc); 00107 while ( 1 ); 00108 // return (0); 00109 } 00110 } else { 00111 printf("ERROR %d in Host_EnumDev()\r\n", rc); 00112 while ( 1 ); 00113 // return (0); 00114 } 00115 while(1); 00116 }
Generated on Thu Jul 14 2022 00:28:57 by
1.7.2