Split from: FatFs AtMega328P

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 i have same problem with you if i use f_open prgoram gives "id returned 1 exit status " error but i couldn't fix it. you said  you fixed this error but i don't understand.can you explain how to do it

emre

Last Edited: Sat. Oct 5, 2019 - 03:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look at the build output. The "LD returned 1" is only the final consequence of a link error. You need to look above to see what the actual link error was. I'm guessing "undefined reference". This all proves why the "Error List" in the IDE is worse than useless!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kayanemre wrote:
 i have same problem

No, you don't!

 

You have a build error - the rest of the thread is about code which built successfully, but didn't then work on the target work.

 

you said  you fixed this error but i don't understand

Because you have an entirely different problem, that fix will not help you at all!

 

clawson wrote:
I'm guessing "undefined reference".

 

Which is generally because you've included the header files, but not the 'C' source (or pre-built binary) files.

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sat. Oct 5, 2019 - 01:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have changed lots of thing header files but i couldn't find the where the error exactly and error list only says  "ld returned 1 exit status"

here is my project. 
 

Attachment(s): 

emre

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kayanemre wrote:
error list only says  "ld returned 1 exit status"

and that is exactly why

clawson wrote:
 the "Error List" in the IDE is worse than useless!

 

So see https://www.avrfreaks.net/commen... for how to get to the 'Output' window ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sat. Oct 5, 2019 - 09:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
------ Build started: Project: SDREAD, Configuration: Debug AVR ------

collect2.exe(0,0): error: ld returned 1 exit status
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

this is my output window ,it only shows this results unlike the link you posted(it is showing building process unlike mine).

emre

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do a "rebuild solution" and post the entire Output

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Do a "rebuild solution" and post the entire Output

 

i tried it also

 

------ Rebuild All started: Project: SDREAD, Configuration: Debug AVR ------
------ Rebuild All started: Project: SDREAD, Configuration: Debug AVR ------
collect2.exe(0,0): error: ld returned 1 exit status
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

 

emre

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have change some building settings so now i can read real problem from error list . problem is as you said  undefined reference .the error is undefined reference to `get_fattime' .   

emre

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You are supposed to implement that. It's so that if you have a real time clock you can pass back the real date and time so files are stamped correctly. If you don't have an RTC implement a get_fattime that always returns a fixed date/time line 12:00 01/01/2019 or something.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


clawson wrote:
You are supposed to implement that

 

The description - ie, what you need to implement -  is here:  http://elm-chan.org/fsw/ff/doc/fattime.html

 

Full documentation of FatFs: http://elm-chan.org/fsw/ff/00index_e.html

In particular, see:

 

Also look at the 'Resources' section at the bottom of the page:

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Also, when you download ffsample.zip from the FatFs site the example given has a main.c that contains:

/*--------------------------------------------------------------------*/
/* User Provided Timer Function for FatFs module                      */
/*--------------------------------------------------------------------*/
/* This is a real time clock service to be called from FatFs module.  */
/* Any valid time must be returned even if the system does not        */
/* support a real time clock. This is not required when FatFs is      */
/* configured for FF_FS_READONLY or FF_FS_NORTC = 1.                  */
/*--------------------------------------------------------------------*/
DWORD get_fattime (void)
{
	RTC rtc;


	if (!RtcOk) return 0;

	/* Get local time */
	rtc_gettime(&rtc);

	/* Pack date and time into a DWORD variable */
	return	  ((DWORD)(rtc.year - 1980) << 25)
			| ((DWORD)rtc.month << 21)
			| ((DWORD)rtc.mday << 16)
			| ((DWORD)rtc.hour << 11)
			| ((DWORD)rtc.min << 5)
			| ((DWORD)rtc.sec >> 1);
}

You can basically just copy that into your own code. Of course you may not have an rtc_gettime() function in which case make it something like:

/*--------------------------------------------------------------------*/
/* User Provided Timer Function for FatFs module                      */
/*--------------------------------------------------------------------*/
/* This is a real time clock service to be called from FatFs module.  */
/* Any valid time must be returned even if the system does not        */
/* support a real time clock. This is not required when FatFs is      */
/* configured for FF_FS_READONLY or FF_FS_NORTC = 1.                  */
/*--------------------------------------------------------------------*/


DWORD get_fattime (void)
{
	RTC rtc;

    rtc.year = 2019;
    rtc.month = 10;
    rtc.mday = 7;
    rtc.hour = 9;
    rtc.min = 53;
    rtc.sec = 41;

	/* Pack date and time into a DWORD variable */
	return	  ((DWORD)(rtc.year - 1980) << 25)
			| ((DWORD)rtc.month << 21)
			| ((DWORD)rtc.mday << 16)
			| ((DWORD)rtc.hour << 11)
			| ((DWORD)rtc.min << 5)
			| ((DWORD)rtc.sec >> 1);
}

Which stamps the files as 7th October 2019 09:53:41.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you all ,now  i can read and write into sd card

FRESULT scan_files (
char* path        /* Start node to be scanned (***also used as work area***) */
)
{
	FRESULT res;
	DIR dir;
	UINT i;
	static FILINFO fno;

	res = f_opendir(&dir, path);                       /* Open the directory */
	if (res == FR_OK) {
		for (;;) {
			res = f_readdir(&dir, &fno);                   /* Read a directory item */
			if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
			if (fno.fattrib & AM_DIR) {                    /* It is a directory */
				i = strlen(path);
				sprintf(&path[i], "%s", fno.fname);
				res = scan_files(path);                    /* Enter the directory */
				if (res != FR_OK) break;
				path[i] = 0;
				} else {

						Serial_print(path);
						Serial_print(" / ");

						Serial_print(fno.fname);
						Serial_print("\n");                               /* It is a file. */
				printf("%s/%s\n", path, fno.fname);
			}
		}
		f_closedir(&dir);
	}

	return res;
}

int main (void)
{

	ioinit();		

	Serial_begin(9600);	

		FATFS fs; 		/* Filesystem object for each logical drive */
		FRESULT res;
		char buff[256];

		res = f_mount(&fs, "", 1);
		if (res == FR_OK) {
			strcpy(buff, "/");
			res = scan_files(buff);
		}

		return res;

		Serial_println("\n done :)");

	}

but  when i use scan_files()  function only shows three file from root although there are more than three files.it works fine any folder in root.

 

 

emre

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Do you have a debugger? I'd simply watch it one file at a time and see what the termination condition is.

 

BTW be careful with recursion - these micros don't have masses of RAM !