int FATFileSystem::format(BlockDevice *bd, int allocation_unit) {
FATFileSystem fs; //this is a not init variable
int err = fs.mount(bd, false);
if (err) {
return err;
}
FATFileSystem fs; before use Variables are not initialized
cc @geky
In C++, declaring a variable calls its constructor. The FATFileSystem constructor is here:
https://github.com/ARMmbed/mbed-os/blob/master/features/filesystem/fat/FATFileSystem.cpp#L235-L240
The fs.mount function sets up the FATFileSystem to use the BlockDevice in the f_mkfs function.
@wjffsx have you had any problems with the function ? any runtime error/compile warning or?
complie is ok ; in runtime ;i can not format SD card
Ah ok, then a few questions:
have found reason, code is ok;
before format() ; should call unmount();
Use the following order:
unmount();
format();
mount();
Ah thats good to know. Glad you found a fix.