Add initial LFS support for IMXRT

This commit is contained in:
robert committed 2026-12-04 17:46:41 +02:00
1 parent f3189519d8
commit 010fd33858
14 files changed
+208 -26

No files matched your search

+20
View File
@@ -74,6 +74,14 @@ 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/",
.enable_delete = true,
.enable_upload = true,
.enable_dir_listing = true,
};
mg_http_serve_dir(c, hm, &opts);
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
__asm volatile("udf #0"); // Trigger HardFault
} else {
@@ -108,6 +116,18 @@ int main(void) {
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
MG_INFO(("Crash record: %M", mg_print_crash_record));
// Create directory for Web file manager. Will be mapped to /files/ URL
if (!mg_lfs_init(MG_LFS_SIZE)) {
MG_ERROR(("LittleFS initialisation failed"));
} else {
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();