Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

NodeMCU v1 ESP8266 - 펌웨어 내 파일 시스템(SPIFFS, LittleFS) 및 EEPROM 활용

Sketch 프로그램을 기기에 업로드한 후 고정된 프로그램이 실행되면서, 때로는 (데스크톱 운영체제 수준은 아니겠지만) 간단한 파일을 다루고 싶을 때가 있습니다. ESP8266 기기의 경우 이를 위해 SPIFFS(Serial Peripheral Interface Flash File System), LittleFS(Little Fail-Safe) 2가지 방식으로 접근할 수 있는데요,

Install ESP8266 Filesystem Uploader in Arduino IDE
; https://randomnerdtutorials.com/install-esp8266-filesystem-uploader-arduino-ide/

Install ESP8266 NodeMCU LittleFS Filesystem Uploader in Arduino IDE
; https://randomnerdtutorials.com/install-esp8266-nodemcu-littlefs-arduino/

littlefs-project/littlefs
; https://github.com/littlefs-project/littlefs

현재 SPIFFS는 deprecated 상태이고 이후 LittleFS 사용이 권장된다고 합니다. 기본적으로 이러한 파일 시스템 용으로 공간이 할당되는데, 아두이노 IDE에서 "Tools" / "Flash Size" 메뉴를 이용해 확인할 수 있습니다.

nodemcu_filesystem_1.png

위에서 보면 4가지 옵션이 나오고 선택은 첫 번째 항목으로 되어 있는데요,

  • 4MB (FS:2MB OTA:~1019KB)
  • 4MB (FS:3MB OTA:~512KB)
  • 4MB (FS:1MB OTA:~1019KB)
  • 4MB (FS:none OTA:~1019KB)

제가 가진 NodeMCU v1 ESP8266 개발 보드는 총 4MB의 플래시 크기를 갖기 때문에 모두 4MB라고 보입니다. (플래시 영역의 크기 및 Sketch 프로그램의 크기는 업로드 시 출력 결과를 통해서도 알 수 있습니다.)

"4MB (FS:2MB OTA:~1019KB)"는 파일 시스템 영역으로 2MB 할당하고 Sketch 프로그램의 영역으로 1019KB를 할당하고 있습니다. 그렇다면 1MB 정도의 영역이 남는데요, 이런 식으로 되는 것은 (저도 잘은 모르겠지만) Sketch 프로그램의 용량에 준하는 영역을 미리 예약하기 때문이라고 합니다. (즉, 현재 실행 중인 Sketch 영역과 새로 업데이트 되는 프로그램의 영역이 필요한 것입니다.)

"4MB (FS:3MB OTA:~512KB)"의 경우에는 파일 시스템 영역을 3MB까지 할당했기 때문에 Sketch 프로그램의 크기가 최대 512KB로 제한되고, 그와 동일한 크기로 512KB가 예비되는 것입니다. 반면, "4MB (FS:1MB OTA:~1019KB)" 항목이나, "4MB (FS:none OTA:~1019KB)"은 무슨 의미가 있는지 잘 모르겠습니다. 왜냐하면 Sketch의 최대 크기는 1MB로 제한이 되어 있기 때문에 결국 파일 시스템 용도로 할당하지 않는 다른 공간은 낭비가 되기 때문입니다. (혹시 이에 대해 기술적인 내용을 아시는 분은 덧글 부탁드립니다. ^^)

암튼, 저 공간을 SPIFFS, LittleFS 라이브러리를 이용해 자유롭게 사용하시면 됩니다.




때로는, 파일 시스템 정도는 아니고 더 작은 데이터를 유지하고 싶을 때도 있을 텐데요, 이런 경우는 512 바이트 고정 크기로 마련된 EEPROM을 사용하는 것도 가능합니다.

Read and write to the eeprom on the ESP8266
; http://www.esp8266learning.com/read-and-write-to-the-eeprom-on-the-esp8266.php

실제 사용 코드는 대략 다음과 같은 식으로 간단한 I/O를 할 수 있습니다.

#include <EEPROM.h>

void setup() 
{
  Serial.begin(115200);
  EEPROM.begin(512);

  char *text = "test";
  writeRom(0, text, strlen(text));
}

void loop() 
{  
  char buf[5] = { 0 };
  readRom(0, buf, 4);

  println(buf);

  delay(5000);
}

void println(char *text)
{
  Serial.write(text);
  Serial.write('\n');
}

void writeRom(int address, char *text, int textLen)
{
  for (int i = 0; i < textLen; i ++)
  {
    EEPROM.write(address + i, text[i]);
  }
}

void readRom(int address, char buffer[], int bufLen)
{
  for (int i = 0; i < bufLen; i ++)
  {
    buffer[i] = EEPROM.read(address + i);
  }
}

/* 출력 결과
(5초마다 test 문자열 출력 반복)
*/




이번에 검색하면서 알게 된 건데, ESP8266 보드 관련한 대부분의 프로젝트가 아래의 사이트에 실려 있으니,

120+ ESP8266 NodeMCU Projects, Tutorials and Guides with Arduino IDE
; https://randomnerdtutorials.com/projects-esp8266/

참고하시면 도움이 될 것입니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/13/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12207정성태4/2/202015734스크립트: 19. Windows PowerShell의 NonInteractive 모드
12206정성태4/2/202018376오류 유형: 613. 파일 잠금이 바로 안 풀린다면? - The process cannot access the file '...' because it is being used by another process.
12205정성태4/2/202015044스크립트: 18. Powershell에서는 cmd.exe의 명령어를 지원하진 않습니다.
12204정성태4/1/202015059스크립트: 17. Powershell 명령어에 ';' (semi-colon) 문자가 포함된 경우
12203정성태3/18/202017871오류 유형: 612. warning: 'C:\ProgramData/Git/config' has a dubious owner: '...'.
12202정성태3/18/202021143개발 환경 구성: 486. .NET Framework 프로젝트를 위한 GitLab CI/CD Runner 구성
12201정성태3/18/202018368오류 유형: 611. git-credential-manager.exe: Using credentials for username "Personal Access Token". [1]
12200정성태3/18/202018485VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
12199정성태3/17/202016125오류 유형: 610. C# - CodeDomProvider 사용 시 Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\f2_6uod0.tmp'.
12198정성태3/17/202019509오류 유형: 609. SQL 서버 접속 시 "Cannot open user default database. Login failed."
12197정성태3/17/202018754VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/202015929오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202018248.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202020972오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/202017862개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202019873개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202021013개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/202015552오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202021171개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202025989Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/202015510오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/202017378오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
12185정성태3/11/202017949오류 유형: 603. The browser service was unable to retrieve a list of servers from the browser master...
12184정성태3/11/202019880오류 유형: 602. Automatic certificate enrollment for local system failed (0x800706ba) The RPC server is unavailable. [3]
12183정성태3/11/202017679오류 유형: 601. Warning: DsGetDcName returned information for \\[...], when we were trying to reach [...].
12182정성태3/11/202019168.NET Framework: 901. C# Windows Forms - Vista/7 이후의 Progress Bar 업데이트가 느린 문제파일 다운로드1
... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...