[TM4C123] Porting steps after getting the minimal build to work

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

[TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Sun Oct 21, 2018 10:59 am

Hi,
I am currently trying to port uPy to the Tiva Launchpad and have no idea how to proceed after I finished the minimal build.

Is there an API documentation on what functions to implement for the peripherals?

Right now I'm trying to edit the CC3200 port, because it is also a TI chip, but I have problems with the MP_QSTR_* defines, because I don't know how to correctly define them.

Generally is there something to read before proceeding, e.g. on how the whole project is structured?

If you want to check my code right now, i created a Fork here:
https://github.com/ExXeptional/micropyt ... odule_gpio
The files are in ports/tm4c123

I'm sorry if these questions are already answered here but I did not find them.

I'm thankful for any pointers right now

-ExXec

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

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by jickster » Sun Oct 21, 2018 2:47 pm

If you want help, What is a concrete question you have?

Asking people to read your code and give pointers is not the best way to get help.


Sent from my iPhone using Tapatalk Pro

ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Sun Oct 21, 2018 3:05 pm

Yeah ok,

I want to understand how the hardware and the Python layer are connected.
What functions do I need to implement?
What needs to be defined, so that I can "import pyb" etc
What do the "MP_QSTR" do.

I haven't found a thing aboout that.

Those are the main questions right now

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

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by jickster » Sun Oct 21, 2018 11:47 pm

I’ll talk about MP_QSTR_ and we’ll move to other topics once you understand MP_QSTR.

In order to save on runtime speed, uPy uses string-interning.

https://en.wikipedia.org/wiki/String_interning

Strings are mapped to integers and those integers are used for fast comparison and for efficiently passing them around. This integer is represented by the C-type “qstr”.

When you use in your C-code MP_QSTR_xyz there is a preprocessing step done by .py code that creates an entry in the qstring pool which maps an integer to the actual string “xyz”.

This interning of the MP_QSTR_ entries is all done at compile time. This process is also done at runtime: All variable names are also turned into qstrings at runtime.

In your C-code, when you want to write a function that returns a string to the .py context, you do NOT return the type “qstr” because that’s a not an mp_obj_t. You have to do MP_OBJ_NEW_QSTR(qstr theQstr) since that transforms a qstr into a micropython object that points to a string.


Sent from my iPhone using Tapatalk Pro

ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Mon Oct 22, 2018 9:38 pm

Ah I see,
also I forgot to specify the c files as sources for the qstr generator in my makefile.

ok I understand this now :D

please tell me how to tackle the next step
What functions do I need to implement?
What needs to be defined, so that I can "import pyb" etc
thank you

ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Sun Oct 28, 2018 3:37 pm

I still don't know how to make modules importable, can someone please explain this to me?

So far I'm guessing that I have to create a touple of a MP_QSTR and then a pointer to a structure that contains the functionality?
In the CC3200 port this happens in the mpconfigport.h or so, I'm not sure.

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

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by dhylands » Mon Oct 29, 2018 5:05 pm

This commit in my repository: https://github.com/dhylands/micropython ... 3f397ec43e has all of the changes required to create a simple module in C and have it be importable.

In particular, look at the changes in mpconfigport.h

Caveat: This branch was created back in Feb, so it's possible that its out of date, but I think it should be ok.

ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Mon Oct 29, 2018 8:08 pm

This is very helpful, thank you very much! :)

ExXec
Posts: 33
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by ExXec » Tue Nov 20, 2018 6:05 pm

I have another question:

What is the difference between
MP_DEFINE_CONST_FUN_OBJ_0
MP_DEFINE_CONST_FUN_OBJ_1
etc and what do the
MP_DEFINE_CONST_FUN_OBJ_VAR
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
MP_DEFINE_CONST_FUN_OBJ_KW do?

And is it better to base a port on an existing port or to start over completley?
I tried to alter the C3200 port and stm32 port, but I seem to be getting nowhere.

Thanks

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

Re: [TM4C123] Porting steps after getting the minimal build to work

Post by dhylands » Tue Nov 20, 2018 6:19 pm

MP_DEFINE_CONST_FUN_OBJ_0 defines a function object that takes zero arguments.
MP_DEFINE_CONST_FUN_OBJ_1 defines a function object that takes one argument.
MP_DEFINE_CONST_FUN_OBJ_VAR defines a function which takes a variable number of arguments (at least n_args_min)
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN defines a function that takes a variable number of arguments (between n_arg_min and n_arg_max arguments).
MP_DEFINE_CONST_FUN_OBJ_KW defines a function that takes a variable number of arguments (at least n_arg_min) as well as keyword arguments.

You can find most of these used in an example I put together here:
https://github.com/dhylands/micropython ... 3f397ec43e

Basing on an existing port makes sense if your port is VERY similar. Otherwise, I'd probably start with the minimal port and go from there.

What distinguishes one port from another is primarily the set of peripherals that you're using. And unfortunately there is often little or no commonality between the peripherals from the various microcontroller vendors.

Post Reply