stm32f103 cubx fatfs problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-04 7:41 AM
hi
i used open file
unsigned char read_file (char *filename,unsigned long address,uint8_t *data){
FIL MyFile; /* File object */ char SDPath[4]; /* SD card logical drive path */ FATFS FatFs; /* Work area (file system object) for logical drive */ FRESULT res; /* FatFs function common result code */ uint32_t bytesread=2; /* File write/read counts */if(FATFS_LinkDriver(&USER_Driver, SDPath) == 0) { if(f_mount(&FatFs, (TCHAR const*)SDPath, 0) != FR_OK) { /* FatFs Initialization Error */ showerror ('Fat Fs Not Int'); return 1; } else { if(f_open(&MyFile, filename , FA_READ) != FR_OK) { /* 'STM32.TXT' file Open for read Error */ showerror ('File Not Fined'); return 2; } else { res = f_read(&MyFile, data ,sizeof(data), (UINT*)&bytesread);if((bytesread == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Read or EOF Error */ showerror (' Read Error '); return 3; } else { f_close(&MyFile); return 0; } } } } FATFS_UnLinkDriver(SDPath); }bout sizeof(data) is wrong number not compatible with size file please advise me how can resolved
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-04 7:56 AM
>>
bout sizeof(data) is wrong number not compatible with size file please advise me how can resolved
Pass the size of the data in as a parameter to the function, you don't want the size of the pointer, but the underlying buffer you are passing
ie
unsigned char read_file (char *filename,unsigned long address,uint8_t *data, uint32_t size)
{
...
res = f_read(&MyFile, data ,size, (UINT*)&bytesread);
...
}
where
uint8_t buffer[1024]
read_file(..., buffer, sizeof(buffer));
What's address?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-04 8:05 AM
address not used
bout how can understand size of file which function can help to me for get size of file usually size of file must fined in fat
i need open file and read until end of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-04 10:27 AM
So use f_size(&MyFile)
But your buffer needs to be large enough to hold the data, so the buffer behind 'data' passed in needs to be big enough, or you need to malloc() the buffer locally if you have a big enough heap.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-04 10:31 AM
You can use smaller buffers, where you repeatedly call f_read until the bytes read is zero, or less than requested.
Up vote any posts that you find helpful, it shows what's working..
