I tried to mess with location and size of variables and currently I have at least small improvement that they are automatically sized in free space between end of heap and beginning of stack. Linker provides following symbols: __HeapStart,__HeapLimit,__StackLimit so if stack is sized properly variables can be between __HeapLimit and __StackLimit (heap is in fact zero so __HeapStart =__HeapLimit but if we'd like to have some heap in future HeapLimit works better).
I have added stack painting with DEADBEEF to nrf startup and initially set stack size to 0x2600 which gives similar size of variables than before (2650) but it looks that when running my typical code in DS-D6 the stack could be much less. @Gordon would you be interested to go in this direction? sizing just stack and autosizing variables according to that? And BTW I had to move variable initialization sooner in main as they are probably used without proper jsvInit call but with static allocation it probably doesn't break.
and BTW when unzipping Nordic sdk11 zip the file gcc_startup_nrf52.s was named with lower case .s suffix and looks like when it does not end with .S the preprocessor run is skipped so at first I had a lot of head scratching why -D__STACK_SIZE=x had no effect.
Also it looks like default stack size is 4096 in SDK11 and was raised to 8192 in SDK12 so maybe 8KB 0x2000 should be enough? How is C stack used in JS interpreter with relation to nested js functions, does it use just JS variables or C stack too?
BTW, Just checked stack in DS-D6 over bluetooth with my SDK11 build
>for (i=0x20010000-0x2600;i<0x20010000;i+=4) { if (peek32(i)!=0xdeadbeef) break; } ; print(i.toString(16))
2000f298
so basically only 0x0D68=3432bytes of stack was ever used. Is there some specific espruino code I can try that uses lot of stack? (eg. regexes?)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I tried to mess with location and size of variables and currently I have at least small improvement that they are automatically sized in free space between end of heap and beginning of stack. Linker provides following symbols:
__HeapStart,__HeapLimit,__StackLimit
so if stack is sized properly variables can be between__HeapLimit
and__StackLimit
(heap is in fact zero so__HeapStart =__HeapLimit
but if we'd like to have some heap in future HeapLimit works better).I have added stack painting with DEADBEEF to nrf startup and initially set stack size to 0x2600 which gives similar size of variables than before (2650) but it looks that when running my typical code in DS-D6 the stack could be much less.
@Gordon would you be interested to go in this direction? sizing just stack and autosizing variables according to that? And BTW I had to move variable initialization sooner in main as they are probably used without proper jsvInit call but with static allocation it probably doesn't break.
here is small patch to see the changes https://gist.github.com/fanoush/957202cdf42d866c046e5ee243fb72e3 for SDK11 based build
I am building with -DJSVAR_MALLOC -DJSVAR_MALLOC_AUTO
Stack sizing and those symbols are used here https://github.com/espruino/Espruino/blob/master/targetlibs/nrf5x_12/components/toolchain/gcc/gcc_startup_nrf52.S#L39 and I have put stack painting here after clearing BSS https://github.com/espruino/Espruino/blob/master/targetlibs/nrf5x_12/components/toolchain/gcc/gcc_startup_nrf52.S#L397 with loop taken from this https://devzone.nordicsemi.com/f/nordic-q-a/3650/nrf51822---exception-on-stack-overflow/13253#13253
and BTW when unzipping Nordic sdk11 zip the file gcc_startup_nrf52.s was named with lower case .s suffix and looks like when it does not end with .S the preprocessor run is skipped so at first I had a lot of head scratching why -D__STACK_SIZE=x had no effect.
Also it looks like default stack size is 4096 in SDK11 and was raised to 8192 in SDK12 so maybe 8KB 0x2000 should be enough? How is C stack used in JS interpreter with relation to nested js functions, does it use just JS variables or C stack too?
BTW, Just checked stack in DS-D6 over bluetooth with my SDK11 build
so basically only 0x0D68=3432bytes of stack was ever used. Is there some specific espruino code I can try that uses lot of stack? (eg. regexes?)