Problem with minimal Micropython firmware

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
rimbi
Posts: 3
Joined: Tue Jan 04, 2022 7:53 am

Problem with minimal Micropython firmware

Post by rimbi » Tue Jan 04, 2022 8:00 am

Hi All,

I am just new to Micropython and interested in porting it to a new platform. I have followed the porting guide and was able to build the minimal micropython firmware on ubuntu. But when I try to import sys the repl displays the following error:

Code: Select all

>>> import sys
Traceback (most recent call last):
  File "<stdin>", in <module>
ImportError: module not found
On the other hand, I can import gc successfully.

The same problem is observable in the ports/minimal as well.

Any idea about the problem?

Best,
Cem
Last edited by rimbi on Tue Jan 04, 2022 9:48 am, edited 1 time in total.

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

Re: Problem with minimal Micropython firmware

Post by dhylands » Tue Jan 04, 2022 10:05 pm

It looks like the default setting for the sys module to be included by default is that MICROPY_CONFIG_ROM_LEVEL need to to set to at least MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES. For the minimal port, this is set to MICROPY_CONFIG_ROM_LEVEL_MINIMUM.

You can either explicitly enable MICROPY_PY_SYS in your mpconfigport.h file, or you can bump the definition of MICROPY_CONFIG_ROM_LEVEL - this will enable multiple modules and features - so which way you want to do things will depend on how much flash space you have.

For reference, here are the definition associated with MICROPY_CONFIG_ROM_LEVEL:
https://github.com/micropython/micropyt ... .h#L65-L81

and this is where the default for MICROPY_PY_SYS is set:
https://github.com/micropython/micropyt ... 1304-L1307

and this is the definition of MICROPY_CONFIG_ROM_LEVEL for the minimal port: https://github.com/micropython/micropyt ... gport.h#L6

rimbi
Posts: 3
Joined: Tue Jan 04, 2022 7:53 am

Re: Problem with minimal Micropython firmware

Post by rimbi » Wed Jan 05, 2022 6:42 am

Hi Dave,

Thank you very much for the explanation. It really helped me understand the underlying concepts a bit more.

On the other hand, I tried both

- turning on MICROPY_PY_SYS

Code: Select all

#define MICROPY_PY_SYS (1)
- setting MICROPY_CONFIG_ROM_LEVEL to all possible values

Code: Select all

#define MICROPY_CONFIG_ROM_LEVEL MICROPY_CONFIG_ROM_LEVEL_EVERYTHING
and neither worked.

Apparently, the documentation has a problem and needs a fix. I can do that as soon as I find a solution to the problem.

Best,
Cem

rimbi
Posts: 3
Joined: Tue Jan 04, 2022 7:53 am

Re: Problem with minimal Micropython firmware

Post by rimbi » Thu Jan 06, 2022 10:22 am

I have understood the problem. The module is named by default as usys. In order to import it as sys instead,

Code: Select all

#define MICROPY_MODULE_WEAK_LINKS (1)
should be defined in the mpconfigport.h file.

Post Reply