Skip to content

Commit 45df494

Browse files
pennampennam
authored andcommitted
Mount function included in mbed lib
1 parent f5de594 commit 45df494

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -328,50 +328,59 @@ void arduino::WiFiClass::feedWatchdog()
328328

329329
#if defined(COMPONENT_4343W)
330330

331-
#include "QSPIFBlockDevice.h"
332-
#include "MBRBlockDevice.h"
333-
#include "FATFileSystem.h"
334-
335-
#define WIFI_FIRMWARE_PATH "/wlan/4343WA1.BIN"
336-
337-
QSPIFBlockDevice root(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
338-
mbed::MBRBlockDevice wifi_data(&root, 1);
339-
mbed::FATFileSystem wifi_data_fs("wlan");
331+
#define WIFI_FIRMWARE_NAME "4343WA1.BIN"
340332

341333
bool firmware_available = false;
334+
static std::string fullname;
335+
336+
#include "wiced_filesystem.h"
337+
#include "resources.h"
342338

343-
extern "C" bool wiced_filesystem_mount() {
344-
mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024);
345-
int err = wifi_data_fs.mount(&wifi_data);
346-
if (err) {
339+
void wiced_filesystem_mount_error(void) {
347340
Serial.println("Failed to mount the filesystem containing the WiFi firmware.");
348341
Serial.println("Usually that means that the WiFi firmware has not been installed yet"
349342
" or was overwritten with another firmware.");
350-
goto error;
351-
}
352-
353-
DIR *dir;
354-
struct dirent *ent;
355-
if ((dir = opendir("/wlan")) != NULL) {
356-
/* print all the files and directories within directory */
357-
while ((ent = readdir(dir)) != NULL) {
358-
String fullname = "/wlan/" + String(ent->d_name);
359-
if (fullname == WIFI_FIRMWARE_PATH) {
360-
closedir(dir);
361-
firmware_available = true;
362-
return true;
363-
}
343+
whd_print_logbuffer();
344+
while (1) {}
345+
}
346+
347+
void wiced_filesystem_firmware_error(void) {
348+
Serial.println("Please run the \"PortentaWiFiFirmwareUpdater\" sketch once to install the WiFi firmware.");
349+
whd_print_logbuffer();
350+
while (1) {}
351+
}
352+
353+
wiced_result_t whd_firmware_check_hook(const char *mounted_name, int mount_err)
354+
{
355+
DIR *dir;
356+
struct dirent *ent;
357+
std::string dir_name(mounted_name);
358+
if(mount_err) {
359+
wiced_filesystem_mount_error();
360+
} else {
361+
if ((dir = opendir(mounted_name)) != NULL) {
362+
// print all the files and directories within directory
363+
while ((ent = readdir(dir)) != NULL) {
364+
fullname = "/"+ dir_name + "/" + std::string(ent->d_name);
365+
if (std::string(ent->d_name) == WIFI_FIRMWARE_NAME) {
366+
closedir(dir);
367+
firmware_available = true;
368+
// Update Mbed resource default mount point /wlan
369+
wifi_firmware_image.val.fs.filename = (const char*)fullname.c_str();
370+
//Serial.println(fullname.c_str());
371+
//Serial.println((char*)(wifi_firmware_image.val.fs.filename));
372+
return WICED_SUCCESS;
373+
}
374+
}
375+
Serial.println("File not found");
376+
closedir(dir);
377+
}
378+
wiced_filesystem_firmware_error();
364379
}
365-
Serial.println("File not found");
366-
closedir(dir);
367-
}
368-
error:
369-
Serial.println("Please run the \"PortentaWiFiFirmwareUpdater\" sketch once to install the WiFi firmware.");
370-
whd_print_logbuffer();
371-
while (1) {}
372-
return false;
380+
return WICED_ERROR;
373381
}
374382

383+
375384
#include "whd_version.h"
376385
char* arduino::WiFiClass::firmwareVersion() {
377386
if (firmware_available) {

0 commit comments

Comments
 (0)