Add memory stats reporting for mdash with FreeRTOS example for H723

This commit is contained in:
robert committed 2026-11-06 17:33:28 +02:00
1 parent aaf202ba2f
commit da33868409
177 files changed
+247892 -17

No files matched your search

@@ -45,15 +45,6 @@ __attribute__((weak)) int _fstat(int fd, struct stat *st) {
extern unsigned char _end[]; // End of data section, start of heap. See link.ld
static unsigned char *s_current_heap_end = _end;
size_t hal_ram_used(void) {
return (size_t) (s_current_heap_end - _end);
}
size_t hal_ram_free(void) {
unsigned char endofstack;
return (size_t) (&endofstack - s_current_heap_end);
}
void *_sbrk(int incr) {
unsigned char *prev_heap;
unsigned char *heap_end = (unsigned char *) ((size_t) &heap_end - 256);
@@ -15,8 +15,6 @@
extern bool hal_timer_expired(volatile uint64_t *t, uint64_t prd, uint64_t now);
extern uint64_t hal_get_tick(void);
extern size_t hal_ram_free(void);
extern size_t hal_ram_used(void);
extern uint32_t SystemCoreClock;
#define BIT(x) (1UL << (x))
+16 -5
View File
@@ -4,6 +4,19 @@
#include "hal.h"
#include "mongoose.h"
size_t mg_usage(int task, int metric) {
extern void *_sbrk(int incr);
if (metric == MG_USAGE_NUM_TASKS) return 1;
if (metric == MG_USAGE_TASK_NAME) return task == 0 ? (size_t) "main" : 0;
// Heap and stack share the free gap, neither has a fixed total
if (metric == MG_USAGE_HEAP_FREE ||
(metric == MG_USAGE_STACK_FREE && task == 0)) {
size_t sp = (size_t) __get_MSP(), heap = (size_t) _sbrk(0);
return sp > heap ? sp - heap : 0;
}
return 0;
}
#ifndef UART_DEBUG
#define UART_DEBUG USART3
#define UART_DEBUG_TX_PIN PIN('D', 8)
@@ -82,10 +95,8 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
} else {
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());
"tick: %llu\n%M\n",
hal_get_tick(), mg_print_mem_stats);
}
}
}
@@ -108,7 +119,7 @@ int main(void) {
mg_http_listen(&mgr, "https://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(("Memory: %M", mg_print_mem_stats));
MG_INFO(("Crash record: %M", mg_print_crash_record));
for (;;) {
@@ -28,6 +28,7 @@
// Crash report support. Health record lives in the .mg_health region, see link.ld
#define MG_ENABLE_HEALTH 1
#define MG_ENABLE_CUSTOM_USAGE 1
// mdash.net device management service support
#define MG_ENABLE_MDASH 0