Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/make/family/NRF52.make b/make/family/NRF52.make
index 725cb55d..90bd9b69 100644
--- a/make/family/NRF52.make
+++ b/make/family/NRF52.make
@@ -46,6 +46,7 @@ NRF5X_SDK=11
NRF5X_SDK_11=1
NRF5X_SDK_PATH=$(ROOT)/targetlibs/nrf5x_11
DEFINES += -DNRF_SD_BLE_API_VERSION=2
+DEFINES += -D__HEAP_SIZE=0 -D__STACK_SIZE=0x2600 -D__STARTUP_CLEAR_BSS
SOFTDEVICE = $(SOFTDEVICE_PATH)/hex/s132_nrf52_2.0.0_softdevice.hex
else
# Use SDK12
diff --git a/src/jsvar.c b/src/jsvar.c
index b81fb34b..68701e20 100644
--- a/src/jsvar.c
+++ b/src/jsvar.c
@@ -255,6 +255,9 @@ static JsVarRef jsvInitJsVars(JsVarRef start, unsigned int count) {
return start;
}
+extern int __HeapLimit;
+extern int __StackLimit;
+
void jsvInit(unsigned int size) {
#ifdef RESIZABLE_JSVARS
assert(size==0);
@@ -262,8 +265,13 @@ void jsvInit(unsigned int size) {
jsVarBlocks = malloc(sizeof(JsVar*)); // just 1
jsVarBlocks[0] = malloc(sizeof(JsVar) * JSVAR_BLOCK_SIZE);
#elif defined(JSVAR_MALLOC)
+#ifdef JSVAR_MALLOC_AUTO
+ jsVarsSize=((unsigned int)(&__StackLimit) - (unsigned int)(&__HeapLimit))/sizeof(JsVar);
+ jsVars=(JsVar *)&__HeapLimit;
+#else
if (size) jsVarsSize = size;
if(!jsVars) jsVars = (JsVar *)malloc(sizeof(JsVar) * jsVarsSize);
+#endif
#else
assert(size==0);
#endif
diff --git a/targets/nrf5x/main.c b/targets/nrf5x/main.c
index a736d272..468c3138 100644
--- a/targets/nrf5x/main.c
+++ b/targets/nrf5x/main.c
@@ -18,13 +18,14 @@
int main() {
+ jsvInit(0);
jshInit();
bool buttonState = false;
#ifdef BTN1_PININDEX
buttonState = jshPinGetValue(BTN1_PININDEX) == BTN1_ONSTATE;
#endif
- jsvInit(0);
+// jsvInit(0);
jsiInit(!buttonState /* load from flash by default */); // pressing USER button skips autoload
while (1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.