Page 1 of 1

frozen module not imported in PyBoard like hw

Posted: Fri Feb 01, 2019 8:36 am
by lnsri22
Hello Everyone!!

I have made my main.py a frozen module and my frozen module directory is "modules"

I have put up main.py in drivers directory and have created a symbolic link to that file in modules

I have modified main.c like this

Code: Select all

// Run the main script from the current directory.
    if ((reset_mode == 1 || reset_mode == 3) && pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        const char *main_py;
        if (MP_STATE_PORT(pyb_config_main) == MP_OBJ_NULL) {
            main_py = "main.py";
        } else {
            main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main));
        }
        mp_import_stat_t stat = mp_import_stat(main_py);
        if (stat == MP_IMPORT_STAT_FILE) {
            int ret = pyexec_frozen_module(main_py);
            if (ret & PYEXEC_FORCED_EXIT) {
                goto soft_reset_exit;
            }
            if (!ret) {
                flash_error(3);
            }
        }
    }
But the control is not transferred inside this part (i.e reset_mode is neither 1 nor 3 always)

If I force the reset_mode to be 1 like this,

Code: Select all

reset_mode = 1;
the frozen_module is imported. What could be the possible cause

If I'm messing up with something w.r.t reset_mode, what could be that

Any help is greatly appreciated!!

Thanks in advance!!

Re: frozen module not imported in PyBoard like hw

Posted: Fri Feb 01, 2019 5:14 pm
by dhylands
In order to execute a frozen main.py or boot.py then you need to modify main.c to do something like this:
https://github.com/micropython/micropyt ... ain.c#L315

The current main.c will only execute main.py from a filesystem, not as a frozen file.

Re: frozen module not imported in PyBoard like hw

Posted: Fri Feb 01, 2019 5:18 pm
by lnsri22
Thanks 🙏🙇 Dave!!

Let me give it a try and update you. But this was somehow running earlier when firmware0 and firmware1 were put in their default spaces. I mean (0*08000000) and (0*08020000) respectively.

Re: frozen module not imported in PyBoard like hw

Posted: Fri Feb 01, 2019 5:21 pm
by lnsri22
Dave I have a question here. This seem to run when I make reset_mode=1 manually as discussed in my above thread.


Is there any specific reason for this behavior?


Thanks again!!

Re: frozen module not imported in PyBoard like hw

Posted: Fri Feb 01, 2019 5:35 pm
by dhylands
Then that suggests that you have something misconfigured.

This line is where reset_mode gets set:
https://github.com/micropython/micropyt ... ain.c#L579

The only reason for reset_mode to get a value not equal to 1 is that the update_reset_mode function thinks that the user switch is pressed at boot time.

If you don't have a user switch then you should have MICROPY_HW_HAS_SWITCH set to 0.

If you do have a user switch then you need to configure it properly:
https://github.com/micropython/micropyt ... .h#L76-L79

Re: frozen module not imported in PyBoard like hw

Posted: Sat Feb 02, 2019 6:20 am
by lnsri22
dhylands wrote:
Fri Feb 01, 2019 5:14 pm
In order to execute a frozen main.py or boot.py then you need to modify main.c to do something like this:
https://github.com/micropython/micropyt ... ain.c#L315

The current main.c will only execute main.py from a filesystem, not as a frozen file.
Dave, I went through what you had suggested.

In the file "py/mpconfig.h", both "MICROPY_MODULE_FROZEN_MPY" and "MICROPY_MODULE_FROZEN_STR" are defined to be (0).

Should I make it (1) such that the frozen module is enabled?

Please advice!!

Re: frozen module not imported in PyBoard like hw

Posted: Sat Feb 02, 2019 7:12 am
by lnsri22
lnsri22 wrote:
Sat Feb 02, 2019 6:20 am
dhylands wrote:
Fri Feb 01, 2019 5:14 pm
In order to execute a frozen main.py or boot.py then you need to modify main.c to do something like this:
https://github.com/micropython/micropyt ... ain.c#L315

The current main.c will only execute main.py from a filesystem, not as a frozen file.
Dave, I went through what you had suggested.

In the file "py/mpconfig.h", both "MICROPY_MODULE_FROZEN_MPY" and "MICROPY_MODULE_FROZEN_STR" are defined to be (0).

Should I make it (1) such that the frozen module is enabled?

Please advice!!
Sorry Dave!!

That change was actually not needed!!

After implementing your suggestion, it worked like a charm!!


You are really my time-saver!! :)