Skip to content

Commit

Permalink
Solved the multi-thread stack problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
iPAS committed Oct 30, 2021
1 parent 38191e6 commit 33307b1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All helper scripts are placed in _scripts_ directory.
* After ```mbed import``` a library into the project,
please command ```mbed deploy``` consecutively.

* [Tracking Memory Usage in Mbed-OS](https://os.mbed.com/blog/entry/Tracking-memory-usage-with-Mbed-OS/)

## LoRaWAN & Gateway

Expand All @@ -50,3 +51,4 @@ please command ```mbed deploy``` consecutively.
* [Using Built-in ChirpStack](https://docs.rakwireless.com/Product-Categories/WisGate/RAK7243C/Quickstart/#connect-the-gateway-with-chirpstack)
* [Firmware of the node](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-lorawan/)
* Edit the configuration in _mbed_app.json_ file.

25 changes: 23 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,38 @@ void ads1220_read(void)
#endif


/******************************************************************************
* AUX functions
******************************************************************************/
void print_memory_info() {
// allocate enough room for every thread's stack statistics
int cnt = osThreadGetCount();
mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));

cnt = mbed_stats_stack_get_each(stats, cnt);
for (int i = 0; i < cnt; i++) {
tr_debug("Thread: 0x%lX, Stack size: %lu / %lu\r\n", stats[i].thread_id, stats[i].max_size, stats[i].reserved_size);
}
free(stats);

// Grab the heap statistics
mbed_stats_heap_t heap_stats;
mbed_stats_heap_get(&heap_stats);
tr_debug("Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
}


/******************************************************************************
* Main
******************************************************************************/
int main()
{
// Setup tracing
setup_trace();

print_memory_info();
// Initialize lorawan & sending
lrw_init();

print_memory_info();

float raw = 0;

Expand Down
10 changes: 8 additions & 2 deletions mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"value": "SX1276"
},
"main_stack_size": { "value": 4096 },
"thread_stack_size": { "value": 4096 },

"lora-spi-mosi": { "value": "NC" },
"lora-spi-miso": { "value": "NC" },
Expand Down Expand Up @@ -249,7 +250,7 @@
},

"IM880B": {
"main_stack_size": 8192,
"main_stack_size": 2048,
"lora-radio": "SX1272",
"lora-spi-mosi": "SPI_RF_MOSI",
"lora-spi-miso": "SPI_RF_MISO",
Expand Down Expand Up @@ -293,6 +294,11 @@
"lora-tcxo": "NC"
}
},
"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]
"macros": [
"MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\"",
"MBED_HEAP_STATS_ENABLED=1",
"MBED_STACK_STATS_ENABLED=1",
"MBED_MEM_TRACING_ENABLED=1"
]
}

0 comments on commit 33307b1

Please sign in to comment.