Skip to content

Commit 3544b04

Browse files
committed
Add support for atomvm_free_heap_size key to system_info/1 on STM32 platform
Adds support for getting the current free heap size on STM32 platform using `erlang:system_info(atomvm_free_heap_size)`. Signed-off-by: Winford <winford@object.stream>
1 parent 15a21be commit 3544b04

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4747
- Added `application:get_env/2`
4848
- Added CodeQL analysis to esp32, stm32, pico, and wasm workflows
4949
- Added Function.ex and Protocol.ex improving Elixir 1.18 support
50+
- Added `system_info/1` key `atomvm_free_heap_size` support for STM32
5051

5152
### Changed
5253

src/platforms/stm32/src/lib/sys.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ void *_sbrk_r(struct _reent *reent, ptrdiff_t diff)
8282
return _old_brk;
8383
}
8484

85+
static int sys_get_free_heap()
86+
{
87+
return (int) ((uint8_t *) (((uintptr_t) &_stack - RESERVE_STACK_SIZE))) - (_cur_brk == NULL ? (int) &_ebss : (int) _cur_brk);
88+
}
89+
8590
// Monotonically increasing number of milliseconds from reset
8691
static volatile uint64_t system_millis;
8792

@@ -263,11 +268,14 @@ Context *sys_create_port(GlobalContext *glb, const char *driver_name, term opts)
263268

264269
term sys_get_info(Context *ctx, term key)
265270
{
266-
UNUSED(ctx);
267-
UNUSED(key);
271+
GlobalContext *glb = ctx->global;
272+
if (key == globalcontext_existing_term_from_atom_string(glb, ATOM_STR("\x15", "atomvm_free_heap_size"))) {
273+
return term_from_int32(sys_get_free_heap());
274+
}
268275
return UNDEFINED_ATOM;
269276
}
270277

278+
271279
void sys_enable_flash_cache()
272280
{
273281
flash_unlock_option_bytes();

0 commit comments

Comments
 (0)