ubinascii

Why doesn’t OpenMV support ubinascii?

http://docs.micropython.org/en/latest/pyboard/library/ubinascii.html?highlight=binascii

It just isn’t linked into the build.

I can fix that for you in a custom image after I get this release out.

Um, just a question, do you have a linux computer and do you know how to compile MicroPython? If so, you should just get setup with the firmware dev environment to have full control.

No, I don’t have a linux machine so let me know when you have custom image for me to test it. Thanks!

See here just for info: https://github.com/openmv/openmv/wiki/Firmware-Development

You can do a ubuntu vm on a windows machine.

How do you link the modubinascii into the build? Do I need to just add it to the make file?

In the openmv repository, you need to populate the micropython repository by doing git submodule update --init and then you should see files in openmv/src/micropython

When you boot the OpenMV board, the banner shows as:

MicroPython v1.8-4348-g62d6127 on 2016-12-14; OPENMV2 with STM32F427

which tells me that we want the OPENMV2 board definition file.

It looks like the mpconfigport.h file in OpenMV is still coded the old way (mpconfigboard.h #included at the end rather than the beginning), so this is what you need to do for what’s in the openmv micropython tree.

There are a couple different ways to change the configuration. You can edit openmv/src/micropython/stmhal/mpconfigport.h and change:

#define MICROPY_PY_UBINASCII        (0)

to be:

#define MICROPY_PY_UBINASCII        (1)

This will change the setting for all of the stmhal boards (which includes all of the OPENMV boards). Or you edit OPENMV2/openmv/src/micropython/stmhal/boards/OPENMV2/mpconfigboard.h and add:

#undef MICROPY_PY_UBINASCII
#define MICROPY_PY_UBINASCII        (1)

to only turn it on for the OPENMV2 board.

With the above, I get these errors:

CC ../py/objmodule.c
In file included from /Users/abencomo/git/openmv/src/micropython/py/mpstate.h:34:0,
                 from ../py/objmodule.c:30:
../py/objmodule.c:185:19: error: 'MP_QSTR_ubinascii' undeclared here (not in a function)
     { MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) },
                   ^
/Users/abencomo/git/openmv/src/micropython/py/obj.h:91: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:185:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) },



With the latter, it generates the firmware; but it still didn’t include the ubinascii module.

MicroPython 38c54bf on 2017-01-23; OPENMV2 with STM32F427
Type "help()" for more information.
>>> import ubinascii
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'ubinascii'

BTW, I’m able to build the OpenMV firmware on OSX without an ubuntu vm. :astonished:

Anytime I get qstr errors, I normally do a clean and rebuild and then they go away. There’s a problem with the Makefile dependencies that makes it not rescan for qstrs when it should.

ok - It looks like there’s a custom Makefile being used as well. So you’ll need to edit openmv/src/Makefile. Around line 308, you should see:

FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/extmod/,\
	fsusermount.o       \
	vfs_fat.o           \
	vfs_fat_ffconf.o    \
	vfs_fat_diskio.o    \
	vfs_fat_file.o      \
	vfs_fat_lexer.o     \
	vfs_fat_misc.o      \
	machine_mem.o       \
	machine_i2c.o       \
    )

Add a line for modubinascii.o at the end (make sure there is a backslash at the end of the line).

I also noticed that your banner shows as:

MicroPython 38c54bf on 2017-01-23; OPENMV2 with STM32F427

It should show as

MicroPython 38c54bf-dirty on 2017-01-23; OPENMV2 with STM32F427

(i.e. with -dirty after the git hash). The fact that yours shows without the -dirty tells me that your firmware isn’t running the customized version.

This time I tested it and it seems to be working:

MicroPython 38c54bf-dirty on 2017-01-23; OPENMV2 with STM32F427
Type "help()" for more information.
>>> import ubinascii
>>> dir(ubinascii)
['__name__', 'hexlify', 'unhexlify', 'a2b_base64', 'b2a_base64']
>>>

I ran make clean as you suggested and I now get this error:

..
CC src/usbd_desc.c
/Users/abencomo/git/openmv/src/build/micropython/py/objmodule.o:(.rodata.mp_builtin_module_table+0x54): undefined reference to `mp_module_ubinascii'
collect2: error: ld returned 1 exit status
make: *** [firmware] Error 1

Sorry for the delayed response (I decided to test what I suggested). See my post just before yours :slight_smile:

Thanks Dave. Your last post did it. It works now and it’s cool that I can build it from my Mac OSX. Cheers!

MicroPython 38c54bf-dirty on 2017-01-23; OPENMV2 with STM32F427
Type "help()" for more information.
>>> import ubinascii
>>>

Cool, um, so, if you want to fix the machine.I2C issue just pull the latest file from Micropython in and patch the code manually.