Getting a "PermissionError" while scanning directories inside "/spiflash"
Posted: Sun May 31, 2020 6:22 am
I am sure that I have written multiple files inside the "/spiflash" folder, I always get the error, but I did not get it when I scanned the root directory which is "/" and I got nothing on the console while scanning it. Based on my searches, this error is related to the python tool that is communicating with the ESP32. It only happened to me when I am reading the directories and printing them to the console. And this is the traceback:
Notice that I have "????????.???" as the name of the file, so weird. This is the application code, so simple:
If there is another way to scan the directories easily, please enlighten me. I will appreciate anything that helps to solve my issue.
Code: Select all
I (317) example: Mounting FAT filesystem
name | type | fileno
Traceback (most recent call last):
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 865, in <module>
main()
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 777, in main
monitor.main_loop()
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 379, in main_loop
self.handle_serial_input(data)
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 439, in handle_serial_input
self._print(line + b'\n')
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 681, in _print
console_printer(string)
File "C:\Users\Hassan\.espressif\python_env\idf4.0_py3.7_env\lib\site-packages
\serial\tools\miniterm.py", line 64, in write_bytes
self.byte_output.flush()
File "C:\Users\Hassan\Documents\Arduino\ESP\esp-idf\tools/idf_monitor.py", lin
e 862, in flush
self.output.flush()
PermissionError: [WinError 31] A device attached to the system is not functionin
g
????????.??? | 2 | 0
idf_monitor failed with exit code 1
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include "esp_vfs.h"
#include "esp_vfs_fat.h"
#include "esp_system.h"
static const char *TAG = "example";
static wl_handle_t s_wl_handle = WL_INVALID_HANDLE;
const char *base_path = "/spiflash";
extern "C" {
void app_main(void );
}
void app_main(void)
{
ESP_LOGI(TAG, "Mounting FAT filesystem");
const esp_vfs_fat_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 4,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
esp_err_t err = esp_vfs_fat_spiflash_mount(base_path, "storage", &mount_config, &s_wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
}
DIR *d;
struct dirent *dir;
d = opendir("/spiflash");
if (d)
{
printf("%10s | %4s | %s\n", "name", "type", "fileno");
dir = readdir(d);
while ((dir = readdir(d)) != NULL)
{
printf("%10s | %4d | %2d\n", dir->d_name, dir->d_type, dir->d_ino);
}
closedir(d);
} else {
printf("The file is empty!\n");
}
ESP_LOGI(TAG, "Unmounting FAT filesystem");
ESP_ERROR_CHECK( esp_vfs_fat_spiflash_unmount(base_path, s_wl_handle));
ESP_LOGI(TAG, "Done");
}