Closed mrguen closed 3 years ago
Hi @mrguen Which kind of file it is ? Names ? Could you share it. My first guess is it could be linked to LFN or format 8.3.
Hello @fpistm
ok, in fact windows can't see it as an SD card. It could access it through a USB adapter. It is seen as a USB drive in FAT32 format. I don't know how to recognize / format it otherwise.
For Windows, it seems correct an SD card is simply a mass storage so see it as an USB drive is correct, I guess.
Now
Example Cardinfo.ino works to list a file created under windows
ReadWrite.ino:
" Initializing SD card...initialization done. Writing to test.txt...done. error opening test.txt
" In fact the file was not written (nothing visble under windows)
Where did you set SD_DETECT_PIN
?
I tried
without changing anything i.e. defined in the sketch (ifnedf)
and setting it to PC4 it in the sketch (ifndef)
OK Fine. Which variant you used ? The generic F401Rx ?
Well there are differences between Generic F401RC and Core board F401RCT6
Generic STM32F4 series / Core board F401RCT6 : both problems 1) file not written 2) Card not seen after upload
Generic STM32F4 series / Generic F401RC:
The card is seen after upload.
The file "test.txt" is written but ReadWrite.ino still reports
" Initializing SD card...initialization done. Writing to test.txt...done. error opening test.txt
"
OK Thanks for the quick feedback.
Those variants has not take in account the SD part.
So, I guess you have enabled the HAL_SD_MODULE_DISABLED
else it won't compile.
By chance there is no duplicated pin in the PinMap_SD
array so the good pins are initialized.
But what I suspect is the clock config is not correct which could explain those issues. The clock have to be less or equal to 48 MHz IIWR.
Anyway, I will have to rework this library to ease use of SD pins as I've done to the MX25R6435F library.
Ok; Thanks. Strange the behaviour seems unconstant indeed. Yes, I used -DHAL_SD_MODULE_ENABLED in build_opt.h
On your custom board do you have an HSE ? If yes which value ?
8 MHz I did not change any clock settings
OK. The clock config seems ok for SD.
Thanks to the schematics, it seems other SD pins are connected and as I said all of them are initialized maybe this could cause some issue.
Could you try to redefine the PinMap_SD
with only the used pins on your sketch:
const PinMap PinMap_SD[] = {
{PC_8, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D0
{PC_9, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D1
{PC_10, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D2
{PC_11, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO)}, // SDIO_D3
{PC_12, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO)}, // SDIO_CK
{PD_2, SDIO, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO)}, // SDIO_CMD
{NC, NP, 0}
};
After removing extern "C": work as before:
Initializing SD card...initialization done. Writing to test.txt...done. error opening test.txt
OK. At this time I've no more clue for you, sorry. I guess your SD is not write protected?
No. The behaviour is strange. I just wrote a "essai.txt" file under windows. Then used ReadWrite.ino: This time the test.txt file was created but the older essai.txt file was removed. Sometimes the file is written, sometimes not and opening it is faulty every time. Also the card detect thing is not constant. I thought about a hardware / physical plugin problem but with the other symptoms it looks like a software / file system problem.
Now I see that windows does not list all the files always neither.
Tried with another SD card: not working at all. Not seen... possibly there are SD card compatibility problems?
Well hard to tell. You best bet is to debug.
to debug... down the libraries with Serial output?
No, I mean use a STLink, a GDB,... I could not help more on this subject as I don't have your hardware. I don't tell there is no software issue but I could not investigate on this without be able to reproduce. Maybe the next FatFS update will solve this issue but currently I have not time to update it.
@fpistm
From reading https://github.com/stm32duino/STM32SD#configuration I understand that we can change some configuration parameters. Since it includes a couple of encoding parameters, I suppose it might help to solve the problem explained above.
I did not find a file ffconf.h in C:\Users\TG\Documents\Arduino\libraries\FatFs\src so I copied ffconf_template.h to ffconf.h
But now I get the error "C:\Users\TG\Documents\Arduino\libraries\FatFs\src/ffconf.h:290:10: fatal error: cmsis_os.h: No such file or directory"
As it is explained in the README.md: https://github.com/stm32duino/STM32SD#dependency
This library depends on FatFs library where you will find the ffconf.h...
@fpistm Yes, I am speaking about the FaFs library ffconf.h in C:\Users\TG\Documents\Arduino\libraries\FatFs\src this is the library linked since the compiler reported the bug.
User can provide his own defined options by adding his configuration in a file named ffconf_custom.h at sketch level or in variant folder.
If you modified the Library structure then don't be surprised to have a build issue. This is not a bug as this is your modification which cause the bug.
1) I did not modify anything. Just used the ffconf_template.h as ffconf.h as explained in https://github.com/stm32duino/STM32SD#configuration "The FatFs has several user defined options, which is specified from within the ffconf.h file. This library provides a default user defined options file named ffconf_default.h"
I did not find a ffconf_default.h but a ffconf_template.h so I used it.
2) I just tried without any change in the FaFs library (removed the new ffconf.h) and adding the ffconf_default.h as ffconf_custom.h at sketch level and get the same error
"C:\Users\TG\Documents\Arduino\STM32\CardInfo/ffconf_custom.h:291:10: fatal error: cmsis_os.h: No such file or directory"
This is not what is explained.
The FatFs has several user defined options, which is specified from within the ffconf.h file.
This only explained the FatFs use this file not you have to change it.
This library provides a default user defined options file named ffconf_default.h.
This line explained a default file is provided in this library.
User can provide his own defined options by adding his configuration in a file named ffconf_custom.h at sketch level or in variant folder.
And now this line explained the way to redefine your own options.
If you open the ff_conf.h
you would see how it is managed:
Ok, I will try to use ffconf_default_68300.h as ffconf_custom.h and tweak the encoding parameters to use unicode.
It does compile when using ffconf_default_68300.h as ffconf_custom.h at sketch level.
When changing the option "_LFN_UNICODE 0" to "_LFN_UNICODE 1", a couple of bugs.
First one: " C:\Users\TG\Documents\Arduino\libraries\STM32duino_STM32SD\src\SD.cpp: In static member function 'static bool SDClass::exists(const char)': C:\Users\TG\Documents\Arduino\libraries\STM32duino_STM32SD\src\SD.cpp:83:14: error: cannot convert 'const char' to 'const TCHAR' {aka 'const short unsigned int'} 83 | if (f_stat(filepath, &fno) != FR_OK) { | ^ |
---|---|---|
const char* |
In file included from C:\Users\TG\Documents\Arduino\libraries\FatFs\src/ff_gen_drv.h:58, from C:\Users\TG\Documents\Arduino\libraries\FatFs\src/FatFs.h:42, from C:\Users\TG\Documents\Arduino\libraries\STM32duino_STM32SD\src\SdFatFs.h:43, from C:\Users\TG\Documents\Arduino\libraries\STM32duino_STM32SD\src\STM32SD.h:23, from C:\Users\TG\Documents\Arduino\libraries\STM32duino_STM32SD\src\SD.cpp:56: C:\Users\TG\Documents\Arduino\libraries\FatFs\src/ff.h:257:30: note: initializing argument 1 of 'FRESULT f_stat(const TCHAR, FILINFO)' 257 | FRESULT f_stat (const TCHAR path, FILINFO fno); / Get file status /
"
This is not a surprise. Not all config has been tested, goal of this library was to be in line with default SD library IIRW. So LFN was not supported.
Ok. Well, I am not competent to debug this. The only thing I can say is that it does not work on my configuration. I believe the hardware layer is ok since CardInfo reports the type of SD card, and sizes but it can't list the files properly, printing only ????? characters. Probably I will wait for the rework.
yes probably printing. anyway this is the first time I see that. Could you share one of the file for reference ?
which file?
which file?
One of the sdcard files which is not properly displayed.
I tried a sequence of writing to the file, using CardInfo.ino and ReadWrite.ino
I could not get the ???? characters error when trying to list the content. But I still get these problems
Output of CardInfo.ino on a freshly formated SDHC card level 10 in FAT 32 4096 bytes
A card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 15942549504
Volume size (Kbytes): 15568896
Volume size (Mbytes): 15204
Files found on the card (name, date and size in bytes):
System Volume Information
WPSettings.dat 2020-09-22 12:01:36 12
IndexerVolumeGuid 2020-09-22 12:01:40 76
###### End of the SD tests ######
Initializing SD card...initialization done.
Writing to test.txt...done.
**error opening test.txt**
###### End of the SD tests ######
CardInfo.ino again Same as first time. Does not see any file
Trying to create a file under windows gives an error 0x80070570 corrupted repertory
Formating the SD card again under win 10 (fr-fr) and creating an empty file "test.txt"
-Using CardInfo.ino again
A card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 15942549504
Volume size (Kbytes): 15568896
Volume size (Mbytes): 15204
Files found on the card (name, date and size in bytes):
System Volume Information
WPSettings.dat 2020-09-22 12:17:20 12
IndexerVolumeGuid 2020-09-22 12:17:24 76
Test.txt 2020-09-22 12:17:28 0
###### End of the SD tests ######
Initializing SD card...initialization done.
Writing to test.txt...done.
**error opening test.txt**
###### End of the SD tests ######
A card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 15942549504
Volume size (Kbytes): 15568896
Volume size (Mbytes): 15204
Files found on the card (name, date and size in bytes):
System Volume Information
WPSettings.dat 2020-09-22 12:17:20 12
IndexerVolumeGuid 2020-09-22 12:17:24 76
Test.txt 2020-09-22 12:17:28 0
###### End of the SD tests ######
Reading the file under windows: empty Under windows, adding content "test" into the file
Initializing SD card...initialization done.
Writing to test.txt...done.
error opening test.txt
###### End of the SD tests ######
Did you try with an other SD card ?
Maybe this is the answer: not reliable with build in pullups https://community.st.com/s/question/0D50X00009XkfrVSAR/using-internal-pullups-for-sdio-interface
I've found a similar weird issue where SD stops working after a while, sometimes don't even start working... my board has 25Mhz crystal, by default SD_CLK_DIV is defined to 0, chaging it to 4 fixed it. Not sure of which freq can handle the card, but for my transfer rates its ok.
Hello,
This library seems great! I tried the CardInfo.ino example. But it can't list files.
The MCU is STM32F401RCT6. Home made board with direct connections
SDCAR_DETECT: PC4 SDIO_CMD: PD2 SDIO_CK: PC13 SDIO_0 to 3: PC8 to PC11
I used a brand new SDHC card an windows sees that it is formated in FAT32.
Here is the visual monitor output:
I am in France, using a french system... I suppose there is a configuration issue. Could you give me your advice?
Thanks