Some Problems of FATFS

Module: FATFS R0.12b

Problem Summary:
The character conversion from Unicode to ASCII/OEM(especially in 936(Simplified Chinese GBK) ) when _LFN_UNICODE==1.

Environment: MDK5.10.0.2

Description:
Firstly, thank you for your FAT filesystem module FATFS, ChaN, I like it very much.

I didn’t know FATFS can convert Unicode to ASCII/OEM automatically when reading a LFN of a file in the situation of _LFN_UNICODE==0 before, so I have to write a function to convert a LFN which is obtained from filinfo.fname, the member of FILINFO type structure, by

f_readdir(DIR* DirObject, FILINFO* FileInfo)

from Unicode to ASCII/OEM in the situation of _LFN_UNICODE==1. Recently, I have found a problem whether it is a bug or not and I expect to ask you for help.

I create a file with Chinese LFN in SD card. I can see the correct file name in SD Card by computer. However, I fail to display the same string in UART debug software except the English file name. The related part of code, files’ name displayed in computer and files’ name displayed in UART debug software are shown as follow.
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

In order to find the problem, taking the LFN “English中文.txt” as an example, I trace into the f_readdir() and get the fileinfo.fname, then I obtain the array of fname[] compared with the code of the same file name coded in Unicode shown in following fig.
这里写图片描述

As is shown, the 1st byte of a DBC is cut out. Then, I trace into the funciton get_fileinfo() which is called by f_readdir(). After rough reading, I find the part of code in get_fileinfo() could cut out the 1st byte in the situation of _LFN_UNICODE==1 but no any problem in the situation of _LFN_UNICODE==0. The part of code is shown in following fig.
这里写图片描述

I try replacing the part of code with the following code and set _LFN_UNICODE==1 then the UART debug software print Chinese file name successfully. I also try printing Chinese file name in the situation of _LFN_UNICODE==0 and it works as well.

while ((w = *lfn++) != 0) {      /* Get an LFN character */
#if !_LFN_UNICODE
  w = ff_convert(w, 0);      /* Unicode -> OEM */
  if (w == 0) { i = 0; break; }   /* No LFN if it could not be converted */
  if (i >= _MAX_LFN) { i = 0; break; }   /* No LFN if buffer overflow */
  if (_DF1S && w >= 0x100) {   /* Put 1st byte if it is a DBCS (always false at SBCS cfg) */
    fno->fname[i++] = (char)(w >> 8);
  }
  fno->fname[i++] = (char)w;
#else
  if (i >= _MAX_LFN) { i = 0; break; }   /* No LFN if buffer overflow */
  fno->fname[i++] = w;
#endif
}
fno->fname[i] = 0;   /* Terminate the LFN */

That is all my description, thanks for reading.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值