frozen module not imported in PyBoard like hw

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

frozen module not imported in PyBoard like hw

Post by lnsri22 » Fri Feb 01, 2019 8:36 am

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!!
lnsri22 :)

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

Re: frozen module not imported in PyBoard like hw

Post by dhylands » 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.

lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

Re: frozen module not imported in PyBoard like hw

Post by lnsri22 » Fri Feb 01, 2019 5:18 pm

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.
lnsri22 :)

lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

Re: frozen module not imported in PyBoard like hw

Post by lnsri22 » Fri Feb 01, 2019 5:21 pm

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!!
lnsri22 :)

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

Re: frozen module not imported in PyBoard like hw

Post by dhylands » Fri Feb 01, 2019 5:35 pm

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

lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

Re: frozen module not imported in PyBoard like hw

Post by lnsri22 » 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!!
lnsri22 :)

lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

Re: frozen module not imported in PyBoard like hw

Post by lnsri22 » Sat Feb 02, 2019 7:12 am

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!! :)
lnsri22 :)

Post Reply