4 years, 10 months ago.

Very slow USB MSD trasfer rates using KL25Z

Hi everybody!

I'm doing a Camera (FIFO) to USB interface using the KL25Z as USB Host. For this task, i'm using this library based on the ARM USB stack. Such library handles all Format System abstraction (FAT32) and also makes use of the USB OTG port connected to the main Freescale CPU.

Import libraryF401RE-USBHost

Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

This project is done without RTOS. I'm able to create and access files successfully using common C methods. The problem arises when data is transferred to the USB drive.

To test the transfer speeds, i write dummy binary data from a buffer until i get a file size of 2MB. With my methodology, this takes approximately 2 and a half minutes. This, of course, is unacceptable for the application. I have tried different chunk sizes, none of them seems to change write speed.

    USBHostMSD msd("usb");
    if (!msd.connect()) {
        ledb = 1;
        ledr = 0;
        error("USB not found.\r\n");
    FILE* fp = fopen("/usb/prueba.bin", "ab+"); //open file

    if(fp) {
        printf("Writing 2MB dummy file...\r\n");
        blinker.attach(&blinkViolet, 0.1); //blinks to indicate writing

        char *dummyInfo = (char *)malloc(512 * sizeof(char)); //512 bytes is the sector size
        if(!dummyInfo) {
            ledb = ledg = 1;
            ledr = 0;
            error("Cannot allocate memory.\r\n");
        memset(dummyInfo, char(0b10101010), 512); //fill info with arbitrary data

        for(int i = 0; i<3907; i++) { //sector by sector (i have tried with bigger chunks, without success)
            fwrite(dummyInfo, sizeof(char), 512, fp); //write 2MB (aproxx)

        fclose(fp); //close file
        free(dummyInfo); //free memory
        blinker.detach(); //stop blinking
        printf("Done writing file\r\n");


Am i doing something wrong? Would be better if i use Codewarrior, an RTOS, or something different? Also thought about using compression, but i believe the CPU isn't powerful enough for DCT and all the JPEG black magic. FYI, I'm also using an RTC (Maxim)

Be the first to answer this question.