查看: 1556|回复: 0
打印 上一主题 下一主题

FatFs多分区,第二个分区新建文件提示该卷没有工作区

[复制链接]
跳转到指定楼层
沙发
发表于 2015-5-27 16:21:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

       
搜索
搜索       
热搜: 净化器雕刻机阿莫邮购
amoBBS 阿莫电子论坛?论坛首页?单片机?STM32/8?FatFs多分区,第二个分区新建文件提示该卷没有工作区 ...bottom↓
返回列表发新帖
查看: 63|回复: 1
打印 上一主题 下一主题 FatFs多分区,第二个分区新建文件提示该卷没有工作区 [复制链接]
tianxiaoMCU

电梯直达跳转到指定楼层 1楼
发表于 4 天前 | 只看该作者 回帖奖励
FatFs版本是R0.11,不分区,新建文件、编辑文件都没有问题的。现在分成两个区,也没有问题,但是新建文件就有问题了,第二个分区新建文件一直出错,根据返回结果是12,The volume has no work area。劳烦大家帮忙看看

static FATFS FATfs;
static FIL fil;
static uint8_t work[_MAX_SS];

void formatflash(void)
{
    FRESULT res;
    DWORD plist[] = {50, 50, 0, 0};  /* Divide drive into two partitions */

    /* Divide physical drive 0 */
    f_fdisk(0, plist, work);

    SEGGER_RTT_WriteString(0, "Partition, please waite...\r\n");


    /* Register work area to the logical drive 0 */
    f_mount(&FATfs, "0:", 0);
    /* Create FAT volume on the logical drive 0. 2nd argument is ignored. */
    res = f_mkfs("0:", 0, 4096);
    if (FR_OK == res)
    {
        SEGGER_RTT_WriteString(0, "format logical drive 0 Succeeded\r\n");
    }
    else
    {
        SEGGER_RTT_WriteString(0, "format logical drive 0 faile\r\n");
        Err_Reason(res);
    }
    /* Unregister work area from the logical drive 0 */
    f_mount(0, "0:", 0);



    /* Register a work area to the logical drive 1 */
    f_mount(&FATfs, "1:", 0);
    /* Create FAT volume on the logical drive 1. 2nd argument is ignored. */
    res = f_mkfs("1:", 0, 4096);
    if (FR_OK == res)
    {
        SEGGER_RTT_WriteString(0, "format logical drive 1 Succeeded\r\n");
    }
    else
    {
        SEGGER_RTT_WriteString(0, "format logical drive 1 faile\r\n");
        Err_Reason(res);
    }
    /* Unregister work area from the logical drive 1 */
    f_mount(0, "1:", 0);
}

void creatfile(void)
{
    FRESULT res;

    /* Register work area to the logical drive 0 */
    res = f_mount(&FATfs, "0:", 0);
    if (RES_OK != res)
    {
        SEGGER_RTT_WriteString(0, "mount logical drive 0 faile\r\n");
        Err_Reason(res);
        return;        
    }

    /* creat a bin file */
    res = f_open(&fil, "test.log", FA_CREATE_ALWAYS);
    if (RES_OK == res)
    {
        SEGGER_RTT_WriteString(0, "creat log file Succeeded\r\n");
    }
    else
    {
        SEGGER_RTT_WriteString(0, "creat file log faile\r\n");
        Err_Reason(res);
    }

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

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




    /* Register work area to the logical drive 1 */
    res = f_mount(&FATfs, "1:", 0);
    if (RES_OK != res)
    {
        SEGGER_RTT_WriteString(0, "mount logical drive 1 faile\r\n");
        Err_Reason(res);
        return;        
    }

    /* creat a bin file */
    res = f_open(&fil, "test.bin", FA_CREATE_ALWAYS);
    if (RES_OK == res)
    {
        SEGGER_RTT_WriteString(0, "creat bin file Succeeded\r\n");
    }
    else
    {
        SEGGER_RTT_WriteString(0, "creat bin file faile\r\n");
        Err_Reason(res);
    }

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

    /* Unregister work area */
    f_mount(0, "1:", 0);
}
复制代码转载

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表