Skip to content

Commit 120e009

Browse files
committed
Don't try and call any sd functions unless mounting was successful.
1 parent 92d38e1 commit 120e009

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

player/src/SDCard.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ SDCard::SDCard(gpio_num_t clk, gpio_num_t cmd, gpio_num_t d0, gpio_num_t d1, gpi
6464
Serial.printf("SDCard mounted at: %s\n", MOUNT_POINT);
6565
// Card has been initialized, print its properties
6666
sdmmc_card_print_info(stdout, m_card);
67+
sd_card_init_success = true;
6768
#endif
6869
}
6970

@@ -123,6 +124,7 @@ SDCard::SDCard(gpio_num_t miso, gpio_num_t mosi, gpio_num_t clk, gpio_num_t cs)
123124
Serial.printf("SDCard mounted at: %s\n", MOUNT_POINT);
124125
// Card has been initialized, print its properties
125126
sdmmc_card_print_info(stdout, m_card);
127+
sd_card_init_success = true;
126128
}
127129

128130
SDCard::~SDCard()
@@ -135,7 +137,10 @@ SDCard::~SDCard()
135137

136138

137139
bool SDCard::isMounted() {
138-
return sdmmc_get_status(m_card) == ESP_OK;
140+
if (sd_card_init_success) {
141+
return sdmmc_get_status(m_card) == ESP_OK;
142+
}
143+
return false;
139144
}
140145

141146
std::vector<std::string> SDCard::listFiles(const char *folder, const char *extension)

player/src/SDCard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SDCard
1717
#else
1818
sdmmc_host_t m_host = SDSPI_HOST_DEFAULT();
1919
#endif
20+
bool sd_card_init_success = false;
2021
public:
2122
SDCard(gpio_num_t miso, gpio_num_t mosi, gpio_num_t clk, gpio_num_t cs);
2223
SDCard(gpio_num_t clk, gpio_num_t cmd, gpio_num_t d0, gpio_num_t d1, gpio_num_t d2, gpio_num_t d3);

0 commit comments

Comments
 (0)