Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create "code.py" when creating the filesystem #2149

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

Closed
tannewt opened this issue Sep 12, 2019 · 17 comments Β· Fixed by #2584
Closed

Create "code.py" when creating the filesystem #2149

tannewt opened this issue Sep 12, 2019 · 17 comments Β· Fixed by #2584

Comments

@tannewt
Copy link
Member

tannewt commented Sep 12, 2019

That way folks who install it have a file to edit. Bonus points if there is a very small bit of useful code. (Maybe just print("Hello world!")? It could be the translation too.)

@jerryneedell
Copy link
Collaborator

jerryneedell commented Sep 12, 2019

I'm not convinced this is a good idea. I assume you are not intending for it to have a "while True" loop in it. That would be even worse. But my concern is that now it gets executed everything the board reboots unless it is deleted. Just bothers me ;-) I guess I think the users should have some understanding of what is going on. this seems like a bit too much handholding to me. Just my opinion.

@tannewt
Copy link
Member Author

tannewt commented Sep 12, 2019

What do you mean by "But my concern is that now it gets executed everything the board reboots unless it is deleted." ?

The reason to do it is that we teach people to "plug it in and edit code.py" which works for boards that ship with CircuitPython and a demo but doesn't when they install CircuitPython themselves.

@jerryneedell
Copy link
Collaborator

I guess I have never been a big fan of using code.py in general. I only use it for finished projects. I much prefer to edit my files off line and copy them to the file system then execute from the REPL. I realize that is not the "official" workflow.

@deshipu
Copy link

deshipu commented Sep 12, 2019

An empty code.py seems like a good idea, but example code is going to take extra flash space, can we afford that?

@deshipu
Copy link

deshipu commented Sep 12, 2019

I wonder if it would be possible to extend the uf2 bootloader to support SPI flash, then we could have the initial filesystem contents in the uf2 file without taking extra flash space.

@iayanpahwa
Copy link

I think it would be really great to have a code.py file considering the fact that recommended mu editor looks for that file and automatically loads in on detecting a CP board. A small demo code to print hello world or LED blink will also be great to have. @tannewt can I work on this one ?

@jepler
Copy link

jepler commented Oct 25, 2019

@iayanpahwa Please feel free to work on this and file a pull request.

In case you didn't learn this yet for yourself, the area of the code to work in is probably supervisor/shared/filesystem.c between

        // No filesystem so create a fresh one, or reformat has been requested.
        uint8_t working_buf[_MAX_SS];
        res = f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));

and

        // and ensure everything is flushed
        supervisor_flash_flush();

@iayanpahwa
Copy link

iayanpahwa commented Oct 26, 2019

@jepler Thank you for code reference. I'll start working on it :)

@iayanpahwa
Copy link

@tannewt @jepler should we do code.py have

  • print ('Hello World!') or
  • Blink BUILT_IN LED program

@jepler
Copy link

jepler commented Nov 13, 2019

@iayanpahwa let's start with "Hello World". It can be changed to a more sophisticated example later on, if that's what's desired.

@deshipu
Copy link

deshipu commented Nov 14, 2019

I would also love to be able to disable this on per-board basis, to save space for the smaller boards.

@jepler
Copy link

jepler commented Nov 14, 2019

@deshipu I agree. @iayanpahwa after you have the basics working, let us know if you need guidance on how to make the code optional

@iayanpahwa
Copy link

@deshipu sounds cool. @jepler thinking a makefile flag?

@jepler
Copy link

jepler commented Nov 14, 2019

@iayanpahwa yes something that can be controlled from a mpconfigboard.mk file would be the ideal result. Ideally you would make the default be $(CIRCUITPY_FULL_BUILD) so that it is automatically excluded on chips with less program space available.

You may find it useful to study how e.g., CIRCUITPY_DISPLAYIO works. Files involved include individual mpconfigboard.mk files, py/circuitpy_mpconfig.mk to set a default value, and supervisor/shared/display.c to make a decision based on whether CIRCUITPY_DISPLAYIO is enabled or not.

Let us know how it goes!

@iayanpahwa
Copy link

PR Created - #2299

@iayanpahwa
Copy link

PR #2299 merged. This issue can now be closed.

@jepler jepler closed this as completed Nov 27, 2019
@jepler
Copy link

jepler commented Nov 27, 2019

Thanks @iayanpahwa !

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

Successfully merging a pull request may close this issue.

5 participants