Adding a module error

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Adding a module error

Post by JPM » Tue Mar 21, 2017 11:37 am

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.

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

Re: Adding a module error

Post by dhylands » Tue Mar 21, 2017 8:04 pm

The .name member is deprecated. Just remove that line.

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

JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Re: Adding a module error

Post by JPM » Wed Mar 22, 2017 10:58 am

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Adding a module error

Post by pythoncoder » Wed Mar 22, 2017 1:44 pm

The function WRITE_PERI_REG doesn't appear in any of the header files. So the compiler sees no function declaration.
Peter Hinch
Index to my micropython libraries.

JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Re: Adding a module error

Post by JPM » Wed Mar 22, 2017 3:50 pm

Thanks, I have added :

Code: Select all

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

Regards.

JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Re: Adding a module error

Post by JPM » Sun Mar 26, 2017 11:02 am

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Adding a module error

Post by pythoncoder » Sun Mar 26, 2017 11:20 am

MicroPython has no mechanism for dynamically loading C modules. You have to flash a firmware build which has been compiled with your module.
Peter Hinch
Index to my micropython libraries.

JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Re: Adding a module error

Post by JPM » Mon Mar 27, 2017 9:48 am

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.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Adding a module error

Post by deshipu » Mon Mar 27, 2017 9:56 am

That was changed recently in master. You can checkout an older version to get the older behavior.

JPM
Posts: 10
Joined: Thu Feb 02, 2017 7:22 pm

Re: Adding a module error

Post by JPM » Mon Mar 27, 2017 11:21 am

Ok, thanks.

Post Reply