#include "tff.h"
#include "diskio.h"
#include <stdio.h>
#include "stm32f10x_lib.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "msd.h"

//constant time in this example
DWORD get_fattime ()
{
	return	((2006UL-1980) << 25)	      // Year = 2006
			| (2UL << 21)	      // Month = Feb
			| (9UL << 16)	      // Day = 9
			| (22U << 11)	      // Hour = 22
			| (30U << 5)	      // Min = 30
			| (0U >> 1)	      // Sec = 0
			;
}





int main (void)
{
  #ifdef DEBUG
  debug();
  #endif

  FATFS fs; 
  FIL F;
  FRESULT fres;
  UINT bytesWritten;
  const char filename[] = "test.txt";
  const char buf1[] = "Hello world!\nIf you can read this text, the filesystem module is working!\n";


  f_mount(0, &fs);

  fres = f_open (&F, filename, FA_READ | FA_WRITE | FA_CREATE_ALWAYS);
  //printf("status f_open: %d\n\r", fres); //status 0 = success
  f_sync (&F);

  fres = f_write (&F, buf1, sizeof (buf1) - 1, &bytesWritten);
  f_sync (&F);
  //printf("status f_write: %d\n\r", fres); //status 0 = success

  f_close (&F);
  f_mount(0, NULL);
  while(1);

}






















