From ba0af4080878c3280fb6e78bc8173d6703962789 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 18 Oct 2018 13:15:31 +0700 Subject: [PATCH] make internal fs work with or without SD enable --- cores/nRF5/flash/flash_nrf52.c | 25 ++++++++++++++----- .../Internal_ListFiles/Internal_ListFiles.ino | 8 ++---- .../Internal_ReadWrite/Internal_ReadWrite.ino | 14 +++++------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/cores/nRF5/flash/flash_nrf52.c b/cores/nRF5/flash/flash_nrf52.c index e0cbdff3..d8e81986 100644 --- a/cores/nRF5/flash/flash_nrf52.c +++ b/cores/nRF5/flash/flash_nrf52.c @@ -36,6 +36,7 @@ #include "flash_nrf52.h" #include "flash_cache.h" +#include "nrf_sdm.h" #include "nrf_soc.h" #include "rtos.h" @@ -109,10 +110,16 @@ bool fal_erase (uint32_t addr) } VERIFY_STATUS(err); - // wait until complete - xSemaphoreTake(_sem, portMAX_DELAY); - VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS); + // wait for async event if SD is enabled + uint8_t sd_en = 0; + (void) sd_softdevice_is_enabled(&sd_en); + if ( sd_en ) + { + xSemaphoreTake(_sem, portMAX_DELAY); + VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS); + } + return true; } @@ -126,9 +133,15 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len) } VERIFY_STATUS(err); - // wait until complete - xSemaphoreTake(_sem, portMAX_DELAY); - VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS); + // wait for async event if SD is enabled + uint8_t sd_en = 0; + (void) sd_softdevice_is_enabled(&sd_en); + + if ( sd_en ) + { + xSemaphoreTake(_sem, portMAX_DELAY); + VERIFY(_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS); + } return len; } diff --git a/libraries/FileSystem/examples/Internal_ListFiles/Internal_ListFiles.ino b/libraries/FileSystem/examples/Internal_ListFiles/Internal_ListFiles.ino index 2f6aa2a7..22e64739 100644 --- a/libraries/FileSystem/examples/Internal_ListFiles/Internal_ListFiles.ino +++ b/libraries/FileSystem/examples/Internal_ListFiles/Internal_ListFiles.ino @@ -31,12 +31,8 @@ void setup() Serial.begin(115200); Serial.println("InternalFS List Files Example"); - // Bluefruit module must be initialized for Nffs to work - // Since Bluefruit's SOC event handling task is required for flash operation - Bluefruit.begin(); - - // Initialize Nffs - //Nffs.begin(); + // Initialize Internal File System + InternalFS.begin(); // Print whole directory tree of root whose level is 0 printTreeDir("/", 0); diff --git a/libraries/FileSystem/examples/Internal_ReadWrite/Internal_ReadWrite.ino b/libraries/FileSystem/examples/Internal_ReadWrite/Internal_ReadWrite.ino index ba751a87..1729bd7e 100644 --- a/libraries/FileSystem/examples/Internal_ReadWrite/Internal_ReadWrite.ino +++ b/libraries/FileSystem/examples/Internal_ReadWrite/Internal_ReadWrite.ino @@ -15,7 +15,8 @@ #include #include -#define FILENAME "/adafruit.txt" +#define FILENAME "/testdir1/ada2.txt" + #define CONTENTS "Bluefruit Feather52's file contents" File file(InternalFS); @@ -38,12 +39,8 @@ void setup() Serial.println(); Serial.println(); - // Bluefruit module must be initialized for Nffs to work - // Since Bluefruit's SOC event handling task is required for flash operation - Bluefruit.begin(); - - // Initialize Nffs - //Nffs.begin(); + // Initialize Internal File System + InternalFS.begin(); file.open(FILENAME, FILE_READ); @@ -61,6 +58,7 @@ void setup() file.close(); }else { + InternalFS.mkdir("/testdir1"); Serial.print("Open " FILENAME " file to write ... "); if( file.open(FILENAME, FILE_WRITE) ) @@ -70,7 +68,7 @@ void setup() file.close(); }else { - Serial.println("Failed to open file to write"); + Serial.println("Failed!"); } } }