← index #8125Issue #12154
Off-topic · high · value 0.167
QUERY · ISSUE

Cannot import user defined module on Raspberry Pico

openby guilhermebeneopened 2021-12-29updated 2022-01-21
port-rp2

I am trying to compile micropython for my Raspberry Pico with an "user defined module" based on pimoroni's implementation of an Encoder class that uses the Pico's PIOs to interface with motor encoders.

I have followed the tutorials explaining how to compile an user defined module for the Pico and everything seems to work just fine, I get the expected messages while compiling with make USER_C_MODULES=../../../modules/micropython.cmake all:

...
Including User C Module from ../../examples/usercmodule/cexample
Including User C Module from ../../examples/usercmodule/cppexample
...

My files to interface the Encoder class and MicroPython are (I am omitting the cpp to avoid flooding this issue even further):

#include "encoder-pio-wrapper.h"

/***** Methods *****/
MP_DEFINE_CONST_FUN_OBJ_0(Encoder___del___obj, Encoder___del__);

MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_state_a_obj, Encoder_get_state_a);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_state_b_obj, Encoder_get_state_b);

MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_count_obj, Encoder_get_count);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_revolutions_obj, Encoder_get_revolutions);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_angle_degrees_obj, Encoder_get_angle_degrees);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_angle_radians_obj, Encoder_get_angle_radians);

MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_frequency_obj, Encoder_get_frequency);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_revolutions_per_second_obj, Encoder_get_revolutions_per_second);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_revolutions_per_minute_obj, Encoder_get_revolutions_per_minute);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_degrees_per_second_obj, Encoder_get_degrees_per_second);
MP_DEFINE_CONST_FUN_OBJ_0(Encoder_get_radians_per_second_obj, Encoder_get_radians_per_second);

MP_DEFINE_CONST_FUN_OBJ_0(Encoder_zero_count_obj, Encoder_zero_count);

/***** Binding of Methods *****/
STATIC const mp_rom_map_elem_t Encoder_locals_dict_table[] = {
    { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&Encoder___del___obj) },
    { MP_ROM_QSTR(MP_QSTR_get_state_a), MP_ROM_PTR(&Encoder_get_state_a_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_state_b), MP_ROM_PTR(&Encoder_get_state_b_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_count), MP_ROM_PTR(&Encoder_get_count_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_revolutions), MP_ROM_PTR(&Encoder_get_revolutions_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_angle_degrees), MP_ROM_PTR(&Encoder_get_angle_degrees_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_angle_radians), MP_ROM_PTR(&Encoder_get_angle_radians_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_frequency), MP_ROM_PTR(&Encoder_get_frequency_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_revolutions_per_second), MP_ROM_PTR(&Encoder_get_revolutions_per_second_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_revolutions_per_minute), MP_ROM_PTR(&Encoder_get_revolutions_per_minute_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_degrees_per_second), MP_ROM_PTR(&Encoder_get_degrees_per_second_obj) },
    { MP_ROM_QSTR(MP_QSTR_get_radians_per_second), MP_ROM_PTR(&Encoder_get_radians_per_second_obj) },
};

STATIC MP_DEFINE_CONST_DICT(Encoder_locals_dict, Encoder_locals_dict_table);

/***** Class Definition *****/
const mp_obj_type_t Encoder_type = {
    { &mp_type_type },
    .name = MP_QSTR_Encoder,
    .print = Encoder_print,
    .make_new = Encoder_make_new,
    .locals_dict = (mp_obj_dict_t*)&Encoder_locals_dict,
};

/***** Globals Table *****/

STATIC const mp_map_elem_t Encoder_globals_table[] = {
    { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_Encoder) },
    { MP_OBJ_NEW_QSTR(MP_QSTR_Encoder), (mp_obj_t)&Encoder_type },
};

STATIC MP_DEFINE_CONST_DICT(mp_module_Encoder_globals, Encoder_globals_table);

/***** Module Definition *****/
const mp_obj_module_t Encoder_user_cmodule = {
    .base = { &mp_type_module },
    .globals = (mp_obj_dict_t*)&mp_module_Encoder_globals,
};
MP_REGISTER_MODULE(MP_QSTR_Encoder, Encoder_user_cmodule, MODULE_ENCODER_ENABLED);
// Include MicroPython API.
#include "../../micropython/py/obj.h"
#include "../../micropython/py/runtime.h"

/***** Extern of Class Definition *****/
extern const mp_obj_type_t breakout_encoder_BreakoutEncoder_type;
extern const mp_obj_type_t encoder_pio_Encoder_type;

/***** Extern of Class Methods *****/
extern void Encoder_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);

extern mp_obj_t Encoder_init(mp_obj_t self_in);

extern mp_obj_t Encoder_get_state_a(mp_obj_t self_in);
extern mp_obj_t Encoder_get_state_b(mp_obj_t self_in);

extern mp_obj_t Encoder_get_count(mp_obj_t self_in);
extern mp_obj_t Encoder_get_revolutions(mp_obj_t self_in);
extern mp_obj_t Encoder_get_angle_degrees(mp_obj_t self_in);
extern mp_obj_t Encoder_get_angle_radians(mp_obj_t self_in);

extern mp_obj_t Encoder_get_frequency(mp_obj_t self_in);
extern mp_obj_t Encoder_get_revolutions_per_second(mp_obj_t self_in);
extern mp_obj_t Encoder_get_revolutions_per_minute(mp_obj_t self_in);
extern mp_obj_t Encoder_get_degrees_per_second(mp_obj_t self_in);
extern mp_obj_t Encoder_get_radians_per_second(mp_obj_t self_in);

extern void mp_obj_t Encoder_zero_count(mp_obj_t self_in);
// extern mp_obj_t Encoder_perform_capture(mp_obj_t self_in);

However, I cannot import my module by just using import Encoder.
I suspect my makefiles and cmakes are ok because I succeed to compile and link but I am not so sure about it.

CANDIDATE · ISSUE

Build on Debian fails

closedby g0730nopened 2023-08-03updated 2023-08-15
bug

I keep getting this error, while trying to build for Pi-Pico, using my laptop with Debian 10.13:

Just as a test I am building the master branch of micropython found here on github with no modifications. I have updated all build tools, and following instructions to a T.

Attempting to build on my pi zero to see if it works there. Have tried everything I can find in search results for similar issues to no avail.

make
[ -e build-PICO/Makefile ] || cmake -S . -B build-PICO -DPICO_BUILD_DOCS=0 -DMICROPY_BOARD=PICO -DMICROPY_BOARD_DIR=/home/gordon/Desktop/pi0-pico/pico/micropython/ports/rp2/boards/PICO
PICO_SDK_PATH is /home/gordon/Desktop/pi0-pico/pico/micropython/lib/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
PICO compiler is pico_arm_gcc
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-none-eabi-g++
-- Check for working CXX compiler: /usr/bin/arm-none-eabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
Build type is MinSizeRel
PICO target board is pico.
Using board configuration from /home/gordon/Desktop/pi0-pico/pico/micropython/lib/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.7 (found version "3.7.3") found components: Interpreter
TinyUSB available at /home/gordon/Desktop/pi0-pico/pico/micropython/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
CMake Warning at /home/gordon/Desktop/pi0-pico/pico/micropython/lib/pico-sdk/src/rp2_common/pico_btstack/CMakeLists.txt:14 (message):
PICO_BTSTACK_PATH specified but content not present.

CMake Warning at /home/gordon/Desktop/pi0-pico/pico/micropython/lib/pico-sdk/src/rp2_common/pico_lwip/CMakeLists.txt:14 (message):
PICO_LWIP_PATH specified but content not present.

Including custom CMake file /home/gordon/Desktop/pi0-pico/pico/micropython/lib/pico-sdk/src/common/pico_base/generate_config_header.cmake
Found User C Module(s):
ELF2UF2 will need to be built
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gordon/Desktop/pi0-pico/pico/micropython/ports/rp2/build-PICO
make -s -C build-PICO || (echo -e "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"; false)
Scanning dependencies of target BUILD_FROZEN_CONTENT
make[3]: *** No rule to make target 'genhdr/mpversion.h', needed by 'genhdr/qstr.i.last'. Stop.
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/BUILD_FROZEN_CONTENT.dir/all] Error 2
make[1]: *** [Makefile:84: all] Error 2
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [Makefile:46: all] Error 1

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied