diff --git a/tutorials/nxp/frdm-imxrt1186/minimal/Makefile b/tutorials/nxp/frdm-imxrt1186/minimal/Makefile index 79a9cb3f..d009b223 100644 --- a/tutorials/nxp/frdm-imxrt1186/minimal/Makefile +++ b/tutorials/nxp/frdm-imxrt1186/minimal/Makefile @@ -10,7 +10,7 @@ CFLAGS += -Icmsis_rt1186/devices/MIMXRT1186/ -Icmsis_rt1186/devices/MIMXRT1186/p CFLAGS += -DCPU_MIMXRT1186CVJ8C_cm33 -DCPU_MIMXRT1186CVJ8C -DMIMXRT1186_cm33_SERIES CFLAGS += -DXIP_EXTERNAL_FLASH=1 -DXIP_BOOT_HEADER_ENABLE=1 CFLAGS += -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c SOURCES += cmsis_rt1186/devices/MIMXRT1186/gcc/startup_MIMXRT1186_cm33.S @@ -44,5 +44,9 @@ cmsis_rt1186: unzip -q NXP.MIMXRT1186_DFP.26.06.00.pack -d $@ rm NXP.MIMXRT1186_DFP.26.06.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/frdm-imxrt1186/minimal/hal.c b/tutorials/nxp/frdm-imxrt1186/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/frdm-imxrt1186/minimal/hal.c +++ b/tutorials/nxp/frdm-imxrt1186/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/frdm-imxrt1186/minimal/main.c b/tutorials/nxp/frdm-imxrt1186/minimal/main.c index 13c0331f..b1cd108d 100644 --- a/tutorials/nxp/frdm-imxrt1186/minimal/main.c +++ b/tutorials/nxp/frdm-imxrt1186/minimal/main.c @@ -42,9 +42,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -65,6 +71,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/nxp/frdm-mcxe247/minimal/Makefile b/tutorials/nxp/frdm-mcxe247/minimal/Makefile index e6cf65f7..b08b05e1 100644 --- a/tutorials/nxp/frdm-mcxe247/minimal/Makefile +++ b/tutorials/nxp/frdm-mcxe247/minimal/Makefile @@ -9,7 +9,7 @@ CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ CFLAGS += -Icmsis_mcxe247/devices/MCXE247/ -Icmsis_mcxe247/devices/MCXE247/periph0/ -Icmsis_mcxe247/devices/MCXE247/drivers/ CFLAGS += -DCPU_MCXE247VLQ -DCPU_MCXE247VLQ_cm4 CFLAGS += -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c mongoose/mongoose.c SOURCES += cmsis_mcxe247/devices/MCXE247/gcc/startup_MCXE247.S @@ -38,5 +38,9 @@ cmsis_mcxe247: unzip -q NXP.MCXE247_DFP.26.06.00.pack -d $@ rm NXP.MCXE247_DFP.26.06.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/frdm-mcxe247/minimal/hal.c b/tutorials/nxp/frdm-mcxe247/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/frdm-mcxe247/minimal/hal.c +++ b/tutorials/nxp/frdm-mcxe247/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/frdm-mcxe247/minimal/main.c b/tutorials/nxp/frdm-mcxe247/minimal/main.c index dc3d8537..648e1ff1 100644 --- a/tutorials/nxp/frdm-mcxe247/minimal/main.c +++ b/tutorials/nxp/frdm-mcxe247/minimal/main.c @@ -66,9 +66,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -92,6 +98,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/nxp/frdm-mcxn947/minimal/Makefile b/tutorials/nxp/frdm-mcxn947/minimal/Makefile index 45bc104f..0635181a 100644 --- a/tutorials/nxp/frdm-mcxn947/minimal/Makefile +++ b/tutorials/nxp/frdm-mcxn947/minimal/Makefile @@ -9,7 +9,7 @@ CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ CFLAGS += -Icmsis_mcxn947/devices/MCXN947/ -Icmsis_mcxn947/devices/MCXN947/periph/ -Icmsis_mcxn947/devices/MCXN947/drivers/ CFLAGS += -DCPU_MCXN947VDF -DCPU_MCXN947VDF_cm33 -DCPU_MCXN947VDF_cm33_core0 CFLAGS += -mcpu=cortex-m33 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c mongoose/mongoose.c SOURCES += cmsis_mcxn947/devices/MCXN947/gcc/startup_MCXN947_cm33_core0.S @@ -40,5 +40,9 @@ cmsis_mcxn947: unzip -q NXP.MCXN947_DFP.26.06.00.pack -d $@ rm NXP.MCXN947_DFP.26.06.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/frdm-mcxn947/minimal/hal.c b/tutorials/nxp/frdm-mcxn947/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/frdm-mcxn947/minimal/hal.c +++ b/tutorials/nxp/frdm-mcxn947/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/frdm-mcxn947/minimal/main.c b/tutorials/nxp/frdm-mcxn947/minimal/main.c index 75b7bf62..8c137484 100644 --- a/tutorials/nxp/frdm-mcxn947/minimal/main.c +++ b/tutorials/nxp/frdm-mcxn947/minimal/main.c @@ -74,9 +74,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -100,6 +106,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/nxp/frdm-rw612/minimal/Makefile b/tutorials/nxp/frdm-rw612/minimal/Makefile index f25baaf5..dfa74705 100644 --- a/tutorials/nxp/frdm-rw612/minimal/Makefile +++ b/tutorials/nxp/frdm-rw612/minimal/Makefile @@ -12,7 +12,7 @@ CFLAGS += -Icmsis_rw612/devices/RW612/ -Icmsis_rw612/devices/RW612/periph/ -Icms CFLAGS += -DCPU_RW612ETA2I -DCPU_RW612ETA2I_cm33_no_dsp CFLAGS += -DBOOT_HEADER_ENABLE=1 CFLAGS += -mcpu=cortex-m33+nodsp -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c startup.c flexspi.c flash_config.c $(MGDIR)/mongoose.c SOURCES += cmsis_rw612/devices/RW612/drivers/fsl_clock.c @@ -36,6 +36,10 @@ cmsis_rw612: unzip -q NXP.RW612_DFP.25.12.00.pack -d $@ rm NXP.RW612_DFP.25.12.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin (echo 'loadfile firmware.elf'; echo 'reset'; echo 'exit';) | JLinkExe -device RW612 -if SWD -speed 4000 -autoconnect 1 -NoGui 1 -ExitOnError 1 # JRun --nogui --device RW612 --if SWD firmware.elf diff --git a/tutorials/nxp/frdm-rw612/minimal/hal.c b/tutorials/nxp/frdm-rw612/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/frdm-rw612/minimal/hal.c +++ b/tutorials/nxp/frdm-rw612/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/frdm-rw612/minimal/main.c b/tutorials/nxp/frdm-rw612/minimal/main.c index f95ae096..789db3bb 100644 --- a/tutorials/nxp/frdm-rw612/minimal/main.c +++ b/tutorials/nxp/frdm-rw612/minimal/main.c @@ -42,9 +42,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/nxp/rt1060-evkb/minimal/Makefile b/tutorials/nxp/rt1060-evkb/minimal/Makefile index 945b0ca4..6ef1a41a 100644 --- a/tutorials/nxp/rt1060-evkb/minimal/Makefile +++ b/tutorials/nxp/rt1060-evkb/minimal/Makefile @@ -7,7 +7,7 @@ CFLAGS += -Wno-cast-function-type CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1062DVL6B CFLAGS += -Icmsis_rt1060/devices/MIMXRT1062/ -Icmsis_rt1060/devices/MIMXRT1062/periph/ -Icmsis_rt1060/devices/MIMXRT1062/drivers/ CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c SOURCES += cmsis_rt1060/devices/MIMXRT1062/gcc/startup_MIMXRT1062.S @@ -35,5 +35,9 @@ cmsis_rt1060: unzip -q NXP.MIMXRT1062_DFP.26.06.00.pack -d $@ rm NXP.MIMXRT1062_DFP.26.06.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/rt1060-evkb/minimal/hal.c b/tutorials/nxp/rt1060-evkb/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/rt1060-evkb/minimal/hal.c +++ b/tutorials/nxp/rt1060-evkb/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/rt1060-evkb/minimal/main.c b/tutorials/nxp/rt1060-evkb/minimal/main.c index e9fd1d6d..18dbb052 100644 --- a/tutorials/nxp/rt1060-evkb/minimal/main.c +++ b/tutorials/nxp/rt1060-evkb/minimal/main.c @@ -38,9 +38,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -59,6 +65,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/nxp/rt1170-evkb/minimal/Makefile b/tutorials/nxp/rt1170-evkb/minimal/Makefile index 7fac195d..c903b1a3 100644 --- a/tutorials/nxp/rt1170-evkb/minimal/Makefile +++ b/tutorials/nxp/rt1170-evkb/minimal/Makefile @@ -8,7 +8,7 @@ CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1176DVMAA_ CFLAGS += -Icmsis_rt1170/devices/MIMXRT1176/ -Icmsis_rt1170/devices/MIMXRT1176/periph/ -Icmsis_rt1170/devices/MIMXRT1176/drivers/ CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA) CFLAGS += -Wno-unused-parameter # NXP support files -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c SOURCES += cmsis_rt1170/devices/MIMXRT1176/gcc/startup_MIMXRT1176_cm7.S @@ -41,5 +41,9 @@ cmsis_rt1170: unzip -q NXP.MIMXRT1176_DFP.26.06.00.pack -d $@ rm NXP.MIMXRT1176_DFP.26.06.00.pack +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/rt1170-evkb/minimal/hal.c b/tutorials/nxp/rt1170-evkb/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/nxp/rt1170-evkb/minimal/hal.c +++ b/tutorials/nxp/rt1170-evkb/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/nxp/rt1170-evkb/minimal/main.c b/tutorials/nxp/rt1170-evkb/minimal/main.c index 680e6f83..3815eb76 100644 --- a/tutorials/nxp/rt1170-evkb/minimal/main.c +++ b/tutorials/nxp/rt1170-evkb/minimal/main.c @@ -42,9 +42,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -65,6 +71,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-f429zi/minimal-rm2/Makefile b/tutorials/stm32/nucleo-f429zi/minimal-rm2/Makefile index 4a450e54..9f3789bf 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal-rm2/Makefile +++ b/tutorials/stm32/nucleo-f429zi/minimal-rm2/Makefile @@ -3,7 +3,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_mcu/Include -Imongoose CFLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c syscalls.c sysinit.c SOURCES += cmsis_mcu/Source/Templates/gcc/startup_stm32f429xx.s @@ -24,6 +24,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-f429zi/minimal-rm2/syscalls.c b/tutorials/stm32/nucleo-f429zi/minimal-rm2/syscalls.c index ac27f093..79e8b14a 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal-rm2/syscalls.c +++ b/tutorials/stm32/nucleo-f429zi/minimal-rm2/syscalls.c @@ -2,6 +2,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + int _fstat(int fd, struct stat *st) { if (fd < 0) return -1; st->st_mode = S_IFCHR; diff --git a/tutorials/stm32/nucleo-f429zi/minimal-rndis/Makefile b/tutorials/stm32/nucleo-f429zi/minimal-rndis/Makefile index 7d7695ed..c4a9d6c5 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal-rndis/Makefile +++ b/tutorials/stm32/nucleo-f429zi/minimal-rndis/Makefile @@ -3,7 +3,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f4/Include -Imongoose CFLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c syscalls.c sysinit.c SOURCES += cmsis_f4/Source/Templates/gcc/startup_stm32f429xx.s @@ -37,6 +37,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-f429zi/minimal-rndis/syscalls.c b/tutorials/stm32/nucleo-f429zi/minimal-rndis/syscalls.c index ac27f093..79e8b14a 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal-rndis/syscalls.c +++ b/tutorials/stm32/nucleo-f429zi/minimal-rndis/syscalls.c @@ -2,6 +2,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + int _fstat(int fd, struct stat *st) { if (fd < 0) return -1; st->st_mode = S_IFCHR; diff --git a/tutorials/stm32/nucleo-f429zi/minimal/Makefile b/tutorials/stm32/nucleo-f429zi/minimal/Makefile index 862c83c2..64251db7 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal/Makefile +++ b/tutorials/stm32/nucleo-f429zi/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f4/Include -Imongoose CFLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c mongoose/mongoose.c SOURCES += cmsis_f4/Source/Templates/gcc/startup_stm32f429xx.s @@ -25,6 +25,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-f429zi/minimal/hal.c b/tutorials/stm32/nucleo-f429zi/minimal/hal.c index e519bff3..22175a26 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal/hal.c +++ b/tutorials/stm32/nucleo-f429zi/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-f429zi/minimal/main.c b/tutorials/stm32/nucleo-f429zi/minimal/main.c index e8063416..69058451 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal/main.c +++ b/tutorials/stm32/nucleo-f429zi/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-f746zg/minimal-pppoe/Makefile b/tutorials/stm32/nucleo-f746zg/minimal-pppoe/Makefile index ed605c5b..8d84f323 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-pppoe/Makefile +++ b/tutorials/stm32/nucleo-f746zg/minimal-pppoe/Makefile @@ -3,7 +3,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c syscalls.c sysinit.c SOURCES += cmsis_f7/Source/Templates/gcc/startup_stm32f746xx.s @@ -22,6 +22,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-f746zg/minimal-pppoe/syscalls.c b/tutorials/stm32/nucleo-f746zg/minimal-pppoe/syscalls.c index ac27f093..79e8b14a 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-pppoe/syscalls.c +++ b/tutorials/stm32/nucleo-f746zg/minimal-pppoe/syscalls.c @@ -2,6 +2,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + int _fstat(int fd, struct stat *st) { if (fd < 0) return -1; st->st_mode = S_IFCHR; diff --git a/tutorials/stm32/nucleo-f746zg/minimal-rm2/Makefile b/tutorials/stm32/nucleo-f746zg/minimal-rm2/Makefile index cd8d64ac..0f9def30 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-rm2/Makefile +++ b/tutorials/stm32/nucleo-f746zg/minimal-rm2/Makefile @@ -3,7 +3,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_mcu/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c syscalls.c sysinit.c SOURCES += cmsis_mcu/Source/Templates/gcc/startup_stm32f746xx.s @@ -24,6 +24,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-f746zg/minimal-rm2/syscalls.c b/tutorials/stm32/nucleo-f746zg/minimal-rm2/syscalls.c index 6fef1007..15975116 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-rm2/syscalls.c +++ b/tutorials/stm32/nucleo-f746zg/minimal-rm2/syscalls.c @@ -2,6 +2,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + int _fstat(int fd, struct stat *st) { if (fd < 0) return -1; st->st_mode = S_IFCHR; diff --git a/tutorials/stm32/nucleo-f746zg/minimal-rndis/Makefile b/tutorials/stm32/nucleo-f746zg/minimal-rndis/Makefile index 0e2b0a11..29666ec6 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-rndis/Makefile +++ b/tutorials/stm32/nucleo-f746zg/minimal-rndis/Makefile @@ -3,7 +3,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c syscalls.c sysinit.c SOURCES += cmsis_f7/Source/Templates/gcc/startup_stm32f746xx.s @@ -37,6 +37,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-f746zg/minimal-rndis/syscalls.c b/tutorials/stm32/nucleo-f746zg/minimal-rndis/syscalls.c index ac27f093..79e8b14a 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-rndis/syscalls.c +++ b/tutorials/stm32/nucleo-f746zg/minimal-rndis/syscalls.c @@ -2,6 +2,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + int _fstat(int fd, struct stat *st) { if (fd < 0) return -1; st->st_mode = S_IFCHR; diff --git a/tutorials/stm32/nucleo-f746zg/minimal/Makefile b/tutorials/stm32/nucleo-f746zg/minimal/Makefile index d69282e4..ead47c3e 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal/Makefile +++ b/tutorials/stm32/nucleo-f746zg/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_f7/Source/Templates/gcc/startup_stm32f746xx.s @@ -26,6 +26,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-f746zg/minimal/hal.c b/tutorials/stm32/nucleo-f746zg/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal/hal.c +++ b/tutorials/stm32/nucleo-f746zg/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-f746zg/minimal/main.c b/tutorials/stm32/nucleo-f746zg/minimal/main.c index 8b79d0f3..f186d5a2 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal/main.c +++ b/tutorials/stm32/nucleo-f746zg/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-f756zg/minimal/Makefile b/tutorials/stm32/nucleo-f756zg/minimal/Makefile index 86760ba6..4aee58fd 100644 --- a/tutorials/stm32/nucleo-f756zg/minimal/Makefile +++ b/tutorials/stm32/nucleo-f756zg/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_f7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_f7/Source/Templates/gcc/startup_stm32f756xx.s @@ -26,6 +26,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-f756zg/minimal/hal.c b/tutorials/stm32/nucleo-f756zg/minimal/hal.c index e519bff3..22175a26 100644 --- a/tutorials/stm32/nucleo-f756zg/minimal/hal.c +++ b/tutorials/stm32/nucleo-f756zg/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-f756zg/minimal/main.c b/tutorials/stm32/nucleo-f756zg/minimal/main.c index 8b79d0f3..f186d5a2 100644 --- a/tutorials/stm32/nucleo-f756zg/minimal/main.c +++ b/tutorials/stm32/nucleo-f756zg/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-g031k8/minimal-w5500/Makefile b/tutorials/stm32/nucleo-g031k8/minimal-w5500/Makefile index 76edd512..08d14472 100644 --- a/tutorials/stm32/nucleo-g031k8/minimal-w5500/Makefile +++ b/tutorials/stm32/nucleo-g031k8/minimal-w5500/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_g0/Include -Imongoose CFLAGS += -mcpu=cortex-m0 -mthumb -mfloat-abi=soft $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_g0/Source/Templates/gcc/startup_stm32g031xx.s @@ -27,6 +27,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash'" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin st-flash --reset write $< 0x8000000 diff --git a/tutorials/stm32/nucleo-g031k8/minimal-w5500/hal.c b/tutorials/stm32/nucleo-g031k8/minimal-w5500/hal.c index d203039d..774feef0 100644 --- a/tutorials/stm32/nucleo-g031k8/minimal-w5500/hal.c +++ b/tutorials/stm32/nucleo-g031k8/minimal-w5500/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-h563zi/minimal/Makefile b/tutorials/stm32/nucleo-h563zi/minimal/Makefile index 0637226a..0e628daf 100644 --- a/tutorials/stm32/nucleo-h563zi/minimal/Makefile +++ b/tutorials/stm32/nucleo-h563zi/minimal/Makefile @@ -8,7 +8,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -I$(MGDIR) -Icmsis_core/CMSIS/Core/Include -Icmsis_h5/Include -Imongoose -Ilittlefs 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 +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += littlefs/lfs.c littlefs/lfs_util.c @@ -28,6 +28,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd mode=UR -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-h563zi/minimal/hal.c b/tutorials/stm32/nucleo-h563zi/minimal/hal.c index e519bff3..22175a26 100644 --- a/tutorials/stm32/nucleo-h563zi/minimal/hal.c +++ b/tutorials/stm32/nucleo-h563zi/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-h563zi/minimal/main.c b/tutorials/stm32/nucleo-h563zi/minimal/main.c index 40b4d999..864a8c3d 100644 --- a/tutorials/stm32/nucleo-h563zi/minimal/main.c +++ b/tutorials/stm32/nucleo-h563zi/minimal/main.c @@ -53,13 +53,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { .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 { - 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)); + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -74,12 +76,15 @@ int main(void) { hal_gpio_output(LED_2); hal_gpio_output(LED_3); hal_ethernet_init(); - MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); struct mg_mgr mgr; mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + 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 mkdir("/fs", 0755); MG_INFO(("File manager operations:")); diff --git a/tutorials/stm32/nucleo-h723zg/minimal-bsd/Makefile b/tutorials/stm32/nucleo-h723zg/minimal-bsd/Makefile index df1d01f2..d6c88ea9 100644 --- a/tutorials/stm32/nucleo-h723zg/minimal-bsd/Makefile +++ b/tutorials/stm32/nucleo-h723zg/minimal-bsd/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_h7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_h7/Source/Templates/gcc/startup_stm32h723xx.s @@ -32,6 +32,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-h723zg/minimal-bsd/hal.c b/tutorials/stm32/nucleo-h723zg/minimal-bsd/hal.c index e519bff3..22175a26 100644 --- a/tutorials/stm32/nucleo-h723zg/minimal-bsd/hal.c +++ b/tutorials/stm32/nucleo-h723zg/minimal-bsd/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-h723zg/minimal-bsd/main.c b/tutorials/stm32/nucleo-h723zg/minimal-bsd/main.c index 3d834258..297afb0f 100644 --- a/tutorials/stm32/nucleo-h723zg/minimal-bsd/main.c +++ b/tutorials/stm32/nucleo-h723zg/minimal-bsd/main.c @@ -47,8 +47,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -59,6 +66,10 @@ static void task1(void *args) { static struct mg_mgr mgr; mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); for (;;) { mg_mgr_poll(&mgr, 0); mg_bsd_poll(&mgr); diff --git a/tutorials/stm32/nucleo-h743zi/minimal/Makefile b/tutorials/stm32/nucleo-h743zi/minimal/Makefile index 6fc25016..a6c611bc 100644 --- a/tutorials/stm32/nucleo-h743zi/minimal/Makefile +++ b/tutorials/stm32/nucleo-h743zi/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_h7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA) -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_h7/Source/Templates/gcc/startup_stm32h743xx.s @@ -26,6 +26,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/nucleo-h743zi/minimal/hal.c b/tutorials/stm32/nucleo-h743zi/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/nucleo-h743zi/minimal/hal.c +++ b/tutorials/stm32/nucleo-h743zi/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-h743zi/minimal/main.c b/tutorials/stm32/nucleo-h743zi/minimal/main.c index d62901f2..396eb942 100644 --- a/tutorials/stm32/nucleo-h743zi/minimal/main.c +++ b/tutorials/stm32/nucleo-h743zi/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-n657x0-q/minimal/Makefile b/tutorials/stm32/nucleo-n657x0-q/minimal/Makefile index dcb66895..e5038c92 100644 --- a/tutorials/stm32/nucleo-n657x0-q/minimal/Makefile +++ b/tutorials/stm32/nucleo-n657x0-q/minimal/Makefile @@ -7,7 +7,7 @@ CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_n6/Include -Imongoose CFLAGS += -mcpu=cortex-m55 -mthumb -mfloat-abi=soft -mfpu=fpv5-d16 -mcmse CFLAGS += $(CFLAGS_EXTRA) -LDFLAGS ?= -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections +LDFLAGS ?= -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = cmsis_n6/Source/Templates/gcc/startup_stm32n657xx.s SOURCES += main.c hal.c mongoose/mongoose.c @@ -40,6 +40,10 @@ fsbl.elf: cmsis_core cmsis_n6 hal.h fsbl.ld Makefile $(FSBL_SOURCES) fsbl.signed.bin: fsbl.bin STM32_SigningTool_CLI -s -nk -of 0x80000000 -t fsbl -hv 2.3 -align -bin $^ -o $@ +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: fsbl.signed.bin firmware.bin STM32_Programmer_CLI -c port=swd mode=HOTPLUG -el MX25UM51245G_STM32N6570-NUCLEO.stldr -d firmware.bin 0x70100000 -hardRst STM32_Programmer_CLI -c port=swd mode=HOTPLUG -el MX25UM51245G_STM32N6570-NUCLEO.stldr -d fsbl.signed.bin 0x70000000 -hardRst diff --git a/tutorials/stm32/nucleo-n657x0-q/minimal/hal.c b/tutorials/stm32/nucleo-n657x0-q/minimal/hal.c index bd09d907..185599da 100644 --- a/tutorials/stm32/nucleo-n657x0-q/minimal/hal.c +++ b/tutorials/stm32/nucleo-n657x0-q/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-n657x0-q/minimal/main.c b/tutorials/stm32/nucleo-n657x0-q/minimal/main.c index adaf36b5..e5a9678b 100644 --- a/tutorials/stm32/nucleo-n657x0-q/minimal/main.c +++ b/tutorials/stm32/nucleo-n657x0-q/minimal/main.c @@ -41,9 +41,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/nucleo-u5a5zj-q/minimal/Makefile b/tutorials/stm32/nucleo-u5a5zj-q/minimal/Makefile index 6c58cc76..34b8d4e4 100644 --- a/tutorials/stm32/nucleo-u5a5zj-q/minimal/Makefile +++ b/tutorials/stm32/nucleo-u5a5zj-q/minimal/Makefile @@ -5,7 +5,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_u5/Include -Imongoose CFLAGS += -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c wifi.c mongoose/mongoose.c SOURCES += cmsis_u5/Source/Templates/gcc/startup_stm32u5a5xx.s @@ -24,6 +24,10 @@ firmware.bin: firmware.elf firmware.elf: cmsis_core cmsis_u5 $(SOURCES) mongoose/mongoose.h $(wildcard *.h) link.ld Makefile arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@ +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w $< 0x8000000 -hardRst diff --git a/tutorials/stm32/nucleo-u5a5zj-q/minimal/hal.c b/tutorials/stm32/nucleo-u5a5zj-q/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/nucleo-u5a5zj-q/minimal/hal.c +++ b/tutorials/stm32/nucleo-u5a5zj-q/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/nucleo-u5a5zj-q/minimal/main.c b/tutorials/stm32/nucleo-u5a5zj-q/minimal/main.c index 700a8f48..a3b774a1 100644 --- a/tutorials/stm32/nucleo-u5a5zj-q/minimal/main.c +++ b/tutorials/stm32/nucleo-u5a5zj-q/minimal/main.c @@ -37,9 +37,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -61,6 +67,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/portenta-h7/minimal/Makefile b/tutorials/stm32/portenta-h7/minimal/Makefile index ef636070..84901504 100644 --- a/tutorials/stm32/portenta-h7/minimal/Makefile +++ b/tutorials/stm32/portenta-h7/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -Wno-cast-function-type CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_h7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -DCORE_CM7 -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c wifi.c hal.c SOURCES += cmsis_h7/Source/Templates/gcc/startup_stm32h747xx.s @@ -34,6 +34,10 @@ mbed: git clone --depth 1 --no-checkout -b extrapatches-6.17.0 https://github.com/arduino/mbed-os $@ && cd $@ && git sparse-checkout set targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/resources && git checkout touch wiced_resource.h +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin dfu-util -a 0 -s 0x8040000:leave -D $< diff --git a/tutorials/stm32/portenta-h7/minimal/hal.c b/tutorials/stm32/portenta-h7/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/portenta-h7/minimal/hal.c +++ b/tutorials/stm32/portenta-h7/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/portenta-h7/minimal/main.c b/tutorials/stm32/portenta-h7/minimal/main.c index ddc76829..635ffb1f 100644 --- a/tutorials/stm32/portenta-h7/minimal/main.c +++ b/tutorials/stm32/portenta-h7/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -69,6 +75,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/stm32h573i-dk/minimal/Makefile b/tutorials/stm32/stm32h573i-dk/minimal/Makefile index a3b9c36e..e5df7f43 100644 --- a/tutorials/stm32/stm32h573i-dk/minimal/Makefile +++ b/tutorials/stm32/stm32h573i-dk/minimal/Makefile @@ -6,7 +6,7 @@ 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 += -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 +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_h5/Source/Templates/gcc/startup_stm32h573xx.s @@ -26,6 +26,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/stm32h573i-dk/minimal/hal.c b/tutorials/stm32/stm32h573i-dk/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/stm32h573i-dk/minimal/hal.c +++ b/tutorials/stm32/stm32h573i-dk/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/stm32h573i-dk/minimal/main.c b/tutorials/stm32/stm32h573i-dk/minimal/main.c index f968aabc..57374d3d 100644 --- a/tutorials/stm32/stm32h573i-dk/minimal/main.c +++ b/tutorials/stm32/stm32h573i-dk/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task(); diff --git a/tutorials/stm32/stm32h747i-disco/minimal/Makefile b/tutorials/stm32/stm32h747i-disco/minimal/Makefile index 27e26b78..cc3744c8 100644 --- a/tutorials/stm32/stm32h747i-disco/minimal/Makefile +++ b/tutorials/stm32/stm32h747i-disco/minimal/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion CFLAGS += -g3 -Os -ffunction-sections -fdata-sections CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_h7/Include -Imongoose CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA) -DCORE_CM7 -LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nosys.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map +LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c SOURCES += cmsis_h7/Source/Templates/gcc/startup_stm32h747xx.s @@ -26,6 +26,10 @@ firmware.bin: firmware.elf @echo @echo "To flash, run 'make flash', or use STM32CubeProgrammer" +# Show all symbols sorted by size +show_symbols_sorted_by_size: firmware.bin + arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 ' + flash: firmware.bin STM32_Programmer_CLI -c port=swd -e all -w firmware.elf -hardRst diff --git a/tutorials/stm32/stm32h747i-disco/minimal/hal.c b/tutorials/stm32/stm32h747i-disco/minimal/hal.c index 6dc65c9f..a7f8ecca 100644 --- a/tutorials/stm32/stm32h747i-disco/minimal/hal.c +++ b/tutorials/stm32/stm32h747i-disco/minimal/hal.c @@ -3,6 +3,12 @@ #include "hal.h" +// Added to minimise the bin size: avoid pulling printf and friends +void __assert_func(const char *s, int line, const char *fn, const char *expr) { + (void) s, (void) line, (void) fn, (void) expr; + for (;;) (void) 0; // or trigger the fault handler +} + bool hal_timer_expired(volatile uint64_t *t, uint64_t period, uint64_t now) { uint64_t diff = now - *t; // Wrap-safe elapsed time since last expiry if (period == 0) return false; // Avoid division by zero diff --git a/tutorials/stm32/stm32h747i-disco/minimal/main.c b/tutorials/stm32/stm32h747i-disco/minimal/main.c index f6d3f9ac..afb77094 100644 --- a/tutorials/stm32/stm32h747i-disco/minimal/main.c +++ b/tutorials/stm32/stm32h747i-disco/minimal/main.c @@ -45,9 +45,15 @@ 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("/api/crash"), NULL)) { + __asm volatile("udf #0"); // Trigger HardFault } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", - hal_get_tick()); + mg_http_reply(c, 200, "", + "Hi from Mongoose!\n" + "tick: %llu\n" + "ram used: %zu\n" + "ram free: %zu\n", + hal_get_tick(), hal_ram_used(), hal_ram_free()); } } } @@ -68,6 +74,10 @@ int main(void) { mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); + MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000)); + MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free())); + MG_INFO(("Crash record: %M", mg_print_crash_record)); + for (;;) { mg_mgr_poll(&mgr, 0); blink_task();