2021年4月5日星期一

PICO hangs on micropython object creation

I recently started working on a small driver for the raspberry pico and the bme280 sensor. I wanted to use the official bosh API written in C and therefore decided to write all the code in C using the micropython C api to write usermodules. I managed to get my code compiled into a UF2 file and my module shows up when I try to list the modules with help('modules'). When I import my module the class with the driver code shows up in dir(mymodule) but when I try to create an object the terminal connected to the PICO hangs and doesn't respond anymore.

typedef struct {      mp_obj_base_t base;      uint8_t sda;      uint8_t scl;      uint8_t i2c_address;  } BME280_obj_t;    const mp_obj_type_t BME280_class_type;      STATIC mp_obj_t BME280_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {      mp_arg_check_num(n_args, n_kw, 2, 2, true);      BME280_obj_t* self = m_new_obj(BME280_obj_t);      self->base.type = &BME280_class_type;      self->sda = mp_obj_get_int(args[0]);      self->scl = mp_obj_get_int(args[1]);      self->i2c_address = n_args <= 2? BME280_I2C_ADDR_SEC : mp_obj_get_int(args[2]);      return MP_OBJ_FROM_PTR(self);  }    STATIC const mp_rom_map_elem_t BME280_locals_dict_table[] = {      // for testing purpose i removed all methods from the class  };      STATIC MP_DEFINE_CONST_DICT(BME280_locals_dict, BME280_locals_dict_table);    const mp_obj_type_t BME280_type = {      { &mp_type_type },      .name = MP_QSTR_BME280,      .print = BME280_print,      .make_new = BME280_make_new,      .locals_dict = (mp_obj_dict_t*) &BME280_locals_dict,  };    STATIC const mp_rom_map_elem_t bme280_module_globals_table[] = {      { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bme280) },      { MP_OBJ_NEW_QSTR(MP_QSTR_BME280), (mp_obj_t)&BME280_class_type }  };    STATIC MP_DEFINE_CONST_DICT(bme280_module_globals, bme280_module_globals_table);    // module registration    const mp_obj_module_t bme280_user_cmodule = {      .base = { &mp_type_module },      .globals = (mp_obj_dict_t*)&bme280_module_globals,  };    MP_REGISTER_MODULE(MP_QSTR_melopero_bme280, melopero_bme280_user_cmodule, 1);  

I think the problem relies somewhere in the initialization procedure since it does not go further... Maybe there is something that micropython is doing behind the scenes that I'm ignoring. There is not so many documentation on writing usermodules in C... any help/hints/ideas are greatly apreciated :)

https://stackoverflow.com/questions/66952337/pico-hangs-on-micropython-object-creation April 05, 2021 at 07:33PM

没有评论:

发表评论