MP_QSTR_ not recognized

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Moretti
Posts: 2
Joined: Fri Nov 18, 2016 1:51 am

MP_QSTR_ not recognized

Post by Moretti » Fri Nov 18, 2016 2:07 am

I was just playing around with the code (particularly, a port to the EDU-CIAA https://github.com/micropython/micropython/pull/1732)
and I saw that the SPI code was not compliant with the official documentation so I started to modify it.

The problem is that some MP_QSTR_ definitions are missing (from the new code)

modpybspi.c:68:11: error: 'MP_QSTR_polarity' undeclared (first use in this function)
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1} },


I used stmhal/spi.c as a reference and basically took a copy of the way you handle the function arguments:

pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
...
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
...


I know there is a task to create "qstrdefs.generated.h". Somehow I'm missing that task from the port, and some of the MP_QSTR_ definitions are missing as a result.

Any hints on how to proceed?

Thank you.

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

Re: MP_QSTR_ not recognized

Post by dhylands » Fri Nov 18, 2016 4:08 am

Whenever I run into these, I typically do a make clean, followed by a make.

Moretti
Posts: 2
Joined: Fri Nov 18, 2016 1:51 am

Re: MP_QSTR_ not recognized

Post by Moretti » Fri Nov 18, 2016 2:33 pm

It was, indeed, a newbie mistake. I was assuming the script was parsing all the MP_QSTR_ from the source files to automatically generate them. My bad.

I didn't know they had to be explicitly declared in the qstrdefsport.h file. Mainly because I started to look at the project yesterday, so I still don't know many of the details.


Thank you Dave. The project is awesome BTW.

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

Re: MP_QSTR_ not recognized

Post by dhylands » Fri Nov 18, 2016 4:59 pm

There is a script which does parse the source files looking for the MP_QSTR usages and automatically creates the qstrs, but there seems to be some dependency issues that cause it to not update all of the time.

The script will map most of the QSTRs but not quite all. There are some special cases like QSTRs which contain characters which can't appear in a C identifier.

So the QSTRs in qstrdefports.h are the ones which contain slashes and pluses and that kind of thing.

Post Reply