Adding a module error
Adding a module error
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.
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
The .name member is deprecated. Just remove that line.
It was removed last Sep: https://github.com/micropython/micropyt ... e1df87c93f
It was removed last Sep: https://github.com/micropython/micropyt ... e1df87c93f
Re: Adding a module error
Thanks but I have changed the function and now appears this error :
Sure I am doing something wrong.
Regards.
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);
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 },
};
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Adding a module error
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.
Index to my micropython libraries.
Re: Adding a module error
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.
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Adding a module error
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.
Index to my micropython libraries.
Re: Adding a module error
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.
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
That was changed recently in master. You can checkout an older version to get the older behavior.