Page 1 of 2

Adding a module error

Posted: Tue Mar 21, 2017 11:37 am
by JPM
Hi,

I am trying to create a micropython module from C source.

I am a newbie on this. In compiling process appears the error:

mymodule.c:49:5: error: unknown field 'name' specified in initializer

.name = MP_QSTR_mymodule,

I am using the method decribed in "Adding a Module" from this web.

Any help will be apreciated.

Thanks in advance.

Re: Adding a module error

Posted: Tue Mar 21, 2017 8:04 pm
by dhylands
The .name member is deprecated. Just remove that line.

It was removed last Sep: https://github.com/micropython/micropyt ... e1df87c93f

Re: Adding a module error

Posted: Wed Mar 22, 2017 10:58 am
by JPM
Thanks but I have changed the function and now appears this error :

Code: Select all

mymodule.c:11:5: error: implicit declaration of function 'WRITE_PERI_REG' [-Werror=implicit-function-declaration]
     WRITE_PERI_REG(0x600011f4, 1 << 16 | channel);
Sure I am doing something wrong.

Code: Select all

#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "portmodules.h"

#include <stdio.h>

STATIC mp_obj_t mymodule_hello(void) {
    uint32_t channel;
    channel = 3;
    WRITE_PERI_REG(0x600011f4, 1 << 16 | channel);
    printf("WiFi channel written in system RTC memory\n");
    return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mymodule_hello_obj, mymodule_hello);

STATIC const mp_map_elem_t mymodule_globals_table[] = {
    { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_mymodule) },
};

STATIC MP_DEFINE_CONST_DICT(mp_module_mymodule_globals, mymodule_globals_table);

const mp_obj_module_t mp_module_mymodule = {
    .base = { &mp_type_module },
    .globals = (mp_obj_dict_t*)&mp_module_mymodule_globals,
};

STATIC const mp_map_elem_t mymodule_globals_table[] = {
    { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_mymodule) },
    { MP_OBJ_NEW_QSTR(MP_QSTR_hello), (mp_obj_t)&mymodule_hello_obj },
};
Regards.

Re: Adding a module error

Posted: Wed Mar 22, 2017 1:44 pm
by pythoncoder
The function WRITE_PERI_REG doesn't appear in any of the header files. So the compiler sees no function declaration.

Re: Adding a module error

Posted: Wed Mar 22, 2017 3:50 pm
by JPM
Thanks, I have added :

Code: Select all

#include "eagle_soc.h"
Now everything is ok.

Regards.

Re: Adding a module error

Posted: Sun Mar 26, 2017 11:02 am
by JPM
Hi, I have flashed a ESP-12E with firmware-combined.bin and everything works fine.

In main.py I can import mymodule and I can call mymodule.hello() function.

But I have a noob question. Are there any way to use mymodule in another ESP-12E flashed
with esp8266-20170108-v1.8.7.bin without any reflash ?.

Regards.

Re: Adding a module error

Posted: Sun Mar 26, 2017 11:20 am
by pythoncoder
MicroPython has no mechanism for dynamically loading C modules. You have to flash a firmware build which has been compiled with your module.

Re: Adding a module error

Posted: Mon Mar 27, 2017 9:48 am
by JPM
Thanks and another question,

When I flash the device with esp8266-20170108-v1.8.7.bin Adafruit "ampy -p COM6 ls" tool reports boot.py but
if firmware-combined.bin is flashed that tool reports flash and boot.py is inside of this directory.

What can I do to make the behavior the same as with esp8266-20170108-v1.8.7.bin ?.

Regards.

Re: Adding a module error

Posted: Mon Mar 27, 2017 9:56 am
by deshipu
That was changed recently in master. You can checkout an older version to get the older behavior.

Re: Adding a module error

Posted: Mon Mar 27, 2017 11:21 am
by JPM
Ok, thanks.