diff --git a/headers/system.h b/headers/system.h index 2154f970a..4319cf26d 100644 --- a/headers/system.h +++ b/headers/system.h @@ -4,10 +4,12 @@ #include namespace System { - // Returns the size of on-board flash memory in bytes + // Returns the size of on-board flash memory reserved by the config uint32_t getTotalFlash(); // Returns the amount of on-board flash memory used by the firmware in bytes uint32_t getUsedFlash(); + // Returns the amount of physical flash memory on the board + uint32_t getPhysicalFlash(); // Returns the amount of memory used for static allocations in bytes uint32_t getStaticAllocs(); // Returns the total size of heap memory in bytes diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index d0f6c7643..c10578b6f 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -214,7 +214,11 @@ static void __attribute__((noinline)) writeDoc(DynamicJsonDocument& doc, const K static int32_t cleanPin(int32_t pin) { return isValidPin(pin) ? pin : -1; } +static uint32_t systemFlashSize; + void WebConfig::setup() { + // System Flash Size must be called once + systemFlashSize = System::getPhysicalFlash(); rndis_init(); } @@ -2106,6 +2110,7 @@ std::string getMemoryReport() DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN); writeDoc(doc, "totalFlash", System::getTotalFlash()); writeDoc(doc, "usedFlash", System::getUsedFlash()); + writeDoc(doc, "physicalFlash", systemFlashSize); writeDoc(doc, "staticAllocs", System::getStaticAllocs()); writeDoc(doc, "totalHeap", System::getTotalHeap()); writeDoc(doc, "usedHeap", System::getUsedHeap()); diff --git a/src/system.cpp b/src/system.cpp index d91caa70a..036e89741 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -28,6 +28,22 @@ uint32_t System::getUsedFlash() { return &__flash_binary_end - &__flash_binary_start; } +#define STORAGE_CMD_TOTAL_BYTES 3 + +// Standard Storage instruction: 9f command prefix, Manufacturer ID, Flash Type, Capacity +#define FLASH_STORAGE_CMD 0x9f +#define FLASH_STORAGE_DATA_BYTES 3 +#define FLASH_STORAGE_TOTAL_BYTES (1 + FLASH_STORAGE_DATA_BYTES) + +uint32_t System::getPhysicalFlash() { + + uint8_t txbuf[FLASH_STORAGE_TOTAL_BYTES] = {0}; + uint8_t rxbuf[FLASH_STORAGE_TOTAL_BYTES] = {0}; + txbuf[0] = FLASH_STORAGE_CMD; + flash_do_cmd(txbuf, rxbuf, FLASH_STORAGE_TOTAL_BYTES); + return 1 << rxbuf[3]; +} + uint32_t System::getStaticAllocs() { const uint32_t inMemorySegmentsSize = reinterpret_cast(&__bss_end__) - SRAM_BASE; const uint32_t stackSize = &__StackTop - &__StackLimit; diff --git a/www/server/app.js b/www/server/app.js index 3e509263f..aacb988b3 100644 --- a/www/server/app.js +++ b/www/server/app.js @@ -761,11 +761,12 @@ app.get('/api/reboot', (req, res) => { app.get('/api/getMemoryReport', (req, res) => { return res.send({ - totalFlash: 2048, - usedFlash: 1048, + totalFlash: 2048 * 1024, + usedFlash: 1048 * 1024, + physicalFlash: 2048 * 1024, staticAllocs: 200, - totalHeap: 2048, - usedHeap: 1048, + totalHeap: 2048 * 1024, + usedHeap: 1048 * 1024, }); }); diff --git a/www/src/Locales/en/HomePage.jsx b/www/src/Locales/en/HomePage.jsx index 4cc9b0044..1cc7eba8e 100644 --- a/www/src/Locales/en/HomePage.jsx +++ b/www/src/Locales/en/HomePage.jsx @@ -4,6 +4,7 @@ export default { 'header-text': 'Welcome to the GP2040-CE Web Configurator!', 'latest-text': 'Latest: {{version}}', 'memory-flash-text': 'Flash', + 'memory-board-text': 'Board Flash', 'memory-header-text': 'Memory (KB)', 'memory-heap-text': 'Heap', 'memory-static-allocations-text': 'Static Allocations', diff --git a/www/src/Pages/HomePage.jsx b/www/src/Pages/HomePage.jsx index e6ba5570c..5f4f08b6e 100644 --- a/www/src/Pages/HomePage.jsx +++ b/www/src/Pages/HomePage.jsx @@ -55,11 +55,12 @@ export default function HomePage() { WebApi.getMemoryReport(setLoading) .then((response) => { - const { totalFlash, usedFlash, staticAllocs, totalHeap, usedHeap } = + const { totalFlash, usedFlash, physicalFlash, staticAllocs, totalHeap, usedHeap } = response; setMemoryReport({ totalFlash: toKB(totalFlash), usedFlash: toKB(usedFlash), + physicalFlash: toKB(physicalFlash), staticAllocs: toKB(staticAllocs), totalHeap: toKB(totalHeap), usedHeap: toKB(usedHeap), @@ -111,6 +112,9 @@ export default function HomePage() { {t('HomePage:memory-static-allocations-text')}:{' '} {memoryReport.staticAllocs} +
+ {t('HomePage:memory-board-text')}: {memoryReport.physicalFlash} +
)}