micropython icon indicating copy to clipboard operation
micropython copied to clipboard

/t/main.py

Open ubaldus opened this issue 4 years ago • 13 comments

Would it make sense to add a /t/main.py check and eventual execution by default?

I mean I think that is the spirit of boot.py and main.py so having in this case an sd card would be a pity not to implement it :)

ubaldus avatar Sep 09 '20 14:09 ubaldus

What kind of problem this solves?

pulkin avatar Sep 09 '20 15:09 pulkin

The idea is that I could rewrite the main.py on the sd card without having to burn again the whole firmware nor risking to mess up with the internal storage

ubaldus avatar Sep 09 '20 15:09 ubaldus

Do you say you have problems rewriting /main.py as a part of internal SPI memory?

pulkin avatar Sep 09 '20 15:09 pulkin

No, my idea is that I burn the firmware, so the device is ready and working, I can then pack it into a nice case but anytime I want to change something I will just need to rewrite the /t/main.py on the sd card without having to take the board out and burn a new firmware.

ubaldus avatar Sep 09 '20 15:09 ubaldus

or having to connect via serial which is also not as easy as to connect via wifi for instance on the esp32...

ubaldus avatar Sep 09 '20 15:09 ubaldus

You may put /main.py with

sys.path.append("/t")
import main_from_sd_card

before packing into a nice case. Then, change to whatever you want in /t/main_from_sd_card.py.

pulkin avatar Sep 09 '20 15:09 pulkin

By the way you don't have to re-burn firmware to update main.py, you can use ampy, and upload files through UART.

bokolob avatar Sep 09 '20 15:09 bokolob

of course Pulkin I could do it so but I would then need to connect the board to the HST pins, burn the firmware, then connect the uart, write the /main.py and disconnect which is fine if I am doing on a board but what if I am flashing hundreds?

I mean I could also easily write my own version of modules/_boot.py I was just wondering if a similar feature could be helpful to someone else and as micropython already is anyway looking for a /boot.py and a /main.py why not adding for this specific board support for a /t/main.py? :)

ubaldus avatar Sep 09 '20 15:09 ubaldus

Oh, I've got your point.

bokolob avatar Sep 09 '20 15:09 bokolob

but what if I am flashing hundreds?

Then you may update _boot.py with your code, rebuild the firmware and flash it hundred times.

If you provide an example of at least one other mainstream mpy firmware with this behaviour I might want to look into it. Otherwise mpy-specific features follow a simple logic: if it is present esp8266 / esp32 it is better to implement it just because people come here with this background. Otherwise fewer code is better.

pulkin avatar Sep 09 '20 15:09 pulkin

Yesterday, I put machine.restart() line at boot.py ! It's takes me a while to reburn firmware.

From documentation: https://docs.micropython.org/en/latest/pyboard/general.html `` When the pyboard boots up, it needs to choose a filesystem to boot from. If there is no SD card, then it uses the internal filesystem /flash as the boot filesystem, otherwise, it uses the SD card /sd. After the boot, the current directory is set to one of the directories above.

If needed, you can prevent the use of the SD card by creating an empty file called /flash/SKIPSD. If this file exists when the pyboard boots up then the SD card will be skipped and the pyboard will always boot from the internal filesystem (in this case the SD card won’t be mounted but you can still mount and use it later in your program using os.mount).

``

https://github.com/micropython/micropython/issues/1915

ens4dz avatar Sep 22 '20 00:09 ens4dz

Question is now, should we run /boot.py and /main.py anyway first if they are present?

    // Startup scripts
    pyexec_frozen_module("_boot.py");
    pyexec_file_if_exists("boot.py");
    if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
        pyexec_file_if_exists("/t/boot.py");
    }
    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        pyexec_file_if_exists("main.py");
        if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
            pyexec_file_if_exists("/t/main.py");
        }
    }

ubaldus avatar Sep 22 '20 10:09 ubaldus

Question is now, should we run /boot.py and /main.py anyway first if they are present?

    // Startup scripts
    pyexec_frozen_module("_boot.py");
    pyexec_file_if_exists("boot.py");
    if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
        pyexec_file_if_exists("/t/boot.py");
    }
    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        pyexec_file_if_exists("main.py");
        if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
            pyexec_file_if_exists("/t/main.py");
        }
    }

take a look here: https://github.com/micropython/micropython/blob/42342fa3cb30e2eac56ceb1d21b4eb60a0f406f3/ports/stm32/main.c#L624

ens4dz avatar Sep 22 '20 14:09 ens4dz