Beispiel #1
0
void main(void)
{
    FATFS fs[2];         /* Work area (file system object) for logical drives */
    FIL fsrc;      /* file objects */
    BYTE buffer[1540];   /* file copy buffer */
    BYTE buffer2[100];
    FRESULT res;         /* FatFs function common result code */
    UINT br;             /* File read count */
    UINT bw;             /* File write count */

    /* Register work area for each volume (Always succeeds regardless of disk status) */
    f_mount(0, &fs[0]);
    f_mkfs(0, 0, 1024);

    /* Open source file on the drive 1 */
    res = f_open(&fsrc, "0:srcfile.dat", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);

    memset(buffer, 0xEE, sizeof(buffer));
    res = f_write(&fsrc, buffer, sizeof(buffer), &bw);    /* Read a chunk of src file */
    res = f_lseek(&fsrc, 1536);
    res = f_lseek(&fsrc, 1024);
    res = f_read(&fsrc, buffer2, 10, &br);

    /* Close open files */
    f_close(&fsrc);

    /* Unregister work area prior to discard it */
    f_mount(0, NULL);
}
Beispiel #2
0
int dfs_elm_mkfs(const char *device_name)
{
	BYTE drv;
	rt_device_t dev;
	FRESULT result;

	/* find device name */
	for (drv = 0; drv < _VOLUMES; drv ++)
	{
		dev = disk[drv];
		if (rt_strncmp(dev->parent.name, device_name, RT_NAME_MAX) == 0)
		{
			/* 1: no partition table */
			/* 0: auto selection of cluster size */
			result = f_mkfs(drv, 1, 0);
			if (result != FR_OK)
			{
				rt_kprintf("format error\n");
				return elm_result_to_dfs(result);
			}

			return DFS_STATUS_OK;
		}
	}

	/* can't find device driver */
	rt_kprintf("can not find device driver: %s\n", device_name);
	return -DFS_STATUS_EIO;
}
Beispiel #3
0
FRESULT DFATFS::fsmkfs(DFSVOL& dfsVol)
{
    FRESULT fr = FR_OK;
    DFSVOL * pDFSVolSave = _arDFSVOL[iMKFS];

    // unmount the drive, in case it is mounted
    fsunmount(szFatFsVols[iMKFS]);

    // delay mount the volume   
    if((fr = fsmount(dfsVol, szFatFsVols[iMKFS], 0)) != FR_OK)
    {
        return(fr);
    }

    // create the file system
    fr = f_mkfs(szFatFsVols[iMKFS], dfsVol._sfd, dfsVol._au);
    // unmount the drive
    fsunmount(szFatFsVols[iMKFS]);

    // restore the old mount
    if(pDFSVolSave != NULL)
    {
        fsmount(*pDFSVolSave, szFatFsVols[iMKFS], 0);
    }

    return(fr);
}
TEST(SDLog, log_topic_integration_test)
{
    // init logging
    log_init();
    log_handler_t stdout_log;
    log_handler_register(&stdout_log, LOG_LVL_WARNING, [](log_level_t lvl, const char *msg, size_t len)
        { std::cout << msg << std::endl;
        });

    // initialize messagebus
    msgbus_t bus;
    msgbus_init(&bus);
    msgbus_topic_t topic;
    test_t topic_buf;
    msgbus_topic_create(&topic, &bus, &test_type, &topic_buf, "/test");

    // create and mount filesystem
    FATFS fs;
    FRESULT mkfs_res = f_mkfs("", FM_ANY, 0, NULL, 0);
    CHECK_EQUAL(FR_OK, mkfs_res);
    FRESULT mount_res = f_mount(&fs, "", 1);
    CHECK_EQUAL(FR_OK, mount_res);
    FRESULT mkdir_res = f_mkdir("/log");
    CHECK_EQUAL(FR_OK, mkdir_res);

    // initialize logger & scheduler
    msgbus_scheduler_t sched;
    msgbus_scheduler_task_buffer_space_t buf[10];
    msgbus_scheduler_init(&sched, &bus, buf, 10);
    static struct logfile_s log_files[] = {
        {.topic="/test"},
    };
FRESULT low_level_format() {
    flash->eraseAll();
    FRESULT result = f_mkfs("", 1, sector_size);
    if (result==FR_OK && !is_formatted())
        result = FR_DISK_ERR;        
    return result;
}
void fatfs_init(unsigned char prio)
{
	FRESULT fret;
	
	raw_printf("FatFs init...\r\t\t\t\t");
	disk_initialize(0);
	fret = f_mount(&_FS, _T("0"), 0);
	if(FR_OK != fret)
	{
		RAW_ASSERT(0);
	}
	raw_printf("[OK]\n");
	
//	if( need_format(0) )
	if(1)
	{
		raw_printf("mkfs ...\r\t\t\t\t");
		fret = f_mkfs(_T("0:"), 0, 512);
		if(FR_OK != fret)
		{
			RAW_ASSERT(0);
		}
		raw_printf("[OK]\n");
	}
}
uint8_t flash_mount()
{
	FRESULT res;

	DataFlash_Init();

	//disk_initialize(1);

	res = f_mount(&Fatfs[0],"0:",0);
#if defined(_FS_DEBUG_)
    printf("\r\nf_mount:%d\r\n", res);
#endif

#if defined(F_SPI_FLASH)
    if(check_spiflash_flag() == 1)
        g_mkfs_done = 1;
    else
        g_mkfs_done = 0;

	res = f_mkfs("0:",0,512);

#if defined(_FS_DEBUG_)
    printf("f_mkfs:%d %d\r\n", res, g_mkfs_done);
#endif
    if(check_spiflash_flag() == 1)
    	save_spiflash_flag();
    g_mkfs_done = 1;
#endif

	return SPI_FLASHM;
}
Beispiel #8
0
static void make_flash_fs()
{
    FIL fp;
    UINT n;

    led_state(LED_RED, 1);

    if (f_mkfs("0:", 0, 0) != FR_OK) {
        __fatal_error("could not create LFS");
    }

    // create default main.py
    f_open(&fp, "main.py", FA_WRITE | FA_CREATE_ALWAYS);
    f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
    f_close(&fp);

    // create .inf driver file
    f_open(&fp, "pybcdc.inf", FA_WRITE | FA_CREATE_ALWAYS);
    f_write(&fp, fresh_pybcdc_inf, sizeof(fresh_pybcdc_inf) - 1 /* don't count null terminator */, &n);
    f_close(&fp);

    // create readme file
    f_open(&fp, "README.txt", FA_WRITE | FA_CREATE_ALWAYS);
    f_write(&fp, fresh_readme_txt, sizeof(fresh_readme_txt) - 1 /* don't count null terminator */, &n);
    f_close(&fp);

    led_state(LED_RED, 0);
}
Beispiel #9
0
void format_disk(
                 BYTE drv,			/* Logical drive number */
                 BYTE partition,		/* Partitioning rule 0:FDISK, 1:SFD */
                 WORD allocsize		/* Allocation unit size [bytes]={0} */
                 )
{
	FATFS fs;
//	FATFS *fls = &fs;
	uint8_t res;
	res = f_mount(0,&fs);
	if (res != FR_OK)
	{
		printf("\r\n挂载文件系统失败,错误代码: %u",res);
		return;
	}	
	printf("\r\n正在格式化磁盘,请稍候...");
	res = f_mkfs(drv,partition,allocsize);
	if (res == FR_OK)
	{
		printf("\r\n格式化成功...");
	}
	else
	{
		printf("\r\n格式化失败...");
		printf("\r\n错误代码: %u",res);
	}
	f_mount(0,NULL);
}
Beispiel #10
0
/* Low level I/O API test */
void fs_test()
{
    FATFS fs;      /* File system object (volume work area) */
    FIL fil;       /* File object */
    FRESULT res;   /* API result code */
    UINT bw;       /* Bytes written */

    /* Register work area (do not care about error) */
    res = f_mount(&fs, "/", 1);
    if (res != 0)
    {
        printk("Mount failed %d, try do mkfs.\n", res);
        /* Create FAT volume with default cluster size */
        res = f_mkfs("/", 0, 0);
        res = f_mount(&fs, "/", 1); //Remount
    }

    /* Create a file as new */
    res = f_open(&fil, "hello.txt", FA_CREATE_ALWAYS | FA_WRITE);
    
    if (res != 0)
        printk("Open failed %d\n", res);

    /* Write a message */
    f_write(&fil, "Hello, World!\r\n", 15, &bw);

    /* Close the file */
    f_close(&fil);

    /* Unregister work area */
    f_mount(0, "", 0);

    printk("Congratulatoins! You have pass fs_test!\n");
}
Beispiel #11
0
int FATFileSystem::format() {
    FRESULT res = f_mkfs(_fsid, 0, 512); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
    if (res) {
        debug_if(FFS_DBG, "f_mkfs() failed: %d\n", res);
        return -1;
    }
    return 0;
}
bool eraseSDCard()
{
    if(f_mkfs((TCHAR const*)SDPath, 0, 0) == FR_OK)
    {
        return true;
    }
    return false;
}
Beispiel #13
0
int main(void) {
	printf("Fatfs Hello world\n");

	/* Init virtio-blk session */
	virtio_blk_session(act_get_cap());

	FRESULT res;

	FATFS fs;
	if((res = f_mount(&fs, "", 1)) != FR_NO_FILESYSTEM) {
		printf("MT:%d\n", res);
		goto end;
	}

	if((res = f_mkfs("", 0, 0))) {
		printf("MK:%d\n", res);
		goto end;
	}

	FIL f;
	FIL * fp = &f;
	const char * path = "aaaa";
	if((res = f_open(fp, path, FA_WRITE | FA_CREATE_NEW))) {
		printf("OP:%d\n", res);
		goto end;
	}

	const char data[] = "test42";
	u_int count = 0;
	if((res = f_write(fp, data, 7, &count))) {
		printf("WR:%d\n", res);
	}

	if((res = f_close(fp))) {
		printf("CL:%d\n", res);
		goto end;
	}

	if((res = f_open(fp, path, FA_READ))) {
		printf("OPR:%d\n", res);
		goto end;
	}

	char read[0x10];
	if((res = f_read(fp, read, sizeof(data), &count))) {
		printf("RD:%d\n", res);
		goto end;
	}
	read[sizeof(data)] = '\0';

	printf("FatFS: -%s-\n", read);
	return 0;

	end:
	printf("FatFS self-test failed\n");

	return -1;
}
Beispiel #14
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 168 MHz */
  SystemClock_Config(); 
    
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /*##-1- LCD Initialization #################################################*/ 
  /* Initialize the LCD */
  BSP_LCD_Init();
 
  /* Enable the LCD */
  BSP_LCD_DisplayOn();

  /* Clear the LCD Background layer */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-2- Touch screen initialization ########################################*/
  Touchscreen_Calibration();
  BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
 
  /*##-3- Link the SD Card disk I/O driver ###################################*/
  if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0) 
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }
  
  /* Create a FAT file system (format) on the logical drive */
  f_mkfs((TCHAR const*)SDPath, 0, 0);
  
  /*##-4- Register the file system object to the FatFs module ################*/
  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }  
  
  /*##-5- Draw the menu ######################################################*/
  Draw_Menu();  

  /* Infinite loop */  
  while (1)
  { 
  /*##-6- Configure the touch screen and Get the position ####################*/    
    GetPosition();
  }
}
Beispiel #15
0
STATIC void mptask_init_sflash_filesystem (void) {
    FILINFO fno;
#if _USE_LFN
    fno.lfname = NULL;
    fno.lfsize = 0;
#endif

    // Initialise the local flash filesystem.
    // Create it if needed, and mount in on /flash.
    // try to mount the flash
    FRESULT res = f_mount(sflash_fatfs, "/flash", 1);
    if (res == FR_NO_FILESYSTEM) {
        // no filesystem, so create a fresh one
        res = f_mkfs("/flash", 1, 0);
        if (res == FR_OK) {
            // success creating fresh LFS
        } else {
            __fatal_error("failed to create /flash");
        }
        // create empty main.py
        mptask_create_main_py();
    } else if (res == FR_OK) {
        // mount sucessful
        if (FR_OK != f_stat("/flash/main.py", &fno)) {
            // create empty main.py
            mptask_create_main_py();
        }
    } else {
        __fatal_error("failed to create /flash");
    }

    // The current directory is used as the boot up directory.
    // It is set to the internal flash filesystem by default.
    f_chdrive("/flash");

    // Make sure we have a /flash/boot.py.  Create it if needed.
    res = f_stat("/flash/boot.py", &fno);
    if (res == FR_OK) {
        if (fno.fattrib & AM_DIR) {
            // exists as a directory
            // TODO handle this case
            // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
        } else {
            // exists as a file, good!
        }
    } else {
        // doesn't exist, create fresh file
        FIL fp;
        f_open(&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
        UINT n;
        f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
        // TODO check we could write n bytes
        f_close(&fp);
    }
}
Beispiel #16
0
BOOL idiskFormat(){
   FATFS fs1;
   int r; 
   unsigned char buf[512];
   f_mount(0, &fs1);
   r = f_mkfs(0,0,0);
   if (FR_OK!=r) {
      return FALSE;
   }
   return TRUE;
}
Beispiel #17
0
void Para_ResetToFactorySetup(void)
{
	/* 如果挂载不成功,进行格式化 */
		f_mkfs("0:",1,0);
	/* 加速计默认校准值 */
	sensor_setup.Offset.Accel.x = 0;
	sensor_setup.Offset.Accel.y = 0;
	sensor_setup.Offset.Accel.z = 0;
	/* 陀螺仪默认校准值 */
	sensor_setup.Offset.Gyro.x = 0;
	sensor_setup.Offset.Gyro.y = 0;
	sensor_setup.Offset.Gyro.z = 0;
	/* 罗盘默认校准值 */
	sensor_setup.Offset.Mag.x = 0;		
	sensor_setup.Offset.Mag.y = 0;		
	sensor_setup.Offset.Mag.z = 0;	
	/* 气压计默认校准值 */	
	sensor_setup.Offset.Baro = 0;
   /* 温度默认校准值 */	
	sensor_setup.Offset.Temperature = 0;
	
  /* PID 默认值 */
	pid_setup.groups.ctrl1.pitch.kp = 0.8;
	pid_setup.groups.ctrl1.roll.kp  = 0.8;	
	pid_setup.groups.ctrl1.yaw.kp   = 0.8;	
	
	pid_setup.groups.ctrl1.pitch.ki = 0.1;
	pid_setup.groups.ctrl1.roll.ki  = 0.1;	
	pid_setup.groups.ctrl1.yaw.ki   = 0.1;	
	
	
	pid_setup.groups.ctrl1.pitch.kd = 2.0;
	pid_setup.groups.ctrl1.roll.kd  = 2.0;	
	pid_setup.groups.ctrl1.yaw.kd   = 1.5;	
	
	pid_setup.groups.ctrl1.pitch.kdamp = 1;
	pid_setup.groups.ctrl1.roll.kdamp  = 1;	
	pid_setup.groups.ctrl1.yaw.kdamp   = 1;

  pid_setup.groups.ctrl2.pitch.kp = 0.8;
  pid_setup.groups.ctrl2.roll.kp  = 0.8;	
	pid_setup.groups.ctrl2.yaw.kp   = 0.8;	
	
	pid_setup.groups.ctrl2.pitch.ki = 0.05;
	pid_setup.groups.ctrl2.roll.ki  = 0.05;	
	pid_setup.groups.ctrl2.yaw.ki   = 0.05;	
	
	pid_setup.groups.ctrl2.pitch.kd = 0.3;
	pid_setup.groups.ctrl2.roll.kd  = 0.3;
  pid_setup.groups.ctrl2.yaw.kd   = 0.3;

  Para_WriteSettingToFile();
	Param_SetSettingToFC();
}
Beispiel #18
0
//extern FATFS inandfs;
BOOL idiskFormat() {
   int r;
   DWORD plist[] = { FIRST_PARTITION_SIZE, -1UL, 0, 0 };  /* Divide drive into two partitions */
   BYTE work[_MAX_SS];
   unsigned int beginLBA = FS_BEGIN_SECTOR;  //64M BYTE BEGIN
   r =  f_fdiskEx(0, beginLBA, plist, work);  /* Divide physical drive 0 */
   if (FR_OK != r) {
      return FALSE;
   }
   r = f_mkfs(0, 0, 0);
   if (FR_OK != r) {
      return FALSE;
   }
   return TRUE;
}
Beispiel #19
0
void SDCard_Init(void)
{
		u32 total,free;
		u8 res=0;	
		
		W25QXX_Init();				//初始化W25Q128
		my_mem_init(SRAMIN);		//初始化内部内存池 
		my_mem_init(SRAMCCM);		//初始化CCM内存池
		
		while(SD_Init())//检测不到SD卡
		{
				LCD_ShowString(30,150,200,16,16,"SD Card Error!");
				delay_ms(500);					
				LCD_ShowString(30,150,200,16,16,"Please Check! ");
				delay_ms(500);
				LED0=!LED0;//DS0闪烁
		}
		exfuns_init();							//为fatfs相关变量申请内存				 
		f_mount(fs[0],"0:",1); 					//挂载SD卡 
		res=f_mount(fs[1],"1:",1); 				//挂载FLASH.	
		if(res==0X0D)//FLASH磁盘,FAT文件系统错误,重新格式化FLASH
		{
				LCD_ShowString(30,150,200,16,16,"Flash Disk Formatting...");	//格式化FLASH
				res=f_mkfs("1:",1,4096);//格式化FLASH,1,盘符;1,不需要引导区,8个扇区为1个簇
				if(res==0)
				{
						f_setlabel((const TCHAR *)"1:ALIENTEK");	//设置Flash磁盘的名字为:ALIENTEK
						LCD_ShowString(30,150,200,16,16,"Flash Disk Format Finish");	//格式化完成
				}else LCD_ShowString(30,150,200,16,16,"Flash Disk Format Error ");	//格式化失败
				delay_ms(1000);
		}													    
		LCD_Fill(30,150,240,150+16,WHITE);		//清除显示			  
		while(exf_getfree("0",&total,&free))	//得到SD卡的总容量和剩余容量
		{
				LCD_ShowString(30,150,200,16,16,"SD Card Fatfs Error!");
				delay_ms(200);
				LCD_Fill(30,150,240,150+16,WHITE);	//清除显示			  
				delay_ms(200);
				LED0=!LED0;//DS0闪烁
		}													  			    
		POINT_COLOR=BLUE;//设置字体为蓝色	   
		LCD_ShowString(30,150,200,16,16,"FATFS OK!");	 
		LCD_ShowString(30,170,200,16,16,"SD Total Size:     MB");	 
		LCD_ShowString(30,190,200,16,16,"SD  Free Size:     MB"); 	    
		LCD_ShowNum(30+8*14,170,total>>10,5,16);				//显示SD卡总容量 MB
		LCD_ShowNum(30+8*14,190,free>>10,5,16);					//显示SD卡剩余容量 MB		

}
Beispiel #20
0
/*
 * ======== ramdisk_start ========
 *
 */
DRESULT ramdisk_start(BYTE drive, unsigned char *data, int numBytes, int mkfs)
{
    DRESULT result;

    /* ensure 'drive' is a valid index */
    if (drive >= _VOLUMES) {
        return RES_PARERR;
    }

    /* ensure this volume isn't already in use */
    if (diskMem[drive] != NULL) {
        return RES_PARERR;
    }

    /*
     *  Register the ramdisk functions with the diskio module.  FatFS will
     *  call these via the diskio function table.
     */
    if ((result = disk_register(drive, ramdisk_init, ramdisk_status,
            ramdisk_read, ramdisk_write, ramdisk_ioctl)) != RES_OK) {
        return result;
    }

    /* if creating a new ramdisk, zero out 'data[]' and call f_mkfs() */
    if (mkfs) {
        memset(data, 0, numBytes);
    }

    diskMem[drive]    = data;
    numSectors[drive] = numBytes / SECTORSIZE;

    /* mount the drive */
    if (f_mount(drive, &(ramdisk_filesystems[drive])) != FR_OK) {
        return RES_ERROR;
    }

    if (mkfs) {
        if (f_mkfs(drive, 0, 512) != FR_OK) {
            return RES_ERROR; 
        }
    }

    return RES_OK;
}
Beispiel #21
0
bool gui_format_sd()
{
	gui_showmessage_P(PSTR("Formating..."));
	gui_force_loop();
	ewdt_reset();
	uint8_t ret = f_mkfs("", 0, 0);
	assert(ret == RES_OK);
	DEBUG("ret = %u\n", ret);
	if (ret == RES_OK)
	{
		gui_showmessage_P(PSTR("Done!"));
		return true;
	}
	else
	{
		char tmp[16];
		sprintf_P(tmp, PSTR("Error: %02u"), ret);
		gui_showmessage(tmp);
		return false;
	}
}
Beispiel #22
0
int jswrap_E_flashFatFS(JsVar* options) {
  uint32_t addr = FS_FLASH_BASE;
  uint16_t sectors = FS_SECTOR_COUNT;
  uint8_t format = 0;
  if (jsvIsObject(options)) {
    JsVar *a = jsvObjectGetChild(options, "addr", false);
    if (a) {
      if (jsvIsNumeric(a) && jsvGetInteger(a)>0x100000)
        addr = (uint32_t)jsvGetInteger(a);
    }
    JsVar *s = jsvObjectGetChild(options, "sectors", false);
    if (s) {
      if (jsvIsNumeric(s) && jsvGetInteger(s)>0)
        sectors = (uint16_t)jsvGetInteger(s);
    }
    JsVar *f = jsvObjectGetChild(options, "format", false);
    if (f) {
      if (jsvIsBoolean(f))
        format = jsvGetBool(f);
    }
  }
  else if (!jsvIsUndefined(options)) {
    jsExceptionHere(JSET_TYPEERROR, "'options' must be an object, or undefined");
  }
  
  uint8_t init=flashFatFsInit(addr, sectors);
  if (init) {
    if ( format ) {
      uint8_t res = f_mount(&jsfsFAT, "", 0);
      jsDebug("Formatting Flash");
      res = f_mkfs("", 1, 0);  // Super Floppy format, using all space (not partition table)
      if (res != FR_OK) {
        jsExceptionHere(JSET_INTERNALERROR, "Flash Formatting error:",res);
        return false;
     }
   }    
  }
  jsfsInit();
  return true;
}
Beispiel #23
0
/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
 * associated arguments. */
int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size) {
    FATFileSystem fs;
    int err = fs.mount(bd, false);
    if (err) {
        return err;
    }

    // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
    fs.lock();
    FRESULT res = f_mkfs(fs._fsid, 1, cluster_size);
    fs.unlock();
    if (res != FR_OK) {
        return fat_error_remap(res);
    }

    err = fs.unmount();
    if (err) {
        return err;
    }

    return 0;
}
Beispiel #24
0
void LTK_format_disk(void)
{
    FATFS fs;
    uint8_t res;
    res = f_mount(0,&fs);
    if (res != FR_OK)
    {
        printf("mont file system error, error code: %u\n",res);
        return;
    }
    printf("formating, may need up to minutes, please wait...\n");
    res = f_mkfs(0,1,4096);
    if (res == FR_OK)
    {
        printf("successful...\n");
    }
    else
    {
        printf("failed to format disk, error code: %u\n", res);
    }
    f_mount(0,NULL);
}
Beispiel #25
0
bool InitExtFS() {
    static bool ramdrv_ready = false;
    
    for (u32 i = 1; i < NORM_FS; i++) {
        char fsname[8];
        snprintf(fsname, 7, "%lu:", i);
        if (fs_mounted[i]) continue;
        fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
        if ((!fs_mounted[i] || !ramdrv_ready) && (i == NORM_FS - 1) && !(GetMountState() & IMG_NAND)) {
            u8* buffer = (u8*) malloc(STD_BUFFER_SIZE);
            if (!buffer) bkpt; // whatever, this won't go wrong anyways
            f_mkfs(fsname, FM_ANY, 0, buffer, STD_BUFFER_SIZE); // format ramdrive if required
            free(buffer);
            f_mount(NULL, fsname, 1);
            fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
            ramdrv_ready = true;
        }
    }
    SetupNandSdDrive("A:", "0:", "1:/private/movable.sed", 0);
    SetupNandSdDrive("B:", "0:", "4:/private/movable.sed", 1);
    return true;
}
Beispiel #26
0
int mount_fs()
{
  FRESULT err;
  filesystem_info fatfs_info;
  FATFS_LinkDriver(&SFLASHDISK_Driver, SFLASHPath);

  err = f_mount(&SFLASHFatFs, (TCHAR const *)SFLASHPath, 0);
  check_file_result(err, "Fail to mount filesystem.");

  fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath);
  if (fatfs_info.total_space == 0)
  {
    helper_log("Filesystem total space is %d, need format", fatfs_info.total_space);
    helper_log("Start formatting filesystem...");
    err = f_mkfs((TCHAR const *)SFLASHPath, 0, _MAX_SS);
    check_file_result(err, "Fail to format filesystem.");
    fatfs_info = fatfs_get_info((uint8_t *)SFLASHPath);
  }
  helper_log("filesystem total space is %dKB, free space is %dKB", fatfs_info.total_space, fatfs_info.free_space);
  is_fs_mounted = true;
  return FR_OK;
}
Beispiel #27
0
/*
*********************************************************************************************************
*	函 数 名: main
*	功能说明: 程序入口,主函数
*	形    参:
*	返 回 值:
*********************************************************************************************************
*/
int main(void)
{
    OS_ERR err;

//	FLASH_SPI_Init();
//	W25QXX_Erase_Chip();
    result = f_mount(&fs,"0:",1);//挂载外部Flash为逻辑磁盘0

    if( result == FR_NO_FILESYSTEM )//如果该磁盘没有被格式化为FatFS,则格式化它
    {
        result = f_mkfs("0:",0,4096); //格式化方式为FDISK,建立分区表,4096为每个簇的大小
        result = f_mount(&fs,"0:",0);
        result = f_mount(&fs,"0:",1);
    }

//	CPU_IntDis();//BSP_IntDisAll();                           /* Disable all interrupts.
    OSInit(&err);

    /*创建任务*/
    OSTaskCreate((OS_TCB     *)&AppTaskStartTCB,              // 任务控制块指针
                 (CPU_CHAR   *)"App Task Start",		          // 任务名称
                 (OS_TASK_PTR )AppTaskStart, 	                // 任务代码指针
                 (void       *)0,			                      	// 传递给任务的参数parg
                 (OS_PRIO     )APP_TASK_START_PRIO,			  		// 任务优先级
                 (CPU_STK    *)&AppTaskStartStk[0],	          // 任务堆栈基地址
                 (CPU_STK_SIZE)APP_TASK_START_STK_SIZE/10,	  // 堆栈剩余警戒线
                 (CPU_STK_SIZE)APP_TASK_START_STK_SIZE,		  	// 堆栈大小
                 (OS_MSG_QTY  )5u,			                      // 可接收的最大消息队列数
                 (OS_TICK     )0u,			                      // 时间片轮转时间
                 (void       *)0,			                      	// 任务控制块扩展信息
                 (OS_OPT      )(OS_OPT_TASK_STK_CHK |
                                OS_OPT_TASK_STK_CLR),	      	// 任务选项
                 (OS_ERR     *)&err);		                    	// 返回值

    /* 启动多任务系统,控制权交给uC/OS-II */
    OSStart(&err);

}
Beispiel #28
0
/**
 * @brief fatfs_mkfs Make a new FAT filesystem
 * @param block_writer the file to contain the raw filesystem data
 * @param block_offset the offset within fatfp for where to start
 * @param block_count how many FWUP_BLOCK_SIZE blocks
 * @return 0 on success
 */
int fatfs_mkfs(struct block_cache *output, off_t block_offset, size_t block_count)
{
    // The block count is only used for f_mkfs according to the docs. Store
    // it here for the call to f_mkfs since there's no way to pass it through.
    block_count_ = block_count;

    MAYBE_MOUNT(output, block_offset);

    // Since we're going to format, clear out all blocks in the cache
    // in the formatted range. Additionally, mark these blocks so that
    // they don't need to be written to disk. If the format code writes
    // to them, they'll be marked dirty. However, if any code tries to
    // read them, they'll get back zeros without any I/O. This is best
    // effort.
    OK_OR_RETURN_MSG(block_cache_trim(output, block_offset * FWUP_BLOCK_SIZE, block_count * FWUP_BLOCK_SIZE, true),
                     "Error trimming blocks affacted by fat_mkfs");

    // The third parameter is the cluster size. We set it low so
    // that we have enough clusters to easily bump the cluster count
    // above the FAT32 threshold. The minimum number of clusters to
    // get FAT32 is 65526. This is important for the Raspberry Pi since
    // it only boots off FAT32 partitions and we don't want a huge
    // boot partition.
    //
    // NOTE2: FAT file system usage with fwup generally has been for the small
    // boot partitions on platforms and not huge partitions. If this
    // changes, it would be good to make this configurable so that massive
    // partitions could be made.
    //
    // NOTE3: Specify FM_SFD (super-floppy disk) to avoid fatfs wanting to create
    // a master boot record.
    char buffer[FF_MAX_SS];
    CHECK("fat_mkfs", NULL, f_mkfs("", FM_SFD|FM_FAT|FM_FAT32, FWUP_BLOCK_SIZE, buffer, sizeof(buffer)));

    return 0;
}
Beispiel #29
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  FRESULT res;                                          /* FatFs function common result code */
  uint32_t byteswritten, bytesread;                     /* File write/read counts */
  uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
  uint8_t rtext[100];                                   /* File read buffer */

  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Initialize IO expander */
  BSP_IO_Init();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* ###########################################################################
     When the uSD Card is used; the Camera module must be unplugged, this is due
     to the shared pins between the two devices. 
  
     Otherwise, you have to set camera sensor in Power Down mode, by calling the
     BSP_CAMERA_PwrDown() available under stm32446e_eval_camera.c BSP driver */
  
      BSP_IO_Init();
      
     /* Assert the camera RSTI pin */ 
     /* Camera power down sequence */
     BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT);
     /* Assert the camera RSTI pin (active low) */
     BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET);
  
  /*##-1- Link the SD disk I/O driver ########################################*/
  if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) 
  {
    /*##-2- Register the file system object to the FatFs module ##############*/
    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
    {
      /* FatFs Initialization Error */
      Error_Handler();
    }
    else
    {
      /*##-3- Create a FAT file system (format) on the logical drive #########*/
      if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
      {     
        Error_Handler();
      }
      else
      {
        /*##-4- Create and Open a new text file object with write access #####*/
        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) 
        {
          /* 'STM32.TXT' file Open for write Error */
          Error_Handler();
        }
        else
        {
          /*##-5- Write data to the text file ################################*/
          res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
          
          if((byteswritten == 0) || (res != FR_OK))
          {
            /* 'STM32.TXT' file Write or EOF Error */
            Error_Handler();
          }
          else
          {
            /*##-6- Close the open text file #################################*/
            f_close(&MyFile);
            
            /*##-7- Open the text file object with read access ###############*/
            if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
            {
              /* 'STM32.TXT' file Open for read Error */
              Error_Handler();
            }
            else
            {
              /*##-8- Read data from the text file ###########################*/
              res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
              
              if((bytesread == 0) || (res != FR_OK))
              {
                /* 'STM32.TXT' file Read or EOF Error */
                Error_Handler();
              }
              else
              {
                /*##-9- Close the open text file #############################*/
                f_close(&MyFile);
                
                /*##-10- Compare read data with the expected data ############*/
                if ((bytesread != byteswritten))
                {                
                  /* Read data is different from the expected data */
                  Error_Handler(); 
                }
                else
                {
                  /* Success of the demo: no error occurrence */
                  BSP_LED_On(LED1);
                }
              }
            }
          }
        }
      }
    }
  }
  
  /*##-11- Unlink the SD disk I/O driver ####################################*/
  FATFS_UnLinkDriver(SDPath);
  
  /* Infinite loop */
  while (1)
  {
  }
}
Beispiel #30
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t  sdram_status = SDRAM_OK;
  uint8_t  lcd_status = LCD_OK;
  uint32_t ts_status  = TS_OK;

  p_bmp_converted_pixel_data = (uint8_t *)CONVERTED_FRAME_BUFFER;

  /* STM32F4xx HAL library initialization:
  - Configure the Flash prefetch, instruction and Data caches
  - Configure the Systick to generate an interrupt each 1 msec
  - Set NVIC Group Priority to 4
  - Global MSP (MCU Support Package) initialization
  */
  HAL_Init();

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /*##-1- Initialize the SDRAM */
  sdram_status = BSP_SDRAM_Init();
  if(sdram_status != SDRAM_OK)
  {
    Error_Handler();
  }

  /*##-2- LCD Initialization #################################################*/
  /* Initialize the LCD DSI */
  lcd_status = BSP_LCD_Init() ;
  if(lcd_status != LCD_OK)
  {
    Error_Handler();
  }

  lcd_status = BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE);
  if(lcd_status != LCD_OK)
  {
    Error_Handler();
  }
  BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_BACKGROUND, LCD_FB_START_ADDRESS);

  /* Clear the LCD Background layer */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-3- Touch screen initialization ########################################*/
  BSP_TS_ResetTouchData(&TS_State);

  /* If calibration is not yet done, proceed with calibration */
  if (TouchScreen_IsCalibrationDone() == 0)
  {
    ts_status = Touchscreen_Calibration();
    if(ts_status == TS_OK)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen calibration success.", CENTER_MODE);
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */



  /*##-4- Link the SD Card disk I/O driver ###################################*/

  /* Clear the LCD and display waiting message */
  BSP_LCD_Clear(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetFont(&Font12);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 27, (uint8_t*)"Please WAIT few seconds", CENTER_MODE);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 12, (uint8_t*)"Creating FAT file system on SD card", CENTER_MODE);

  if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0)
  {
    /* FatFs Initialization Error */
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
  }

/*##-4- Register the file system object to the FatFs module ################*/
  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
    {
    /* FatFs Initialization Error */
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
   }
  /* Create a FAT file system (format) on the logical drive */
  if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
  {
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t*)"FAT FS Error !!", CENTER_MODE);
    Error_Handler();
  }

  /*##-5- Draw the menu ######################################################*/
  Draw_Menu();

  /* Infinite loop */
  while (1)
  {
  /*##-6- Configure the touch screen and Get the position ####################*/
    GetPosition();
  }
}