給stm32移植fatfs文件系統,今天終於取得階段性勝利。只需要提供這樣幾個函數即可
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); // 如果實現只讀的文件系統就不需要了。
DRESULT disk_ioctl (BYTE, BYTE, void*);
移植成功後,可以用如下方式讀取SD卡了,實在太方便了,和PC機上編程差不了多少。
unsigned int i;
BYTE buffer[512]; // file buffer
FATFS fs; // Work area (file system object) for logical drive
FIL fsrc; // file objects
FRESULT res; // FatFs function common result code
UINT br; // File R/W count
USART1_Puts("Now, I'll read file 'i2c/uart.lst'.\n");
// Register a work area for logical drive 0
f_mount(0, &fs);
// Open source file
res = f_open(&fsrc, "i2c/uart.lst", FA_OPEN_EXISTING | FA_READ);
if (res)
{
USART1_Puts("Can't open i2c/uart.lst for read. :-(\n");
goto exit;
}
for (;;) {
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
if (res || br == 0) break; // error or eof
for( i = 0; i < br; ++i )
USART1_Putc(buffer[i]);
}
f_close(&fsrc);
exit:
// Unregister a work area before discard it
f_mount(0, NULL);
2. STM32 文件系統,傳輸文件
文件:mian.c
//功能:串口初始化、打開定時器中斷,然後一直接收數據狀態就好了。發送版在中斷中實現權
#include "stm32f10x.h"
#include "usart.h"
u8 USART_rx_data;
int main(void)
{
RCC_Configuration(); //系統時鍾配置
GPIO_Configuration(); //埠初始化
NVIC_Configuration(); //中斷源配置
USART_Configuration(); //串口1初始化
Time_Init(); //定時器初始化
#ifdef DEBUG
debug();
#endif
TIM_Cmd(TIM3,ENABLE);
while(1)
{
}
}
3. STM32的FatFS文件系統中如何創建和批量命名文件
給你個我寫的樣板。。。
char pch[40];
short inum=0,bmpres;
FIL bmpfsrc;
do
{
sprintf((char*)pch,"0:ScreenShort/SS_%d.bmp",inum++);
if(inum>500)return;
bmpres = f_open( &bmpfsrc,(char*)pch, FA_CREATE_NEW | FA_WRITE);
}while(bmpres!=FR_OK);
BmpScreen_short(0,0,400,240,&bmpfsrc);
f_close(&bmpfsrc);
我這個是截圖用的一部分代碼,功能是把當前截回圖保存到內存卡上面,答內存卡上面已經有一部分截圖了,所以當前截圖的名字需要不和以前的重復,我用了一個while來一直創建,知道創建成功為止。圖片命名裡面有個變數,比如第一張截圖是SS_0.bmp,第二個截圖就是SS_1.bmp。
假設內存卡上面已經有SS_0.bmp和SS_1.bmp,那麼,當前截圖的名字就是SS_2.bmp。你那個比我這個還簡單,希望能夠給你提示。
4. stm32 sd卡文件系統移植什麼意思
通俗的講就是stm32能將sd卡格式化,然後可以往裡面讀寫文件。野火開發板常式裡面有sd卡文件系統的例子吧。