wave player pwm & covox
Dependencies: wave_player_pwm_and_covox mbed USBHost
Diff: main.cpp
- Revision:
- 9:d0a3b4c7b261
- Parent:
- 4:f8a5c8aa895a
- Child:
- 10:c3614ed19126
--- a/main.cpp Thu Mar 14 14:23:42 2013 +0000 +++ b/main.cpp Thu Apr 19 13:31:58 2018 +0000 @@ -1,50 +1,73 @@ +/* +Big green ugly test. Free for use bla bla bla. Do not eat. +Tested on stm32f746zg +Results: 814 KB/s, to slow for my project. +No have idea how i can increase reading speed up to 4MB/s. +*/ + #include "mbed.h" #include "USBHostMSD.h" -DigitalOut led(LED1); +Serial pc(USBTX, USBRX, 115200); // tx, rx, baud rate to avoid terminal glitches + +// read block size +unsigned int bs = 65536; +// read memory buffer +char buff[65536]; -void msd_task(void const *) { +// Binary test file, 10MB size +unsigned long fsize=1024*1024*10; +// start time, end time, delta time +unsigned long time1, time2, time3; +// speed = fsize / time3 +float speed; + + +Timer t; + +int main() { + +// Mission clock on. +t.start(); USBHostMSD msd("usb"); - int i = 0; - - while(1) { - - // try to connect a MSD device + + while(1) { while(!msd.connect()) { - Thread::wait(500); + pc.printf("Waiting for USB\r\n"); + wait_ms(500); } - - // in a loop, append a file - // if the device is disconnected, we try to connect it again - while(1) { - - // append a file - FILE * fp = fopen("/usb/test1.txt", "a"); + pc.printf("Flash mounted\r\n"); + + FILE * fp = fopen("/usb/test1.bin", "rb"); if (fp != NULL) { - fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); - printf("Goodbye World!\r\n"); - fclose(fp); + pc.printf("File opened, reading...\r\n"); + + time1=t.read_ms(); + pc.printf("Start timer value = %u \r\n",time1); + + while(!feof(fp)) + { + fread(&buff,bs,1,fp); + } + + time2 = t.read_ms(); + pc.printf("End timer value = %u\r\n",time2); + + fclose(fp); + pc.printf("File closed\r\n"); + + time3 = time2 - time1; + speed = fsize / time3; + + pc.printf ("Time to read file %u speed KB/s = %f \r\n======================\r\n", time3, speed); + } else { - printf("FILE == NULL\r\n"); + pc.printf("FILE == NULL\r\n"); } - - Thread::wait(500); - - // if device disconnected, try to connect again + if (!msd.connected()) break; } - - } } - - -int main() { - Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); - while(1) { - led=!led; - Thread::wait(500); - } -} \ No newline at end of file