mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
LFS nits
This commit is contained in:
1 parent
f62f3545b4
commit
81f6acbce7
19 files changed
+258
-128
No files matched your search
@@ -150,7 +150,7 @@ static bool graph1_fn(enum mg_dash_op op, struct mg_dash_user *u) {
|
||||
return true;
|
||||
}
|
||||
static struct mg_field_set set_graph1 = {"graph1", fields_graph1, graph1_fn,
|
||||
NULL, NULL};
|
||||
NULL, NULL};
|
||||
|
||||
#define NUM_POINTS_GRAPH2 100 // How many graph2 data points to send
|
||||
static char s_graph2_data[NUM_POINTS_GRAPH2 * 4 + 2 + 1];
|
||||
@@ -218,6 +218,7 @@ void mg_dash_init(struct mg_mgr *mgr) {
|
||||
|
||||
#if MG_ARCH == MG_ARCH_UNIX
|
||||
// Create demo files in the upload directory
|
||||
mkdir("/tmp", 0755);
|
||||
mkdir("/tmp/dashboard", 0755);
|
||||
mg_file_printf(&mg_fs_posix, "/tmp/dashboard/device-config.json",
|
||||
"{\"model\":\"example\",\"fw\":\"1.0\"}");
|
||||
|
||||
@@ -778,15 +778,22 @@ a, a:visited, a:link { text-decoration: none; }
|
||||
</div>
|
||||
|
||||
<div class="note">
|
||||
<p>The two default files are fake - you can delete them</p>
|
||||
<p>However the manager works - you can upload new files. They
|
||||
are uploaded to /tmp/ directory on the device.
|
||||
This requires stdio (fopen/fread/...) implemeneted.</p>
|
||||
<p>The easiest way to implement it is to use a filesystem like
|
||||
LittleFS on your internal or external flash
|
||||
and retarget the standard library to use it.</p>
|
||||
<p>See <a href="https://github.com/cpq/bare-metal-programming-guide/tree/main/templates/lfs/nucleo-h563zi">this example</a> on how LittleFS can be implemented on
|
||||
Nucleo-H563ZI internal flash partition.</p>
|
||||
<p>This file manager uses /tmp/dashboard/ directory.
|
||||
It works on any platform that supports
|
||||
standard file IO: fopen, fread, fwrite, fclose.
|
||||
This includes Linux/Mac/Windows.</p>
|
||||
<p>
|
||||
Mongoose provides a built-in LittleFS integration that
|
||||
makes stadard file IO work on embedded systems like STM32.
|
||||
For that, add "#define MG_ENABLE_LFS 1" to your
|
||||
mongoose_config.h
|
||||
</p>
|
||||
<p>See
|
||||
<a href="https://github.com/cesanta/embedded-web-file-manager">this ready-to-build example</a>
|
||||
which implements LittleFS on Nucleo-H563ZI internal flash. You
|
||||
can upload, delete and serve files on STM32 - which is
|
||||
a perfect use case for confuration files, keeping and viewing logs, etc.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
# Copyright (c) 2026 Cesanta Software Limited
|
||||
# Environment setup: https://mongoose.ws/docs/getting-started/build-environment/
|
||||
|
||||
MGDIR = ../../../..
|
||||
|
||||
CFLAGS = -W -Wall -Wextra -Wundef -Wshadow -Wdouble-promotion
|
||||
CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion
|
||||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
||||
CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_h5/Include -Imongoose
|
||||
CFLAGS += -I. -I$(MGDIR) -Icmsis_core/CMSIS/Core/Include -Icmsis_h5/Include -Imongoose
|
||||
CFLAGS += -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard $(CFLAGS_EXTRA)
|
||||
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
|
||||
|
||||
SOURCES = main.c hal.c
|
||||
SOURCES += littlefs/lfs.c littlefs/lfs_util.c
|
||||
SOURCES += cmsis_h5/Source/Templates/gcc/startup_stm32h563xx.s
|
||||
SOURCES += mongoose/mongoose.c
|
||||
SOURCES += $(MGDIR)/mongoose.c
|
||||
|
||||
# Disabled for littlefs/lfs.c
|
||||
CFLAGS += -Wno-conversion -Wno-shadow
|
||||
|
||||
all build example: firmware.bin
|
||||
|
||||
mongoose/mongoose.c mongoose/mongoose.h:
|
||||
cp ../../../../mongoose.[ch] mongoose/
|
||||
|
||||
firmware.elf: cmsis_core cmsis_h5 hal.h link.ld Makefile $(SOURCES) mongoose/mongoose.h
|
||||
firmware.elf: cmsis_core cmsis_h5 littlefs hal.h link.ld Makefile $(SOURCES) $(MGDIR)/mongoose.h
|
||||
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(CFLAGS_EXTRA) $(LDFLAGS) -o $@
|
||||
|
||||
firmware.bin: firmware.elf
|
||||
@@ -42,6 +45,10 @@ cmsis_core:
|
||||
cmsis_h5:
|
||||
git clone -q -c advice.detachedHead=false --depth 1 -b v1.6.0 https://github.com/STMicroelectronics/cmsis-device-h5 $@
|
||||
|
||||
littlefs/lfs.c littlefs/lfs_util.c: littlefs
|
||||
littlefs:
|
||||
git clone -q -c advice.detachedHead=false --depth 1 -b v2.11.3 https://github.com/littlefs-project/littlefs $@
|
||||
|
||||
clean:
|
||||
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
||||
|
||||
|
||||
@@ -45,8 +45,20 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
||||
} else if (mg_match(hm->uri, mg_str("/files/#"), NULL)) {
|
||||
struct mg_http_serve_opts opts = {
|
||||
.root_dir = "/files/=/fs/",
|
||||
.allow_delete = true,
|
||||
.allow_upload = true,
|
||||
};
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
} else {
|
||||
mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", hal_get_tick());
|
||||
size_t u = hal_ram_used(), t = u + hal_ram_free();
|
||||
mg_http_reply(c, 200, "",
|
||||
"Hi from Mongoose!\n"
|
||||
"Tick %llu\n"
|
||||
"RAM usage: %zu / %zu (%zu %%)\n",
|
||||
hal_get_tick(), u, t, (size_t) (100 * u / t));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +79,14 @@ int main(void) {
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
||||
|
||||
// Create directory for Web file manager. Will be mapped to /files/ URL
|
||||
mkdir("/fs", 0755);
|
||||
MG_INFO(("File manager operations:"));
|
||||
MG_INFO(("Upload: curl IP/files/NAME --data-binary @FILE"));
|
||||
MG_INFO(("Delete: curl IP/files/NAME -X DELETE"));
|
||||
MG_INFO(("Show: curl IP/files/NAME"));
|
||||
MG_INFO(("List: curl IP/files/"));
|
||||
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
blink_task();
|
||||
|
||||
+5
@@ -12,6 +12,11 @@
|
||||
#define MG_ENABLE_PACKED_FS 1
|
||||
#define MG_ENABLE_DRIVER_STM32H 1
|
||||
|
||||
#define MG_ENABLE_LFS 1 // Enable POSIX filesystem on interfal flash using LFS
|
||||
#define MG_LFS_SIZE (1024 * 128) // Must be multiple of H5 8Kb sectors
|
||||
#define MG_OTA MG_OTA_STM32H5 // MG_OTA required for LFS, for flash usage
|
||||
#define MG_ENABLE_LINES 1
|
||||
|
||||
// #define MG_DRIVER_MDC_CR 4 // RMII MDC clock divider, from 0 to 4
|
||||
// #define MG_TCPIP_PHY_ADDR 0 // PHY address
|
||||
|
||||
Whitespace-only changes.
Reference in new issue
Block a user