Commit 2e202796 authored by Marcel Stör's avatar Marcel Stör
Browse files

Fix LFS Markdown syntax

Contributes to #2432
parent a405fea4
...@@ -4,70 +4,77 @@ ...@@ -4,70 +4,77 @@
LFS is a way how to execute your Lua code out of ESP8266 flash memory so more RAM is available for variables and data structures. This way large Lua files can be run on ESP8266. There would not be enough RAM to execute such files in a "normal" (out of SPIFFS) way. LFS is a way how to execute your Lua code out of ESP8266 flash memory so more RAM is available for variables and data structures. This way large Lua files can be run on ESP8266. There would not be enough RAM to execute such files in a "normal" (out of SPIFFS) way.
The tutorial assumes that you are able to build a nodemcu-firmware on a Windows 10 host. The tutorial assumes that you are able to build a NodeMCU firmware on a Windows 10 host.
This is a simple step-by-step how to use the LFS feature: This is a simple step-by-step recipe how to use the LFS feature.
1. Get and flash LFS enabled firmware
Either you get it from [NodeMCU Build](https://nodemcu-build.com/). In the section "LFS options (currently just for dev)" choose the size of the LFS partition (64 KB should be fine). SPIFFS default settings should be fine. ### Get and flash LFS enabled firmware
Get the firmware from [NodeMCU Build](https://nodemcu-build.com/). In the section "LFS options (currently just for dev)" choose the size of the LFS partition (64 KB should be fine). SPIFFS default settings should be fine.
Another possibility is to compile own firmware and enable LFS in [user_config.h](../../app/include/user_config.h), setting `#define LUA_FLASH_STORE 0x10000`. This file includes explanation of how to configure LFS in its comments. Another possibility is to compile your own firmware and enable LFS in [user_config.h](../../app/include/user_config.h), setting `#define LUA_FLASH_STORE 0x10000`. This file includes explanations for how to configure LFS in its comments.
For details see section [Selecting the firmware](###Selecting-the-firmware) of the LFS documentation. For details see section [Selecting the firmware](#selecting-the-firmware) of the LFS documentation below.
Flash the firmware to ESP8266. [Flash the firmware](flash.md) to ESP8266.
2. Select Lua files to be run from LFS ### Select Lua files to be run from LFS
The easest way is to maintain Lua files of your project in its own directory tree on your host. Project files will be compiled by `luac.cross` to build the LFS image in next step. The easiest way is to maintain Lua files of your project in its own directory tree on your host. Project files will be compiled by `luac.cross` to build the LFS image in next step.
Nice example is to run telnet and ftp client from LFS. In order to do this put the following files in 1 directory: A nice example is to run Telnet and FTP servers from LFS. In order to do this put the following files in 1 directory:
* [lua_examples/lfs/_init.lua](../../lua_examples/lfs/_init.lua)
* [lua_examples/lfs/dummy_strings.lua](../../lua_examples/lfs/dummy_strings.lua) * [lua_examples/lfs/_init.lua](../../lua_examples/lfs/_init.lua)
* [lua_examples/telnet/telnet.lua](../../lua_examples/telnet/telnet.lua) * [lua_examples/lfs/dummy_strings.lua](../../lua_examples/lfs/dummy_strings.lua)
* [lua_modules/ftp/ftpserver.lua](../../lua_modules/ftp/ftpserver.lua) * [lua_examples/telnet/telnet.lua](../../lua_examples/telnet/telnet.lua)
* [lua_modules/ftp/ftpserver.lua](../../lua_modules/ftp/ftpserver.lua)
3. Build the LFS image
### Build the LFS image
Windows 10 users can use the Windows Subsystem for Linux. From the directory with Lua files from the previous section run `bash` and execute the command (adjust the path as needed):
```bash Windows 10 users can use the Windows Subsystem for Linux. From the directory with Lua files from the previous section run `bash` and execute the command (adjust the path as needed):
/mnt/c/GitHub/nodemcu-firmware/luac.cross -f *.lua
``` ```bash
or the following command which includes all Lua files except `init.lua` into LFS image can be used (`init.lua` needs to be in SPIFFS so it does not make sense to include it in the LFS image) /mnt/c/GitHub/nodemcu-firmware/luac.cross -f *.lua
```bash ```
/mnt/c/GitHub/nodemcu-firmware/luac.cross -f `find *.lua -not -name 'init.lua'`
``` Or the following command which includes all Lua files except `init.lua` (`init.lua` needs to be in SPIFFS so it does not make sense to include it in the LFS image)
As a result the `luac.out` file is created.
```bash
4. Upload the LFS image /mnt/c/GitHub/nodemcu-firmware/luac.cross -f `find *.lua -not -name 'init.lua'`
```
Now it's time to upload the generate LFS image file (`luac.out`) as a normal SPIFFS file. Several tools can be used to upload the files from host to SPIFFS.
As a result the `luac.out` file is created.
One way is to use the [ESPlorer](https://github.com/4refr0nt/ESPlorer) tool, button "Upload...".
### Upload the LFS image
5. Flash the LFS image to LFS partition
Now upload the generate LFS image file (`luac.out`) as a normal SPIFFS file. Several tools can be used to upload the files from host to SPIFFS.
Run the following command on ESP
```Lua
node.flashreload("luac.out")
```
The firmware will reboot the ESP8266 and modules will be available after reboot.
6. Adjust the `init.lua` file
`init.lua` is the file that is first executed by the NodeMCU firmware. Usually it setups the wifi connection and executes the main Lua file.
Add the following lines: One way is to use the [ESPlorer](https://github.com/4refr0nt/ESPlorer) tool, button "Upload...".
```Lua ### Flash the LFS image to LFS partition
-- Execute the LFS init
node.flashindex("_init")() Run the following command on ESP
-- Start telnet server
require("telnet"):open() ```lua
-- Start ftp serer node.flashreload("luac.out")
require("ftpserver").createServer('user', 'password') ```
```
The firmware will reboot the ESP8266 and modules will be available after reboot.
### Adjust the `init.lua` file
`init.lua` is the file that is first executed by the NodeMCU firmware. Usually it setups the wifi connection and executes the main Lua file.
Add the following lines:
```lua
-- Execute the LFS init
node.flashindex("_init")()
-- Start Telnet server
require("telnet"):open()
-- Start FTP serer
require("ftpserver").createServer('user', 'password')
```
## Background ## Background
An IoT device such as the ESP8266 has very different processor characteristics from the CPU in a typical PC: An IoT device such as the ESP8266 has very different processor characteristics from the CPU in a typical PC:
......
...@@ -33,8 +33,8 @@ pages: ...@@ -33,8 +33,8 @@ pages:
- Whitepapers: - Whitepapers:
- Filesystem on SD card: 'en/sdcard.md' - Filesystem on SD card: 'en/sdcard.md'
- Internal filesystem: 'en/spiffs.md' - Internal filesystem: 'en/spiffs.md'
- Lua Compact Debug(LCD): 'en/lcd.md' - Lua Compact Debug (LCD): 'en/lcd.md'
- Lua Flash Store(LFS): 'en/lfs.md' - Lua Flash Store (LFS): 'en/lfs.md'
- Modules: - Modules:
- 'adc': 'en/modules/adc.md' - 'adc': 'en/modules/adc.md'
- 'ads1115' : 'en/modules/ads1115.md' - 'ads1115' : 'en/modules/ads1115.md'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment