Skip to content

Commit

Permalink
Merge pull request #14 from tobozo/1.0.5
Browse files Browse the repository at this point in the history
1.0.5
  • Loading branch information
tobozo authored Jun 14, 2024
2 parents 03dc80b + f71d95f commit 4439159
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
13 changes: 11 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# ESP32-PsRamFS

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32-PSRamFS.svg?)](https://www.ardu-badge.com/ESP32-PSRamFS)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/tobozo/library/ESP32-PSRamFS.svg)](https://registry.platformio.org/packages/libraries/tobozo/ESP32-PSRamFS)


![](extras/logo.jpeg)




Coding Horror
-------------

Expand Down Expand Up @@ -33,6 +38,8 @@ void setup()

Serial.begin(115200);

PSRamFS.setPartitionSize( ESP.getFreePsram()/2 ); // use half of psram

if(!PSRamFS.begin()){
Serial.println("PSRamFS Mount Failed");
return;
Expand Down Expand Up @@ -61,9 +68,11 @@ Tested on:
- ESP32-Wroom
- ESP32-Wrover
- ESP32-S2
- ESP32-S3
- ESP32-C3



Known issues:
------------

Expand All @@ -74,7 +83,7 @@ Known issues:



Credits:
Credits/thanks:
--------

- [lbernstone](https://github.com/lbernstone) special thanks for assisting me in this experience
Expand All @@ -83,6 +92,6 @@ Credits:
- [Bill Greiman](https://github.com/greiman/RamDisk)
- [lorolol](https://github.com/lorol)
- [sharandac](https://github.com/sharandac)

- [Rob58329](https://github.com/Rob58329)


4 changes: 4 additions & 0 deletions examples/PSRamFS_Test/PSRamFS_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ void setup()
UNITY_END(); // stop unit testing
#endif

if( ! PSRamFS.setPartitionSize( ESP.getFreePsram()/2 ) ) { // try to allocate half of psram
Serial.println("Failed to allocate half of PSRam, will use heap instead");
}

// - testing the fs::FS layer from PSRamFS.cpp
if(!PSRamFS.begin()){
ESP_LOGE(TAG, "PSRamFS Mount Failed");
Expand Down
2 changes: 2 additions & 0 deletions examples/PSRamFS_Test/tests/vfs_pfs_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ int vfs_pfs_closedir(DIR* pdir);
#define pfs_partition_label "psram"
#define pfs_base_path "/psram"

static const char TAG[] = "test";

static const char pfs_test_partition_label[] = pfs_partition_label;
static const char pfs_test_hello_str[] = "Hello, World!\n";
static const char pfs_test_filename[] = pfs_base_path "/hello.txt";
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP32-PSRamFS
version=1.0.3-beta
version=1.0.5
author=tobozo <tobozo@noreply.github.com>
maintainer=tobozo <tobozo@noreply.github.com>
sentence="ESP32 RamDisk for PSRAM and fs::FS"
Expand Down
18 changes: 10 additions & 8 deletions src/PSRamFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ F_PSRam::F_PSRam(FSImplPtr impl)

bool F_PSRam::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
{

if( pfs_get_files() != NULL ) {
log_w("Filesystem already mounted");
return true;
Expand All @@ -52,8 +51,8 @@ bool F_PSRam::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFil
pfs_set_psram( false );
pfs_set_partition_size( 100*1024 /*0.25 * ESP.getFreeHeap()*/ );
} else {
//pfs_set_psram( true );
pfs_set_partition_size( FPSRAM_PARTITION_SIZE * ESP.getFreePsram() );
if( partitionSize == 0 ) partitionSize = FPSRAM_PARTITION_SIZE * ESP.getFreePsram();
pfs_set_partition_size( partitionSize );
}

esp_vfs_pfs_conf_t conf = {
Expand Down Expand Up @@ -85,7 +84,6 @@ bool F_PSRam::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFil
}



void F_PSRam::end()
{
pfs_deinit();
Expand All @@ -94,6 +92,14 @@ void F_PSRam::end()
}


bool F_PSRam::setPartitionSize(size_t size_bytes)
{
if (!psramInit() ) return false;
if( size_bytes==0 || size_bytes>ESP.getFreePsram() ) return false;
partitionSize = size_bytes;
return true;
}


bool F_PSRam::format(bool full_wipe, char* partitionLabel)
{
Expand All @@ -102,7 +108,6 @@ bool F_PSRam::format(bool full_wipe, char* partitionLabel)
}



size_t F_PSRam::totalBytes()
{
return pfs_get_partition_size();
Expand Down Expand Up @@ -133,22 +138,19 @@ size_t F_PSRam::usedBytes()
}



size_t F_PSRam::freeBytes()
{
return totalBytes() - usedBytes();
}



bool F_PSRam::exists(const char* path)
{
File f = open(path, "r");
return (f == true) && !f.isDirectory();
}



bool F_PSRam::exists(const String& path)
{
return exists(path.c_str());
Expand Down
1 change: 1 addition & 0 deletions src/PSRamFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace fs
void end();
bool exists(const char* path);
bool exists(const String& path);
bool setPartitionSize(size_t size_bytes);
virtual void **getFiles();
virtual void **getFolders();
virtual size_t getFilesCount();
Expand Down
30 changes: 19 additions & 11 deletions src/pfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@
#include "esp_log.h"


#if !defined CONFIG_SPIRAM_SUPPORT
#if defined BOARD_HAS_PSRAM || defined CONFIG_SPIRAM_SUPPORT
#warning "Will use PSRAM or heap"
#elif !defined CONFIG_SPIRAM_SUPPORT
#warning "No SPIRAM detected, will use heap"
#endif

// for SPIRAM detection support
// for PSRAM/SPIRAM detection support
#ifdef CONFIG_IDF_CMAKE // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/spiram.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/spiram.h"
#include "esp32s2/rom/cache.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/spiram.h"
#include "esp32s3/rom/cache.h"
#if __has_include("esp_psram.h") // IDF 5+, all devices
#include "esp_psram.h"
static int esp_spiram_init(void) { esp_psram_init(); return esp_psram_is_initialized()?ESP_OK:-1; }
#else
#error Target CONFIG_IDF_TARGET is not supported
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/spiram.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/spiram.h"
#include "esp32s2/rom/cache.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/spiram.h"
#include "esp32s3/rom/cache.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif

#endif
#else // ESP32 Before IDF 4.0
#include "esp_spiram.h"
Expand Down

0 comments on commit 4439159

Please sign in to comment.