如题,我的F4的板子,文件系统版本是R0.07e。已经调了4,5天了,快崩溃了,就大家帮我看看程序到底有什么问题,万分感谢!!!
/*********************************************************************************************************
*
* File : main.c
* Hardware Environment:
* Build Environment : RealView MDK-ARM Version: 4.20
* Version : V1.0
* By :
*
* (c) Copyright 2005-2011, WaveShare
* http://www.waveshare.net
* All Rights Reserved
*
*********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "sdcard.h"
#include "usart.h"
#include "string.h"
#include "diskio.h"
#include "ff.h"
/* Private functions ---------------------------------------------------------*/
FATFS fs; // Work area (file system object) for logical drive
FIL fsrc; // file objects
FRESULT res; // FatFs function common result code
UINT bw; // File R/W count
XCHAR fileName[20]="test1.txt";
/*******************************************************************************
* Function Name : NVIC_Config
* Description : Configures SDIO IRQ channel.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void WRUTE_File(void)
{
FRESULT res;
DIR dirs;
char path[16]={""};
char buffer[512]; //??????????????×é
int i;
for(i=0;i<512;i++)
{
buffer
='k';
}
printf(" ??????????:%d
",disk_initialize(0));
printf("????????:%d
",f_mount(0, &fs));
if (f_opendir(&dirs, path) == FR_OK)
{
if(f_open(&fsrc, fileName, FA_READ|FA_WRITE|FA_OPEN_ALWAYS))
{
printf("can not open file
");
}
else
{
printf("here A
");
if(f_lseek(&fsrc,fsrc.fsize))//f_size(&file)
{
printf("can not seek the file pointer
");
}
else
{
printf("filesize=%d
",fsrc.fsize);
res=f_write(&fsrc, buffer, 512, &bw);
if(res==FR_OK)//????&file????filename???????×???·??3000??????????×?????
{
printf(" write ok
");
printf("bw=%d
",bw);
}
else
{printf("can not write file
");}
}
}
}
else{printf("cao not open dir
");}
f_close(&fsrc); // ??±???????±?????f_open????????????
f_mount(0, 0); //????????????
printf("here C
");
}
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
SystemInit();/* Clock Config */
NVIC_Configuration();/* Interrupt Config */
USART_Configuration();
//printf("buffer=%s
",buffer);
WRITE_File();
/* Infinite loop */
while (1);
}
这些ABC是我用来调试用的,没有什么意义。我在SD卡里看test1.txt还是0KB,不知道是什么原因
麻烦大家帮我看看,这的是绝望了。
---------------------------------
f_write之后立刻调用f_close
---------------------------------
刚刚照您说的去检测了f_close();还真是出了问题,文件关闭失败,那为什么会失败呢?不都是这样用的吗?感谢老师在百忙之中已于的帮助。
---------------------------------
4楼回复错了
太感谢老师给予的解答了,大赞一个,虽然我还没有找您说的在write后立即调用close,但是感觉这就是解决办法
一周热门 更多>