Page 6 of 7
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Fri Nov 30, 2018 4:47 pm
by Zezombye
Thanks; I must have missed that #define when I skimmed over the mpconfig.h.
I also thought MPy used the allocated memory as stack memory, instead of using actual stack memory.
However, for some reason defining MICROPY_STACK_CHECK makes me unable to import any script; the shell simply hangs as if it was stuck in an infinite loop (even if the script doesn't do anything, eg. defining a function).
As a workaround I defined MICROPY_STACKLESS and MICROPY_STACKLESS_STRICT so that it stays strictly within the heap; now I can do up to around r(650), however I'd like to also use the stack memory (though I would be happy with this workaround as it gives me enough memory, and it crashes gracefully when out of memory). Any idea why it does that?
How do I make a port of MicroPython for Casio calculators?
Posted: Fri Nov 30, 2018 4:52 pm
by jickster
You have to call a c function to set the amount of C stack available to uPy.
Sent from my iPhone using Tapatalk Pro
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 3:03 am
by Zezombye
I can't use the mp_pystack_init() function though, as I can't know the absolute stack addresses (unless there's another way, but whatever, it seems there's only 3k of stack available, not gonna bother when I've got 32kb :p).
Do you have any idea for my other problems (raising a keyboardinterrupt from timer, and repl printing string-by-string)? Thanks
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 3:23 am
by jickster
mp_pystack_init() is NOT the right function. That refers to something else.
mp_stack_set_limit(mp_uint_t limit) takes in a stack SIZE limit.
Sent from my iPhone using Tapatalk Pro
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 3:53 am
by Zezombye
Calling mp_stack_set_limit(2048) at the beginning of mpy_main() doesn't seem to fix the "infinite loop" problem (I also tried with 256).
Doing "reset&run execution" on the SDK gives the error "reserved instruction exception by code read access at 003317F8" which is the function nlr_jump_fail:
Code: Select all
003317f8 <_nlr_jump_fail>:
3317f8: af fe bra 3317f8 <_nlr_jump_fail>
3317fa: 00 09 nop
Not sure what to draw from this.
How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 3:56 am
by jickster
Create a super simple script and import it like:
Does it work?
I think what may be happening is you’re importing something too big.
Sent from my iPhone using Tapatalk Pro
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 4:13 am
by Zezombye
There you go:
Code: Select all
int mpy_main(char *text) {
mp_stack_set_limit(256);
int heapLen = 32768;
#if MICROPY_ENABLE_GC
heap = malloc(heapLen);
#endif
if (heap == NULL) {
int key;
locate(1,1);
Print("Couldn't alloc!");
GetKey(&key);
}
ML_clear_vram();
ML_display_vram();
shell_init();
readline_index = 0;
initNbOpenedFiles();
int stack_dummy;
extern int rx_index;
rx_index = 1;
stack_top = (char*)&stack_dummy;
#if MICROPY_ENABLE_GC
gc_init(heap, heap + heapLen);
#endif
mp_init();
pyexec_friendly_repl(text);
free(heap);
mp_deinit();
closeAllFiles();
return 0;
}
Edit: no, it happens with any script, even one with only "1" in it.
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 4:28 am
by jickster
You forgot to call mp_stack_ctrl_init() which takes care of what you’re trying to do with the variable stack_dummy.
Sent from my iPhone using Tapatalk Pro
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 4:34 am
by Zezombye
Thanks, works fine now
Re: How do I make a port of MicroPython for Casio calculators?
Posted: Sat Dec 01, 2018 4:57 am
by jickster
Zezombye wrote:Thanks, works fine now
Thank god. I was gonna be exasperated otherwise.
I’ll address your REPL issue next.
To be clear, does your
represent ALL the lines of a .py script?
Sent from my iPhone using Tapatalk Pro