STM32 machine.I2C.readfrom_into does not match documentation

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
RWLTOK
Posts: 53
Joined: Thu Dec 14, 2017 7:24 pm

STM32 machine.I2C.readfrom_into does not match documentation

Post by RWLTOK » Fri Apr 03, 2020 3:57 pm

I am working with an I2C device on the PYBOARDV1.1 with V1.12 installed

This line of code was giving me an error

Code: Select all

self._i2c.readfrom_into(self._addr, mvarray[start:end], stop=stop)
If I change the line to:

Code: Select all

self._i2c.readfrom_into(self._addr, mvarray[start:end]) #, stop=stop)
All is good. I don't know how it is on other ports, but I believe the implementation of machine_i2c_readfrom_into for the STM32 port is incorrect.

From https://docs.micropython.org/en/latest/ ... e.I2C.html

I2C.readfrom_into(addr, buf, stop=True, /)
Read into buf from the slave specified by addr. The number of bytes read will be the length of buf. If stop is true then a STOP condition is generated at the end of the transfer.

The method returns None.

code

There is nothing here to deal with the stop=stop keyword parameter.

Code: Select all

STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
    mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
    mp_int_t addr = mp_obj_get_int(args[1]);
    mp_buffer_info_t bufinfo;
    mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
    bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
    int ret = mp_machine_i2c_readfrom(self, addr, bufinfo.buf, bufinfo.len, stop);
    if (ret < 0) {
        mp_raise_OSError(-ret);
    }
    return mp_const_none;
}

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: STM32 machine.I2C.readfrom_into does not match documentation

Post by tve » Fri Apr 03, 2020 5:53 pm

Sure there is: `bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);`.
I'm not sure how KW args are handled, I wonder whether the problem is that to specify a stop arg you need to use `self._i2c.readfrom_into(self._addr, mvarray[start:end], stop)`, i.e., no KW for stop.

User avatar
RWLTOK
Posts: 53
Joined: Thu Dec 14, 2017 7:24 pm

Re: STM32 machine.I2C.readfrom_into does not match documentation

Post by RWLTOK » Fri Apr 03, 2020 9:42 pm

I know it works that way, but that is not how it is documented. The code does not handle the keyword as documented. The way it is documented is the way Circuit Python does it.

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: STM32 machine.I2C.readfrom_into does not match documentation

Post by tve » Fri Apr 03, 2020 10:25 pm

Ah, if you want to file a bug report then github is the best place...

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: STM32 machine.I2C.readfrom_into does not match documentation

Post by jimmo » Sat Apr 04, 2020 11:22 am

RWLTOK wrote:
Fri Apr 03, 2020 3:57 pm
From https://docs.micropython.org/en/latest/ ... e.I2C.html

I2C.readfrom_into(addr, buf, stop=True, /)
That "/" on the end -- that means that this function doesn't take keyword arguments. See https://www.python.org/dev/peps/pep-0570/ and https://github.com/micropython/micropython/issues/5196

Post Reply