Problem in micropython porting

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
deepak
Posts: 8
Joined: Sun Apr 19, 2020 5:20 pm

Problem in micropython porting

Post by deepak » Tue May 05, 2020 7:56 am

Hi,

I am new to micropython and was trying to port micropython v1.12 to TizenRT which is based on 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:


System Information:
Version: 3.0
Commit Hash: c06ed70de468e740f836f8b8991385c67399ebcf
Build User: deepak@lin-2030025426
Build Time: 2020-05-05 04:24:14
System Time: 08 Jun 2014, 00:00:00 [s] UTC
TASH>>[WM]T8 _wifi_utils_callback_handler:169
run utils callback handler (should be moved to booting)
Hello, World!!

TASH>>
TASH>>micropython
Micro Python 3.0_GBM-397-gc06ed70de on 2020-05-05
Type "help()" for more information.
>>> 3*2
>>>
>>> 3* 2*
>>> 4+*4
>>> 4+
>>> 4-4
>>>
>>> p-rin t


in this i typed 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.

stijn
Posts: 464
Joined: Thu Apr 24, 2014 9:13 am

Re: Problem in micropython porting

Post by stijn » Tue May 05, 2020 10:51 am

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.

deepak
Posts: 8
Joined: Sun Apr 19, 2020 5:20 pm

Re: Problem in micropython porting

Post by deepak » Thu May 14, 2020 6:15 am

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 TizenRT, which has only core python and want to run a mpy file on board. i can push the .py file in board using TizenRT FS but unable to execute. would you like to let me know how can i execute .py file in board?

stijn
Posts: 464
Joined: Thu Apr 24, 2014 9:13 am

Re: Problem in micropython porting

Post by stijn » 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?

User avatar
dhylands
Posts: 3391
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Problem in micropython porting

Post by dhylands » 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.

deepak
Posts: 8
Joined: Sun Apr 19, 2020 5:20 pm

Re: Problem in micropython porting

Post by deepak » Mon May 18, 2020 6:52 am

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, TizenRT(with ported micropython) is running on that 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 TizenRT
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 TizenRT 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.

stijn
Posts: 464
Joined: Thu Apr 24, 2014 9:13 am

Re: Problem in micropython porting

Post by stijn » Mon May 18, 2020 1:20 pm

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.

Post Reply