How do I make a port of MicroPython for Casio calculators?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Fri Nov 30, 2018 4:47 pm

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?

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

How do I make a port of MicroPython for Casio calculators?

Post by jickster » Fri Nov 30, 2018 4:52 pm

You have to call a c function to set the amount of C stack available to uPy.


Sent from my iPhone using Tapatalk Pro

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Dec 01, 2018 3:03 am

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 :)

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Sat Dec 01, 2018 3:23 am

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

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Dec 01, 2018 3:53 am

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.

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

How do I make a port of MicroPython for Casio calculators?

Post by jickster » Sat Dec 01, 2018 3:56 am

Create a super simple script and import it like:

Code: Select all

a = 1
Does it work?

I think what may be happening is you’re importing something too big.


Sent from my iPhone using Tapatalk Pro
Last edited by jickster on Sat Dec 01, 2018 3:56 am, edited 1 time in total.

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Dec 01, 2018 4:13 am

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.

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Sat Dec 01, 2018 4:28 am

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

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Dec 01, 2018 4:34 am

Thanks, works fine now :D

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Sat Dec 01, 2018 4:57 am

Zezombye wrote:Thanks, works fine now :D
Thank god. I was gonna be exasperated otherwise.

I’ll address your REPL issue next.

To be clear, does your

Code: Select all

char * text
represent ALL the lines of a .py script?


Sent from my iPhone using Tapatalk Pro

Post Reply