Skip to content

Commit

Permalink
Add board flash 0x9f SPI command to web config (OpenStickCommunity#1075)
Browse files Browse the repository at this point in the history
* [ImgBot] Optimize images

*Total -- 11,807.83kb -> 10,597.19kb (10.25%)

/configs/MavercadeRev2/assets/Rev2_config_pic.jpg -- 1,148.71kb -> 1,001.39kb (12.83%)
/configs/MavercadeRev2/assets/Rev2_thumbnail.png -- 4,501.00kb -> 3,984.05kb (11.49%)
/configs/ZeroRhythm/Assets/ZeroThythm 2.jpg -- 2,954.52kb -> 2,669.00kb (9.66%)
/configs/ZeroRhythm/Assets/ZeroRhythm 1.jpg -- 2,687.40kb -> 2,428.72kb (9.63%)
/configs/MavercadeRev1/assets/Rev1_config_pic.png -- 516.19kb -> 514.02kb (0.42%)

Signed-off-by: ImgBotApp <[email protected]>

* Added actual board flash info to homepage

* Missing define

* Bump up the TX/RX memory space even more

* Last attempt at correctness

* Updated system flash size to be a static int32_t only called once at start of web

---------

Signed-off-by: ImgBotApp <[email protected]>
Co-authored-by: ImgBotApp <[email protected]>
  • Loading branch information
arntsonl and ImgBotApp authored Sep 17, 2024
1 parent ca3bac9 commit 9e3d7a6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion headers/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include <cstdint>

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
Expand Down
5 changes: 5 additions & 0 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(&__bss_end__) - SRAM_BASE;
const uint32_t stackSize = &__StackTop - &__StackLimit;
Expand Down
9 changes: 5 additions & 4 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

Expand Down
1 change: 1 addition & 0 deletions www/src/Locales/en/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion www/src/Pages/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -111,6 +112,9 @@ export default function HomePage() {
{t('HomePage:memory-static-allocations-text')}:{' '}
{memoryReport.staticAllocs}
</div>
<div>
{t('HomePage:memory-board-text')}: {memoryReport.physicalFlash}
</div>
</div>
)}
</div>
Expand Down

0 comments on commit 9e3d7a6

Please sign in to comment.