Skip to content

opentitan i2c: zero-length requests hang #680

@midnightveil

Description

@midnightveil

The micropython machine_i2c_scan command performs zero-length writes with a STOP condition.

static mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
    mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in);
    mp_obj_t list = mp_obj_new_list(0, NULL);
    // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
    for (int addr = 0x08; addr < 0x78; ++addr) {
        int ret = mp_machine_i2c_writeto(self, addr, NULL, 0, true);
        if (ret == 0) {
            mp_obj_list_append(list, MP_OBJ_NEW_SMALL_INT(addr));
        }
        // This scan loop may run for some time, so process any pending events/exceptions,
        // or allow the port to run any necessary background tasks.  But do it as fast as
        // possible, in particular we are not waiting on any events.
        mp_event_handle_nowait();
    }
    return list;
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);

In the case of the Opentitan i2c driver, this results in it hanging.

We should:

  1. Fix this
  2. Add sDDF tests to verify this case is OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingi2c

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions