Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/t/main.py #81

Open
ubaldus opened this issue Sep 9, 2020 · 13 comments
Open

/t/main.py #81

ubaldus opened this issue Sep 9, 2020 · 13 comments

Comments

@ubaldus
Copy link

ubaldus commented Sep 9, 2020

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

@pulkin
Copy link
Owner

pulkin commented Sep 9, 2020

What kind of problem this solves?

@ubaldus
Copy link
Author

ubaldus commented Sep 9, 2020

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

@pulkin
Copy link
Owner

pulkin commented Sep 9, 2020

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

@ubaldus
Copy link
Author

ubaldus commented Sep 9, 2020

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
Copy link
Author

ubaldus commented Sep 9, 2020

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

@pulkin
Copy link
Owner

pulkin commented Sep 9, 2020

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.

@bokolob
Copy link

bokolob commented Sep 9, 2020

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

@ubaldus
Copy link
Author

ubaldus commented Sep 9, 2020

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? :)

@bokolob
Copy link

bokolob commented Sep 9, 2020

Oh, I've got your point.

@pulkin
Copy link
Owner

pulkin commented Sep 9, 2020

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.

@ens4dz
Copy link

ens4dz commented Sep 22, 2020

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

``

micropython#1915

@ubaldus
Copy link
Author

ubaldus commented Sep 22, 2020

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");
        }
    }

@ens4dz
Copy link

ens4dz commented Sep 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants