Forum Rule: Always post complete source code & details to reproduce any issue!
Page 14 of 14 FirstFirst ... 4 12 13 14
Results 326 to 338 of 338

Thread: USBHost_t36 USB Mass Storage Driver Experiments

  1. #326
    Senior Member
    Join Date
    Aug 2017
    Posts
    125
    Quote Originally Posted by defragster View Post
    Thanks for seeing through making it usable!

    I am using the SanDisk Ultra - a 32GB micro SDHC card. Seems that is what PJRC.com noted as good on the SD related page - brand makes a difference - and some are 'misbranded' it seems at times. But one seems dead now - and I tossed another cheapo out sometime during T4 Beta as well? I have new ones of some brand - not sure these were new just ones I had around open with no current purpose from old phones or something. Other than that this was the stock example from current downloads. For HDD's and other testing I had played some with alternate buffer sizes - but this was fresh from github.

    @BOBILLIER - okay - simple FLASH cards work okay. But nothing HDD or even SSD would work without being on a powered HUB - so I wondered. And working from hub requires that 'HUB' code as noted then it can chain USB to get to a device on a HUB 'transparently'.

    TeensyThreads seems nice - I just looked at it for Teensy 4 and learned the loop() is just thread 0 - not sure if it is treated like all other threads. I left a question I didn't see an answer to about that - and I didn't get back to it after I looked a bit. I did suggest a perf 'cycles per thread' used tracker for debug that got put in - I hacked up a slightly diff implementation that made more sense to me but didn't see any reaction to that yet. Using that it looked like in the sample I wrote 10% of the T_4 was consumed in the thread switching - mainly because my threads did very little and then did a .yield() so the switch rate was extreme.

    @wwatson - seems I asked a while back about async calls to move data? THough not sure that would help TeensyThreads taskswitch any better unless it was running with DMA?
    @defragster

    I updated MassStorageHost.cpp and MassStorageDriver.cpp. There were some missing returns in a couple of functions hat the compiler was warning about. And of course I will be testing everything again to make sure I did not mess things up

    @wwatson - seems I asked a while back about async calls to move data? THough not sure that would help TeensyThreads taskswitch any better unless it was running with DMA?
    I can honestly tell you that I have no idea how to do this
    I know Paul I going to be working on USBHost so I probably will wait till then.

  2. #327
    Senior Member
    Join Date
    Aug 2017
    Posts
    125
    Quote Originally Posted by BOBILLIER View Post
    I just use one simple USB Key with 16GB directly connect to USB Port (this who place on the top of T3.6 circuit). But like I have powered T3.6 with only 5V, i lost some power through LP38691 circuit. Finally, i just obtain 4.6V for my USB key. I solve this by powering key directly through 5V power supply.

    Yes i'm using TeensyThreads library. the 10ms come from the information i have find in the read-me https://github.com/ftrias/TeensyThre...ster/readme.md in "Change" paragraph. I have don't test it to verify if 10ms is true.
    To solve my problem with write multi-threading, i have place the open-write-close action to USB Key in the loop() (not in one thread) and just before do it, i lock threading mechanism with one threading.stop() and a threading.start(-1) just after. Like i just save my data every second and like write to key (take between 16 and 40ms) , my threading process isn't very perturbed. And now, all seem working correctly.

    wwatson, thank for your library upgrade. But i have test it for my Unmount - mount action and i have always the same problem. I can unmount correctly , but if i try to mount my key again, nothing arrive and T3.6 stay lock. (i have test with and without unplug-plug key action). Do you plan to solve this ? Thanks
    I have checked this out. This is a function in FatFS. Hopefully today I will have time to work with it further. As far as MSC is concerned, it only deals with the USB drive connections to USBHost and communications with the drives.

  3. #328
    Senior Member
    Join Date
    Aug 2017
    Posts
    125
    @BOBILLIER - I figured out why the USB drive will not remount. Basically f_mount() calls the disk_initialize() function located in uSDFS library file sd_msc.ccp.

    Code:
    	int MSC_disk_initialize() 
    	{	myusb.begin();
    		return mscInit();
    	}
    This was causing the lockup with multiple calls to f_mount(). As a test I commented out mysub.begin() in disk_initialize() and added the following to your sketch:

    Code:
    #include <diskio.h>
    #include <ff.h>
    #include <ffconf.h>
    #include <uSDFS.h>
    #include <USBHost_t36.h>
    USBHub hub1(nullptr);
    USBHub hub2(nullptr);
    
    extern USBHost myusb;
    
    
    const char *Dev = "2:/"; // USB
    FRESULT rc; /* Result code */
    FATFS fatfs; /* File system object */
    FIL fil; /* File object */
    /* Stop with error message */
    void die(const char *text, FRESULT rc)
    { Serial.printf("%s: Failed with rc=%s.\r\n", text,FR_ERROR_STRING[rc]); while(1) asm("wfi"); }
    
    void setup() {
    
    while(!Serial);
    
    myusb.begin();
    
    // put your setup code here, to run once:
    if((rc = f_mount (&fatfs, Dev, 1))) die("Mount",rc); /* Mount/Unmount a logical drive */
    
    Serial.println("USB Mount OK");
    }
    void loop() {
    // put your main code here, to run repeatedly:
    while (Serial.available() > 0) {
    char Ordre = Serial.read();
    switch (Ordre) {
    case 'm':
    rc = f_mount (&fatfs, Dev, 1);
    Serial.println ("Mount USB");
    Serial.println(FR_ERROR_STRING[rc]);
    break;
    case 'u':
    rc = f_unmount(Dev);
    Serial.println ("Unmount USB");
    Serial.println(FR_ERROR_STRING[rc]);
    break;
    }
    }
    }
    @WMXZ - I am going to try figure a way around this. Any Ideas so I don't screw this up would be great

    EDIT 2:

    Added this to sd_msc.cpp disk_initialize():
    Code:
    	int MSC_disk_initialize() 
    	{	
                    	if(!deviceAvailable())
    			myusb.begin();
    		return mscInit();
    	}
    It seems to work. Going to do more testing
    Last edited by wwatson; 09-02-2019 at 07:54 PM. Reason: Clarification

  4. #329
    Junior Member
    Join Date
    Jun 2016
    Location
    Rennes France
    Posts
    18
    @wwatson . Thanks for your suggestion , but not working for me . The program stay lock at the first myusb.begin() in main.
    I have changed my USB key and tested again with my program, and now it work as expected. If you unmount, remove key, plug it again and mount, it's fine. But if you unmount key and directly mount it, program stay lock in mount process. To avoid that, i have add test in my program with
    Code:
    stat = disk_status (2);
    . This test return me value (stat) with value below:
    1)When i run program with one key, stat = 0 (correct)
    2)When i un_mount key, stat = 0 (??)((Why not stat = 1 = Disk not initialized)
    3)When i remove key , stat = 1 (Disk not initialized)(Why not stat = 2 = No disk)
    4)When i plug key , stat = 1 (Disk not initialized)
    5)When i mount key , stat = 0 (correct)

    For step 3, is-it like deviceAvailable() was always true and don't fall to false when i remove key.
    Finally step 2 and 3 don't return me one expected value (for me), but perhaps it's correct for you.
    Thanks for you help

  5. #330
    Senior Member
    Join Date
    Aug 2017
    Posts
    125
    Quote Originally Posted by BOBILLIER View Post
    @wwatson . Thanks for your suggestion , but not working for me . The program stay lock at the first myusb.begin() in main.
    I have changed my USB key and tested again with my program, and now it work as expected. If you unmount, remove key, plug it again and mount, it's fine. But if you unmount key and directly mount it, program stay lock in mount process. To avoid that, i have add test in my program with
    Code:
    stat = disk_status (2);
    . This test return me value (stat) with value below:
    1)When i run program with one key, stat = 0 (correct)
    2)When i un_mount key, stat = 0 (??)((Why not stat = 1 = Disk not initialized)
    3)When i remove key , stat = 1 (Disk not initialized)(Why not stat = 2 = No disk)
    4)When i plug key , stat = 1 (Disk not initialized)
    5)When i mount key , stat = 0 (correct)

    For step 3, is-it like deviceAvailable() was always true and don't fall to false when i remove key.
    Finally step 2 and 3 don't return me one expected value (for me), but perhaps it's correct for you.
    Thanks for you help
    You should not have unplug and plug the the USB key. Did you comment out the myusb.begin() in the uSDFS file sd_msc.cpp which is in the disk_initialize() function like this?

    Code:
    	int MSC_disk_initialize() 
    	{	
    		//myusb.begin();
    		return mscInit();
    	}
    The sd_msc.cpp file is in the uSDFS utility folder.

    Here is the output from your program on my T36 and t$:

    Code:
    USB Mount OK
    Unmount USB
    FR_OK
    Mount USB
    FR_OK
    I am working on a better fix for this.

  6. #331
    Junior Member
    Join Date
    Jun 2016
    Location
    Rennes France
    Posts
    18
    @wwatson.
    I have tested again with comment myusb.begin() in the uSDFS file sd_msc.cpp. if i do that, disk_status return 1 (not init) although key was plugged and main stay lock. I need add "extern USBHost myusb;" and "myusb.begin();" in my main for starting correctly, like indicate in your previous message. But like previously, i can unmounted correctly, but can't mount again without unplug-plug USB key. Perhaps, it's about key, who aren't working like your. Have you idea about bad disk_status value ?

  7. #332
    Junior Member
    Join Date
    Jun 2016
    Location
    Rennes France
    Posts
    18
    @wwatson
    I have just test with another key, and like you i can unmount-mount without unplug-plug key. It's perhaps my first key is USB3 and second is USB2 ...
    Your library seem very sensible to key model, because yesterday i have test with another USB2 key, but it's never start (never USB Mount OK).

  8. #333
    Senior Member
    Join Date
    Aug 2017
    Posts
    125
    Quote Originally Posted by BOBILLIER View Post
    @wwatson
    I have just test with another key, and like you i can unmount-mount without unplug-plug key. It's perhaps my first key is USB3 and second is USB2 ...
    Your library seem very sensible to key model, because yesterday i have test with another USB2 key, but it's never start (never USB Mount OK).
    Glad to here that you have one working. Make sure the USB keys are formatted at least with fat32 formatting.
    As far as I know, the T36 and T4 only support USB2 at this point.
    I have had some USB keys that flat would not work and some that take up to 20 seconds to initialize.

  9. #334
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,706
    Using MSC to test USB Host on T4 with Looger_RawWrite test and keep having to add this code:
    Code:
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    Would be handy to have that in github sources as HDD test requires external HUB.

    Tests were on Beta breakout board for T4 and they do work - USB Flash drive and Dongle holding SD and HDD and SSD - but hub needs that code each time.

  10. #335
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,333
    Quote Originally Posted by defragster View Post
    Using MSC to test USB Host on T4 with Looger_RawWrite test and keep having to add this code:
    Code:
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    Would be handy to have that in github sources as HDD test requires external HUB.

    Tests were on Beta breakout board for T4 and they do work - USB Flash drive and Dongle holding SD and HDD and SSD - but hub needs that code each time.
    Would be happy to include that, but which version are you using? in my uSDFS/examples/logger_RawWrite is no #include <USBHost_t36.h>
    Maybe I had it in the beginning, but now it is not there.
    Could you check the latest repo and make a PR?
    Thanks

  11. #336
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,706
    Thanks @WMXZ - Yes it is missing in the :: "...\libraries\uSDFS\examples\logger_RawWrite\logg er_RawWrite.ino"

    it works for me adding those lines after this as follows:
    Code:
    // use following lines for early definitions of multiple partition configuration in uSDFS.h
    #define MY_VOL_TO_PART
    #include "uSDFS.h"
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    Can't github just now - but if indicated can do that.

  12. #337
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,333
    Quote Originally Posted by defragster View Post
    Thanks @WMXZ - Yes it is missing in the :: "...\libraries\uSDFS\examples\logger_RawWrite\logg er_RawWrite.ino"
    updated the Github Repo

  13. #338
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,706
    Quote Originally Posted by WMXZ View Post
    updated the Github Repo
    Yes you did update: https://github.com/WMXZ-EU/uSDFS

    Downloaded ZIP - closed IDE - replaced libraries files copy and 'logger_RawWrite' works direct device or through HUB to with SD on USB Dongle, or HUB to SSD and HDD!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •