This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: why fatfs is creating unknown/weird file in the sd card while copying and renaming the files ??

Part Number: TM4C1294NCPDT

hi 

I am working with fatfs filesystem and Tm4c1294ncpdt microcontroller. We had two sd cards on board on is primary and another is secondary.The external camera attached to primary sd card and mc is with secondary sd cards.The Mc do image processing output files save it in another directory and move the original file in another directory and renaming this file with a timestamp. Now after completing image processing, Mc will switch to another sd card to primary and camera to secondary and it is a continues processes.

Now my issues are that after 2-3 days running the filesystem start creating some weird files and also sometimes it is corrupting sd card sector/cluster. I do n't know why this happening. Kindly give me some suggestion to narrow down the issues.

Best regards

Dev

  • Hello Dev,

    Can you provide details on what example firmware was used to put together this application? Did you use the example from [Install Path]\TivaWare_C_Series-2.1.4.178\examples\boards\dk-tm4c129x\sd_card as a basis? I ask as I am not sure what to even suggest as possible areas to look for an issue without some sort of starting point to go from.
  • hi ralph

    Did you use the example from [Install Path]\TivaWare_C_Series-2.1.4.178\examples\boards\dk-tm4c129x\sd_card as a basis?

    yes , I used this as a reference but i updated the filesytem with R0.13a .In the above example the file system is R0.09b .According to it I changed some of functions and ffconf.h settings .

    I had one doubt that, if camera is having different filesystem then may be while writing image on the sd card it would corrupt the filesystem or sector /cluster.Since it is not happening everytimes and it is happening in 2-3days . so i am not able to debug the issues or can found some specifics functions/region where it is happening.

    Best regards
    Dev
  • Hello Dev,

    Thank you for the additional details, the problem itself is clearer now but unfortunately we don't have a lot of knowledge with FATFS or SD Card formatting, so I am not sure how helpful I'll be able to be.

    One thing I feel reasonably confident about is that an older file system on the Camera should not impact you using the latest on the MCU. The claim is that they are backward compatible with older versions: http://elm-chan.org/docs/fat_e.html

    Now then, as far as how to debug the issue itself, one way could be to come up with some form of stress test. You mention the issue occurs rarely, so I would look into how many images are processed between occurences, and then see if you can speed up that process to the point you can actually observe and debug (may require using hardware other than the camera?).

    Also it looks like they have full release notes for the updates form R0.09b to R0.13a: http://elm-chan.org/fsw/ff/updates.txt - You may want to review these and see if any functions are used by you and could be impacted by the updates. Perhaps the issue is occurring due a missed update to an API.

    Another debug idea would be to leverage UART if possible to add debug messages within the software. This only would work if the issue can occur while the device is plugged into the PC, but if so, you could print out UART debug logs for each step of the process and then see if you can identify what steps were missed/failed when the issue occurred. If you suspect you'll get a large amount of UART data from them, I'd recommend appending a timestamp as well then, so you can compare the UART output logs to the creation of files on your SD card.

    I hope one of these ideas has some use to you, sorry that we don't have further expertise to offer on the subject.

  • In addition to the (very) sound guidance vendor's Ralph has supplied - do consider:

    • it is unclear (at least to me) if it is the (same) SD card which is being corrupted.     Is it not wise to change to a different (known good) SD card - and repeat your observation?
    • what is the status of "SD Card" Removal & Reinsertion?     How often does this occur?     We've seen cases where (either) removal/insertion - performed at the wrong time - may cause such issues.
    • what is the status of Power to your board - is it there "throughout" the entirety of your "2-3 day corruption" occurrences?      Or - is the board freely (or regularly) powered/depowered?    Is the power supply (truly) adequate?    Have you measured under ALL operating conditions (and very recently)  - especially while "writing to the SD Card?
    • are any high-current or high noise (relays, actuators) or high frequency switching sources located in "near vicinity" of your board?
    • might (nearby) cell phone use - or other RF sources - possibly distress the SD card?
    • have you attempted to, "Copy but NOT rename the files?"     (indeed - almost useless - except I'm challenging/probing your "renaming" process.)
    • and - if you create a "reasonable number of  "known good" files - w/in each SD Card - and "MAKE NO ATTEMPT" to "Copy & Rename" - what then?     (such tests to confirm (your) identification of the issue's cause.)

    It proves wise to employ "beefy pcb traces to power the SD Card - and to reduce their length.     The signal line traces should also be direct - avoiding sharp bends.

    It often is useful to attach a scope probe to your board's power (specifically here - the SD Card's power) and trigger -  "If and only if" the voltage "wanders" (outside) either low or high bounds.     (i.e. create a "windowed analog comparator")

    When you are "open" to many potential causes - KISS (one measurable, systematic step at a time) proves supreme as "guide to your discovery & resolution..."

  • Hi cb1,

    *LIKE*! Thanks for sharing those excellent insights on further faults to consider, really appreciate your whole system view inputs (both here and on yesterday's motor/propulsion thread)!
  • Hi Ralph,

    How nice to receive your kind comments (especially that "LIKE")  - thank you - appreciated.

    As crack millennial staff (often) notes - "Enough smoke has been released in our facility!"      It appears (almost) reasonable - that we've "Learned something."     (maybe)

    We outsiders can (rarely) compete w/your group's, "Smarts & Inside Knowledge."     Yet - more often than not - an "overall system view" - advised by the desire to, "Avoid further smoke/fire" - may work to "Poster Advantage."

    Might it be noted that, "Varying Perspective" - does at times - offer real advantages... Thanks again...     (and thank you for those "Suggested Answer Hi-Lights - never would I, "Self-Award!")

  • moul_26feb.txthi,

    Thanks for the suggestion.

    have gone through all updates documents and update readme. According to it all changes I made but again I will look into it.

    Yes, I am using Uart to debug the issue and I am saving debug log. In that, there are no such failure conditions, Just some hang issues after 6-7 days.For that, I will enable watchdog timer.

    Regards

    Dev

  • hi cb1_mobile

    *Sd corruption is not static, either both sd are corrupted or any one of them.Both sd cards are of same type (class10 8Gb sd cards).

    *When MCU is free then, MCU go into hibernation.This will cut the power from sd cards connector also.

    *But mux switching the sd cards according to camera power pin, if a camera gets off we will switch sd cards. Insertion/removal of sd cards performed after removing power sources.

    *No there is no high-frequency switching sources.

    *But yes there is CDMA module but currently it not in use.

    *This is how I am copying and renaming.

    void SAVE_IMAGE(void)
    {
     uint8_t Folder[200] ={"/SENT/"};						//	Save file 
     in the sent folder 
    	//iFResult = f_mkdir ("/SENT"); 				//	Create a new directory 
    	sprintf((char *)Folder,"/SENT/%s",dest_name);
    	if(EPROM_cnfgSettings.img_rsz==0x33)
    	{
    	DEBUG_PRINT_TIME();
    	DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Renaming ");
    	DEBUG_PRINT((uint8_t *)FIL_NAME);
    	DEBUG_PRINT((uint8_t *)" to ");
    	DEBUG_PRINT((uint8_t *)Folder);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	iFResult = f_rename((char *)FIL_NAME,(char *)Folder);
    	
       if(iFResult!=FR_OK){
    	DEBUG_PRINT_TIME();
    	DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Failed!!So Renaming ");
    	DEBUG_PRINT((uint8_t *)FIL_NAME);
    	DEBUG_PRINT((uint8_t *)" to ");
    	DEBUG_PRINT((uint8_t *)dest_folder);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	iFResult = f_rename((char *)FIL_NAME,(char *)dest_folder);						
    	if(iFResult!=FR_OK){
    	DEBUG_PRINT_TIME();
    	DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Failed!!So deleting ");
    	DEBUG_PRINT((uint8_t *)FIL_NAME);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	iFResult = f_unlink ((char *)(FIL_NAME));	
    	}
       }
      }
    else  
    	{
    	iFResult = f_unlink ((char *)(FIL_NAME));	
    	DEBUG_PRINT_TIME();
           DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Renaming ");
    	DEBUG_PRINT((uint8_t *)original);
    	DEBUG_PRINT((uint8_t *)" to ");
    	DEBUG_PRINT((uint8_t *)Folder);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	iFResult = f_rename((char *)original,(char *)Folder);
    			
    	if(iFResult!=FR_OK){
    	DEBUG_PRINT_TIME();
    	DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Failed!!So Renaming ");
    	DEBUG_PRINT((uint8_t *)original);
    	DEBUG_PRINT((uint8_t *)" to ");
    	DEBUG_PRINT((uint8_t *)dest_folder);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	iFResult = f_rename((char *)original,(char *)dest_folder);
    	if(iFResult!=FR_OK){
    	DEBUG_PRINT_TIME();
    	DEBUG_PRINT((uint8_t *)"\t\t");
    	DEBUG_PRINT((uint8_t *)"Failed!!So deleting ");
    	DEBUG_PRINT((uint8_t *)original);
    	DEBUG_PRINT((uint8_t *)"\r\n");
    	f_unlink ((char *)(original));	
      }
    }			
    }
    ClearBuffer((char*)temp_FIL_NAME);	
    sprintf((char *)temp_FIL_NAME,"%s",FIL_NAME);
    SDCARD_MEMORY_CALCULATION((char*)"/SENT");  	// 	Check if the memory is full, if yes then images need to overwrite or delete oldest after 20%
    		if (Response[1]<= 0x14)
    		{
    		MEMORYFULL();																								//	If memory is full then process according to settings
    		ClearBuffer((char*)FIL_NAME);	
    		sprintf((char *)FIL_NAME,"%s",temp_FIL_NAME);
    		}
    }

  • Thank you - the "new detail" you've provided always assists our, "Drive toward the solution."

    This is the first time we've noted that "Hibernation" is in play.      There are (many) variables w/in your operation - some are "candidates for SD card disturbance" - it is difficult to know, "Where to begin" under such circumstance.     I suggest that you (temporarily) REMOVE "Hibernation" from the mix - and run the system EXACTLY as BEFORE - seeing if  "hibernation" proves "causal-nexus."     (It is a prime suspect - to my mind!)

    You have "self-diagnosed" the issue as being triggered by,  "Copying and Renaming the files" - while those files are resident upon two (attached) SD cards.     May I ask, "How you've come to such conclusion?"    After a reasonable "scan" of this building thread - I cannot find your explanation nor justification - for such conclusion.     And I think many would agree - (as the irony in your thread's Subject Line notes) - such simple, (Copy & Rename File) - causing SD card corruption - is a (much) Unexpected Occurrence!

    I quote now from your initial posting, "Now my issues are that after 2-3 days running the filesystem starts creating some weird files and also sometimes it is corrupting sd card sector/cluster."

    Does it not prove useful for you to (somewhat) "detail" - what occurs during this, "2-3 day interval" - prior to your, "Detection of (either) weird or corruption?      There's a clause w/in your quote which yields  uncertainty, "after 2-3 days running the filesystem" as written - this suggests that you've been, "Running your system - likely updating the SD cards."      Yet - if  punctuation is added, "after 2-3 days, - (then) running the filesystem!"     This 2nd interpretation of your writing suggests that your system "sat idle for 2-3 days" - and your issue only arose (or was noted) - after that 2-3 days passage."        Might you clarify - we believe this to be important.

    It remains unclear,  "How and when" you first note the issue?     I have asked that you create (only),  "known good files" - and store these on each of the two SD Cards - and then, "Leave the system to itself - for a similar - 2-3 day period."    And then - test for "weird/corruption!"      As "No files have been "Copied nor Renamed" - should corruption (now) occur - your diagnosis may have been proven to be, "incomplete."    (it still may arise - but OTHER issues have just been PROVEN to exist!)

    The final suggestions - w/in my prior "Diagnostic Listing" created in your behalf - appear (not) to have been adopted.     Yet those are the ones (restated here) which I believe to "go far" to, "Confirming an "Unlikely Diagnosis."

    As neither firm nor I employ your MCU - it would be greatly helpful if  Vendor Agents would be so good as to review your code - and judge its effectiveness.    I would note, "Adding Delays" between critical aspects of your "Copy & Rename" code - may prove helpful...    (even "solving!")

    One last point - you mentioned adding a "camera & SD Card" - are you (absolutely) certain that your board's power supply - proves adequate - especially when, "So many external devices are Drawing Current?"    (firm/I have seen such issues - caused by inadequate power (under special circumstances) - often enough to warn you to (really) "Test & Verify."     (hope/guess proves NOT acceptable...)

    it is suggested that you follow the later suggestions w/in the earlier Diagnostic list.     Variables need to be minimized (discarded, really) - and those suggestions  move nicely in that direction...

    IF - after truly, "Following and clearly reporting your findings" - and desired results are not achieved -  my firm has developed,  "Unique & highly advanced methods" to,  "Speed & Enhance the ARRIVAL of such Faults/Issues" - which surely  Aids/Propels diagnosis.     (I'm disallowed from presenting those here - you may contact us privately (via PM) this forum - if such is sought...)

    Your present situation is,  "HIGHLY ANTI-KISS" - and the, "EXCESSIVE NUMBER OF "NOOKS/CRANNIES" (especially the earlier identified "Hibernate") can be expected to (continue) to Over-Challenge!