如题,我的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,不知道是什么原因
麻烦大家帮我看看,这的是绝望了。
---------------------------------
如果ff.c没错的话(LZ没有无意中改动过),那么还是看看前面的f_open以及f_mount吧,前面的对了,后面一般不会出错。另外,建议LZ把调用f_mount的代码发来,如果可以f_open()用全路径吧;另外,LZ的SD卡最好在开发板上面进行格式化,并确保成功,程序简单,要错最有可能的不是逻辑,而是有些基本的LZ可能忽略了
[mw_shl_code=c,true]int main(void) { FRESULT res; uint32_t byteswritten; volatile int num = 0; HAL_Init(); SystemClock_Config(); res = FATFS_LinkDriver(&SDRAMDISK_Driver, RAMpath); if(res != FR_OK) Error_Handler(); res = FATFS_LinkDriver(&SD_Driver, SDpath); if(res != FR_OK) Error_Handler(); res = f_mount(&RAMFatFs, (TCHAR const*)RAMpath, 0); if(res != FR_OK) Error_Handler(); res = f_mount(&SDFatFs, (TCHAR const*)SDpath, 0); if(res != FR_OK) Error_Handler(); /* res = f_mkfs((TCHAR const*)SDpath, 0, 0); if(res != FR_OK) Error_Handler(); */ res = f_open(&SDFile, "1:STM000.c", FA_OPEN_ALWAYS | FA_WRITE); if(res != FR_OK) Error_Handler(); write_buf(middle); //往middle里面填满4096字节数据 while(1) { num++; res = f_write(&SDFile, middle, 4096, (void *)&byteswritten); f_sync(&SDFile); } f_close(&SDFile); FATFS_UnLinkDriver(RAMpath); FATFS_UnLinkDriver(SDpath); /* Infinite loop */ while (1) { } } void write_buf(char middle[4096]) { char *p = "aaaaaaaabbbbbbbbeeeeeeeeffffffff"; int count = 0; while(count < 128) { count++; strncat(middle,p,128); } } [/mw_shl_code]
大致调用就这样了,里面有RAM,不过没用到
另外我的SD卡簇大小格式化成了4096
---------------------------------
兄弟,感谢!我也想问您要下,你的写一个字符数组到SD卡的程序,邮箱745677020@qq.com。你说的办法我都试了,但是还是没有起 {MOD},不知道是什么原因,我用的文件版本是R0.07e的,不知道这个会不会有影响
---------------------------------
我的是0.09b版本的,你还是换个新版本的吧
---------------------------------
请问在挂载文件系统之前,也就是f_mount()之前,要不要进行内存分配也就是调用memlloc函数?我看了原子哥的程序,他里面的程序就有,请问这个必须的吗
一周热门 更多>