Nucleo stm32f746zg USB wave player

Dependencies:   mbed wave_player USBHost

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

main.cpp

Committer:
vsolonar
Date:
2018-04-19
Revision:
9:d0a3b4c7b261
Parent:
4:f8a5c8aa895a
Child:
10:c3614ed19126

File content as of revision 9:d0a3b4c7b261:

/*
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"

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];

// 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");

        while(1) {
        while(!msd.connect()) {
            pc.printf("Waiting for USB\r\n");
            wait_ms(500);
        }
            pc.printf("Flash mounted\r\n");    

            FILE * fp = fopen("/usb/test1.bin", "rb");
        
            if (fp != NULL) {
                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 {
                pc.printf("FILE == NULL\r\n");
            }
                    
            if (!msd.connected())
                break;
        }
}