Page 1 of 1

Problem in micropython porting

Posted: Tue May 05, 2020 7:56 am
by deepak
Hi,

I am new to micropython and was trying to port micropython v1.12 to Nuttx. and i am interested to port core functionalities as of now so i used main.c and mpconfigport.h from ports/minimal, pyexec.c and pyexec.h from lib/utils, readline.c and readline.h from libs/mp-readline and used these files in my makefile so after building up i am getting the following problem in mpy REPL:

if i type 3*2 then entered, nothing displayed then again typed 3*2 then it takes 3*2*. this kind of behavior it is showing.
please tell me where is the problem?

In addition to that i have modified above mentioned files, i was getting error in these kind of functions mp_hal_stdout_tx_strn("\x04", 1), so i changed these with fprintf(stdout, "\x04").
moreover, if any info required please let me know.

Re: Problem in micropython porting

Posted: Tue May 05, 2020 10:51 am
by stijn
Hard to tell without seeing your actual code, but mp_hal_stdin_rx_chr/mp_hal_stdout_tx_strn could be the problem: you should provide an mphalport.c file which properly implements these (and other) functions to provide the I/O for the REPL. Just using fprintf might not be sufficient (also, you need an input part somewhere, looks like that is missing i.e. whatever you enter maybe doesn't even make it into MicroPython?). And if it would be, you shouldn't replace mp_hal_stdout_tx_strn but implement it. Have a look at mphalport.c from the other ports.

Re: Problem in micropython porting

Posted: Thu May 14, 2020 6:15 am
by deepak
Thanks stijn for help, the problem was because of mp_hal_stdin_rx_chr/mp_hal_stdout_tx_strn, though i had replaced it with fprintf adn getc in mpy-1.3.8 and it worked so i thought for same.

now i have ported minimal micropython-1.12 to Nuttx, which has only core python and want to run a mpy file on board. i can push the .py file in board but unable to execute. would you like to let me know how can i execute .py file in board?

Re: Problem in micropython porting

Posted: Thu May 14, 2020 6:52 pm
by stijn
Sorry don't know, little experience with that.
But you should provide more info anyway: 'unable to execute' is a bit vague. Is there an actual error message?

Re: Problem in micropython porting

Posted: Thu May 14, 2020 10:37 pm
by dhylands
fprintf on stdout by default is line buffered, so the output won't be sent until a \n is sent. So you should follow your fprintf call with an fflush call.

Re: Problem in micropython porting

Posted: Mon May 18, 2020 6:52 am
by deepak
stijn wrote:
Thu May 14, 2020 6:52 pm
Sorry don't know, little experience with that.
But you should provide more info anyway: 'unable to execute' is a bit vague. Is there an actual error message?
Actually i want to run a simple test file e.g. mat_mul.py (file contains simple matrix multiplication program). so can you please tell me how can i run this file on board.

i tried with following way:
i pushed the mat_mul.py into the board. i tried to run this file as "micropython mat_mul.py" then micropython REPL opened but didn't execute the file. this is happening because i ported minimal micropython to Nuttx
so it is not supposed to take the file as the command line arguments.

i think it can take the file as a command line arguments if i port unix micropython to Nuttx but currently, i don't want to.

can you tell me any other way?

dhylands wrote:
Thu May 14, 2020 10:37 pm
fprintf on stdout by default is line buffered, so the output won't be sent until a \n is sent. So you should follow your fprintf call with an fflush call.
i did the same. but it was not working.
now it's working with mp_hal_stdin_rx_chr/mp_hal_stdout_tx_strn after ading unix_mphal.c and mpconfigport.h as the source files.

Re: Problem in micropython porting

Posted: Mon May 18, 2020 1:20 pm
by stijn
If you want to execute the file passed on the commandline, there's not really any other way than to add code for parsing the commandline to get the path/name of the file and to pass that to a function like pyexec_file (from pyexec.c) to get it executed.