mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Prevent sdcard_getMetadata from being called when card is not inserted or not ready
This commit is contained in:
parent
a598d06fe5
commit
57a6060005
3 changed files with 10 additions and 4 deletions
|
@ -150,7 +150,8 @@ bool sdcard_poll(void)
|
||||||
|
|
||||||
bool sdcard_isFunctional(void)
|
bool sdcard_isFunctional(void)
|
||||||
{
|
{
|
||||||
// sdcard_isFunctional is called from multiple places
|
// sdcard_isFunctional is called from multiple places, including the case of hardware implementation
|
||||||
|
// without a detect pin in which case sdcard_isInserted() always returns true.
|
||||||
if (sdcardVTable) {
|
if (sdcardVTable) {
|
||||||
return sdcardVTable->sdcard_isFunctional();
|
return sdcardVTable->sdcard_isFunctional();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1999,7 +1999,7 @@ static void cliSdInfo(char *cmdline)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sdcard_isInitialized()) {
|
if (!sdcard_isFunctional() || !sdcard_isInitialized()) {
|
||||||
cliPrintLine("Startup failed");
|
cliPrintLine("Startup failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,8 +304,13 @@ static void serializeSDCardSummaryReply(sbuf_t *dst)
|
||||||
sbufWriteU8(dst, state);
|
sbufWriteU8(dst, state);
|
||||||
sbufWriteU8(dst, afatfs_getLastError());
|
sbufWriteU8(dst, afatfs_getLastError());
|
||||||
// Write free space and total space in kilobytes
|
// Write free space and total space in kilobytes
|
||||||
|
if (state == MSP_SDCARD_STATE_READY) {
|
||||||
sbufWriteU32(dst, afatfs_getContiguousFreeSpace() / 1024);
|
sbufWriteU32(dst, afatfs_getContiguousFreeSpace() / 1024);
|
||||||
sbufWriteU32(dst, sdcard_getMetadata()->numBlocks / 2); // Block size is half a kilobyte
|
sbufWriteU32(dst, sdcard_getMetadata()->numBlocks / 2); // Block size is half a kilobyte
|
||||||
|
} else {
|
||||||
|
sbufWriteU32(dst, 0);
|
||||||
|
sbufWriteU32(dst, 0);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
sbufWriteU8(dst, 0);
|
sbufWriteU8(dst, 0);
|
||||||
sbufWriteU8(dst, 0);
|
sbufWriteU8(dst, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue