Skip to content

Commit d1aaa48

Browse files
Added user partition
1 parent b3a4e2c commit d1aaa48

File tree

8 files changed

+868
-92
lines changed

8 files changed

+868
-92
lines changed

flash.ld

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Flash Split for 4M chips */
2+
/* sketch @0x40200000 (~1019KB) (1044464B) */
3+
/* empty @0x402FEFF0 (~1028KB) (1052688B) */
4+
/* dashboard @0x40400000 (~1012KB) (1036288) */
5+
/* user 0x404FD000 (~1012KB) (1036288) */
6+
/* eeprom @0x405FB000 (4KB) */
7+
/* rfcal @0x405FC000 (4KB) */
8+
/* wifi @0x405FD000 (12KB) */
9+
10+
MEMORY
11+
{
12+
dport0_0_seg : org = 0x3FF00000, len = 0x10
13+
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
14+
iram1_0_seg : org = 0x40100000, len = 0x8000
15+
irom0_0_seg : org = 0x40201010, len = 0xfeff0
16+
}
17+
18+
PROVIDE ( _FS_start = 0x40400000 );
19+
PROVIDE ( _FS_end = 0x404FD000 );
20+
PROVIDE ( _FS_page = 0x100 );
21+
PROVIDE ( _FS_block = 0x2000 );
22+
PROVIDE ( _EEPROM_start = 0x405fb000 );
23+
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
24+
PROVIDE ( _SPIFFS_start = 0x40400000 );
25+
PROVIDE ( _SPIFFS_end = 0x404FD000 );
26+
PROVIDE ( _SPIFFS_page = 0x100 );
27+
PROVIDE ( _SPIFFS_block = 0x2000 );
28+
29+
INCLUDE "local.eagle.app.v6.common.ld"

led-matrix-display/CustomSPIFFS.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifdef ESP32
16+
17+
#include "vfs_api.h"
18+
19+
extern "C" {
20+
#include <sys/unistd.h>
21+
#include <sys/stat.h>
22+
#include <dirent.h>
23+
#include "esp_spiffs.h"
24+
}
25+
26+
#include "CustomSPIFFS.h"
27+
28+
using namespace fs;
29+
30+
class CustomSPIFFSImpl : public VFSImpl
31+
{
32+
public:
33+
CustomSPIFFSImpl();
34+
virtual ~CustomSPIFFSImpl() { }
35+
virtual bool exists(const char* path);
36+
};
37+
38+
CustomSPIFFSImpl::CustomSPIFFSImpl()
39+
{
40+
}
41+
42+
bool CustomSPIFFSImpl::exists(const char* path)
43+
{
44+
File f = open(path, "r");
45+
return (f == true) && !f.isDirectory();
46+
}
47+
48+
CustomSPIFFSFS::CustomSPIFFSFS() : FS(FSImplPtr(new CustomSPIFFSImpl()))
49+
{
50+
this->_partition = NULL;
51+
}
52+
53+
bool CustomSPIFFSFS::begin(bool formatOnFail, const char * partition, const char * basePath, uint8_t maxOpenFiles)
54+
{
55+
this->_partition = partition;
56+
57+
if(esp_spiffs_mounted(_partition)){
58+
log_w("SPIFFS Already Mounted!");
59+
return true;
60+
}
61+
62+
esp_vfs_spiffs_conf_t conf = {
63+
.base_path = basePath,
64+
.partition_label = _partition,
65+
.max_files = maxOpenFiles,
66+
.format_if_mount_failed = false
67+
};
68+
69+
esp_err_t err = esp_vfs_spiffs_register(&conf);
70+
if(err == ESP_FAIL && formatOnFail){
71+
if(format()){
72+
err = esp_vfs_spiffs_register(&conf);
73+
}
74+
}
75+
if(err != ESP_OK){
76+
log_e("Mounting SPIFFS failed! Error: %d", err);
77+
return false;
78+
}
79+
_impl->mountpoint(basePath);
80+
return true;
81+
}
82+
83+
void CustomSPIFFSFS::end()
84+
{
85+
if(esp_spiffs_mounted(_partition)){
86+
esp_err_t err = esp_vfs_spiffs_unregister(_partition);
87+
if(err){
88+
log_e("Unmounting SPIFFS failed! Error: %d", err);
89+
return;
90+
}
91+
_impl->mountpoint(_partition);
92+
}
93+
}
94+
95+
bool CustomSPIFFSFS::format()
96+
{
97+
disableCore0WDT();
98+
esp_err_t err = esp_spiffs_format(_partition);
99+
enableCore0WDT();
100+
if(err){
101+
log_e("Formatting SPIFFS failed! Error: %d", err);
102+
return false;
103+
}
104+
return true;
105+
}
106+
107+
size_t CustomSPIFFSFS::totalBytes()
108+
{
109+
size_t total,used;
110+
if(esp_spiffs_info(_partition, &total, &used)){
111+
return 0;
112+
}
113+
return total;
114+
}
115+
116+
size_t CustomSPIFFSFS::usedBytes()
117+
{
118+
size_t total,used;
119+
if(esp_spiffs_info(_partition, &total, &used)){
120+
return 0;
121+
}
122+
return used;
123+
}
124+
#endif

led-matrix-display/CustomSPIFFS.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifdef ESP32
15+
#ifndef _CUSTOM_SPIFFS_H_
16+
#define _CUSTOM_SPIFFS_H_
17+
18+
#include "FS.h"
19+
20+
class CustomSPIFFSFS : public FS
21+
{
22+
public:
23+
CustomSPIFFSFS();
24+
bool begin(bool formatOnFail=false, const char * partition="user", const char * basePath="/user", uint8_t maxOpenFiles=10);
25+
bool format();
26+
size_t totalBytes();
27+
size_t usedBytes();
28+
void end();
29+
30+
private:
31+
const char* _partition;
32+
};
33+
34+
#endif
35+
36+
#endif

0 commit comments

Comments
 (0)