新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2020-6-26
- 在线时间
- 8 小时
|
1金钱
stm32 sd卡使用fatfs文件管理,在调用f_open函数时返回12号错误,FR_NOT_ENABLED, /* (12) The volume has no work area */
以下为源代码
#include "led.h"
#include "delay.h"
#include "usart.h"
#include "malloc.h"
#include "MMC_SD.h"
#include "diskio.h"
#include "integer.h"
#include "stm32f10x.h"
#include "ffconf.h"
#include "ff.h"
u8 buff[128];
u8 read_buffer[128];
FIL fill;
UINT br,bw;
FATFS *fs;
static FRESULT res;
int main(void)
{
int i=0;
u8 t=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
uart_init(115200);
LED_Init();
mem_init();
while(SD_Initialize())
{
delay_ms(500);
delay_ms(500);
LED0=!LED0;
}
printf("SD Card OK ");
printf("SD Card Size: MB");
delay_ms(1000);
res = f_mount(fs,"0:",1); //
if(res != RES_OK)
{
printf("f_mount error!\r\n");
delay_ms(500);
}
else {
printf("f_mount successful!\r\n");
}
res = f_open(&fill,"0:/test.txt",FA_READ | FA_WRITE | FA_CREATE_ALWAYS);
delay_ms(500);
if(res!=RES_OK)
{
t=res;
printf("open %d ",t);
}
else{
printf("f_open succeed");
}
delay_ms(500);
for(i = 0;i < 128;i++)
{
buff[i] = i % 256;
}
res = f_write(&fill,buff,128,&bw);
if(res!=RES_OK)
{
t=res;
printf("write %d ",t);
}
else{
printf("f_write succeed");
}
delay_ms(500);
res = f_read(&fill,read_buffer,128,&br);
if(res != RES_OK || br != 128)
{
t=res;
printf("read %d ",t);
}
else{
printf("f_read successful!\r\n");
}
delay_ms(500);
f_close(&fill);
for(i=0;i<128;i++)
{
printf("%d ",read_buffer[i]);
}
delay_ms(1000);
while(1)
{
LED0=!LED0;
delay_ms(1000);
}
}
|
|