Code: Select all
def copyRadioBufferToString(i):
if (radioBuffer[i]==0):
return "" # null string
else:
return chr(radioBuffer[i])+copyRadioBufferToString(i+1)
def receivedString():
return copyRadioBufferToString(0)
Code: Select all
def copyRadioBufferToString(i):
if (radioBuffer[i]==0):
return "" # null string
else:
return chr(radioBuffer[i])+copyRadioBufferToString(i+1)
def receivedString():
return copyRadioBufferToString(0)
Code: Select all
Traceback (most recent call last):
File "<stdin>", in <module>
File "main.py", in start
File "main.py", in receivedString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
File "main.py", in copyRadioBufferToString
RuntimeError: maximum recursion depth exceeded
Code: Select all
void mp_stack_set_limit(mp_uint_t limit) {
MP_STATE_THREAD(stack_limit) = limit;
}
Code: Select all
// Whether to check C stack usage. C stack used for calling Python functions,
// etc. Not checking means segfault on overflow.
#define MICROPY_STACK_CHECK (1)
Thanks for that pointer, very informative.pythoncoder wrote: ↑Tue Oct 23, 2018 6:41 amYou might like to read the docs which provides useful guidance on how to write efficient MicroPython code.
That's a very helpful comment. I'll be sure to look into that when I get to the optimization phase.pythoncoder wrote: ↑Tue Oct 23, 2018 6:41 amIn general it's best to avoid heavy recursion when programming microcontrollers because of their limited resources. The use of the string addition operator is also inefficient on RAM use compared to string.join(). So I'd rewrite it as an iterative function.
You might like to read the docs which provides useful guidance on how to write efficient MicroPython code.
Code: Select all
from my_frozen_module import data
a = data[760] # good
b = data[3:7] # Uses RAM