Btree Module on stm32

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Drako
Posts: 12
Joined: Thu Oct 19, 2017 9:28 am

Btree Module on stm32

Post by Drako » Thu Mar 08, 2018 11:09 am

Hi,

I tried to implement the Btree module in a custom board with an stm32F765.

When in implement the line
"#define MICROPY_PY_BTREE (1)"
into the mpconfigboard.h, I get an error when creating the firmware:

"In file included from ../../py/objmodule.h:29:0,
from ../../py/objmodule.c:30:
../../py/objmodule.c:221:19: error: 'MP_QSTR_btree' undeclared here (not in a function)
{ MP_ROM_QSTR(MP_QSTR_btree), MP_ROM_PTR(&mp_module_btree) },
^
../../py/obj.h:92:56: note: in definition of macro 'MP_OBJ_NEW_QSTR'
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
^
../../py/objmodule.c:221:7: note: in expansion of macro 'MP_ROM_QSTR'
{ MP_ROM_QSTR(MP_QSTR_btree), MP_ROM_PTR(&mp_module_btree) },
^"

I used the acutal master branch of micropython (MicroPython v1.9.3-411-g6db0cb78)

I also tried to activate the module in the makefile.
This lead to a different error message, which lead me to also activate :
#define MICROPY_STREAMS_POSIX_API (1)

which ultimatly lead to another error when creating the firmware.

Is this modul working for an stm32 MCU or only for ESP and UNIX ports of micropython?

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

Re: Btree Module on stm32

Post by dhylands » Thu Mar 08, 2018 4:10 pm

When you make a change like that you should do a clean and then rebuild. Otherwise you run into water errors like you're seeing.

Drako
Posts: 12
Joined: Thu Oct 19, 2017 9:28 am

Re: Btree Module on stm32

Post by Drako » Fri Mar 09, 2018 8:05 am

Hi,

good advice, but I didn't get to compile the firmware for an stm32 port with the BTREE module enabled.

When I add the define for BTREE in the mpconfigboard.h, I get the following error:
build-mcCPU_F7V01/py/objmodule.o:(.rodata.mp_builtin_module_table+0xc4): undefined reference to `mp_module_btree'

When I add a define for BTREE in the make file (like in an esp port), I get the following error:
../../extmod/modbtree.c:324:5: error: 'mp_stream_posix_read' undeclared here (not in a function)
mp_stream_posix_read,
^
../../extmod/modbtree.c:325:5: error: 'mp_stream_posix_write' undeclared here (not in a function)
mp_stream_posix_write,
^
../../extmod/modbtree.c:326:5: error: 'mp_stream_posix_lseek' undeclared here (not in a function)
mp_stream_posix_lseek,
^
../../extmod/modbtree.c:327:5: error: 'mp_stream_posix_fsync' undeclared here (not in a function)
mp_stream_posix_fsync
^

When I then add a define for the Posix api in the mpconfigport.h (#define MICROPY_STREAMS_POSIX_API (1)) and add the posix_helpers.c to the source in the makefile, I get to the following error:
build-mcCPU_F7V01/posix_helpers.o: In function `m_malloc':
posix_helpers.c:(.text.m_malloc+0x0): multiple definition of `m_malloc'
build-mcCPU_F7V01/py/malloc.o:malloc.c:(.text.m_malloc+0x0): first defined here
build-mcCPU_F7V01/posix_helpers.o: In function `m_free':
posix_helpers.c:(.text.m_free+0x0): multiple definition of `m_free'
build-mcCPU_F7V01/py/malloc.o:malloc.c:(.text.m_free+0x0): first defined here
build-mcCPU_F7V01/posix_helpers.o: In function `m_realloc':
posix_helpers.c:(.text.m_realloc+0x0): multiple definition of `m_realloc'
build-mcCPU_F7V01/py/malloc.o:malloc.c:(.text.m_realloc+0x0): first defined here
build-mcCPU_F7V01/extmod/modbtree.o: In function `mod_btree_open':
modbtree.c:(.text.mod_btree_open+0x54): undefined reference to `__errno'
build-mcCPU_F7V01/extmod/modbtree.o: In function `btree_seq':
modbtree.c:(.text.btree_seq+0x2c): undefined reference to `__errno'
build-mcCPU_F7V01/extmod/modbtree.o: In function `btree_iternext':
modbtree.c:(.text.btree_iternext+0x56): undefined reference to `__errno'
build-mcCPU_F7V01/extmod/modbtree.o: In function `btree_subscr':
modbtree.c:(.text.btree_subscr+0x78): undefined reference to `__errno'
build-mcCPU_F7V01/extmod/modbtree.o: In function `btree_get.part.0':
modbtree.c:(.text.unlikely.btree_binary_op.part.1+0x2): undefined reference to `__errno'
build-mcCPU_F7V01/lib/berkeley-db-1.xx/btree/bt_close.o:bt_close.c:(.text.__bt_sync+0x1a): more undefined references to `__errno' follow


Before each build I did a make clean.

Long question short, did anyone of you get the BTREE module to run in an stm32 port, because in the doc of the pyboard the module is listed?

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

Re: Btree Module on stm32

Post by pythoncoder » Fri Mar 09, 2018 9:00 am

I don't know the status of the official port but the Loboris port claims to support it: see this post.
Peter Hinch

User avatar
oserror
Posts: 43
Joined: Tue Feb 12, 2019 12:26 am

Re: Btree Module on stm32

Post by oserror » Tue Apr 23, 2019 2:55 pm

I know this is an old thread but I was able to build btree support into the Pyboard 1.1 firmware.

If this interests you, make the following changes to the code:

Change the target board to build for (pretty obvious but here it is) in the Makefile:

Code: Select all

BOARD ?= PYBV11
Copy posix_helpers.c from the esp8266 port. Add it to the Makefile in the SRC_C section, appending it to the list with a trailing backslash:

Code: Select all

posix_helpers.c \
Also pretty obviously, add btree module to mpconfigport.mk:

Code: Select all

MICROPY_PY_BTREE = 1
mpconfigport.h: add this line for ssize_t, off_t (and probably others):

Code: Select all

#include <sys/types.h>
also add a #define to mpconfigport.h:

Code: Select all

#define MICROPY_STREAMS_POSIX_API (1)
add this to the end of mphalport.c (fixes __errno reference):

Code: Select all

extern int mp_stream_errno;
int *__errno() {
    return &mp_stream_errno;
}
Thanks to @Drako for his informative post. I had some spare time over the weekend and I did a lot of grep-ing on the code to find the missing references. I have a program reading from an existing btree database right now and it's working splendidly.

Post Reply