Skip to content

Supervisor: create code.py file with sample code #2299

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

Merged
merged 7 commits into from
Nov 27, 2019
Merged

Supervisor: create code.py file with sample code #2299

merged 7 commits into from
Nov 27, 2019

Conversation

iayanpahwa
Copy link

Addresses Issue #2149

Create a sample code.py file during board flashing with a print hello world program. Tested on CircuitPlayground Express Board.

To-Do's:

1- Add compiler flags to disable this feature on non-express / limited memory boards
2- Error handling when fail to write the file for any reason

@tannewt
Copy link
Member

tannewt commented Nov 19, 2019

You may be able to save space by creating an empty file for small boards instead of one with basic code.

@iayanpahwa
Copy link
Author

@tannewt I'm not sure how to do that, any pointers will be appreciated :)

@iayanpahwa
Copy link
Author

@jepler , @dhalbert please share review comments :)

@jepler
Copy link

jepler commented Nov 20, 2019

Besides my comments directly on the code, a build failed:

 Build pirkey_m0 for zh_Latn_pinyin took 12.46s and failed
make: Entering directory '/home/runner/work/circuitpython/circuitpython/ports/atmel-samd'
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.

-48 bytes free in flash out of 188160 bytes ( 183.75 kb ).
26000 bytes free in ram for stack out of 32768 bytes ( 32.0 kb ).

Too little flash!!!```

By making this new feature optional, and keeping it disabled for "small" (resource-constrained) boards, this problem can be resolved.

@iayanpahwa
Copy link
Author

Thanks @jepler for the review comments and suggestions. I'll push the changes as requested soon.

@tannewt
Copy link
Member

tannewt commented Nov 20, 2019

@iayanpahwa It would be something like:

#if CIRCUITPY_FULL_BUILD == 0
make_empty_file(&vfs_fat->fatfs, "/code.py");
#else
make_sample_code_file(&vfs_fat->fatfs);
#endif

@iayanpahwa
Copy link
Author

@tannewt tried what you suggested, It's breaking builds on some boards. Any idea?

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the failed builds was arduino_mkr1300 so in ports/atmel-samd you can make BOARD=arduino_mkr1300 to check that your changes have fixed the errors that were detected during CI. (I didn't look at other builds, but most likely they all have the same underlying cause)

@iayanpahwa
Copy link
Author

iayanpahwa commented Nov 25, 2019

@jepler pushed the fix. Build still failing for pirkey_mo, what do you suggest we do now?

-8 bytes free in flash out of 188160 bytes ( 183.75 kb ).

@jepler
Copy link

jepler commented Nov 25, 2019

Now, the error is

Build pirkey_m0 for zh_Latn_pinyin took 11.79s and failed
make: Entering directory '/home/runner/work/circuitpython/circuitpython/ports/atmel-samd'
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.

-8 bytes free in flash out of 188160 bytes ( 183.75 kb ).
26000 bytes free in ram for stack out of 32768 bytes ( 32.0 kb ).

Too little flash!!!

The main option now is to do as @deshipu suggested and do not enable any new feature (including creating a zero-length code.py file) on (CIRCUITPY_FULL_BUILD == 0) boards. So the code would become something like

#if CIRCUITPY_FULL_BUILD!= 0
    FIL fs;
    UINT char_written = 0;
    const byte buffer[] = "print('Hello World!')\n";
    //Create or modify existing code.py file 
    f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
    f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
    f_close(&fs);
#endif

specifically without the make_empty_file call. As before you can make BOARD=pirkey_m0 in ports/atmel-samd to check on the result yourself before pushing.

@iayanpahwa
Copy link
Author

@jepler guess that's our only option now :)

@iayanpahwa
Copy link
Author

iayanpahwa commented Nov 25, 2019

@jepler should it be:

#if CIRCUITPY_FULL_BUILD == 0
or
#if CIRCUITPY_FULL_BUILD != 0

? The CIRCUITPY_FULL_BUILD == 0 means build for express boards?

@jepler
Copy link

jepler commented Nov 25, 2019

Right, I had it backwards. (edited the original comment so it is correct now, I hope)

@dhalbert
Copy link
Collaborator

CIRCUITPY_FULL_BUILD == 1 is for Express boards. I'm confused.

@iayanpahwa
Copy link
Author

@dhalbert , @jepler checking on my cpx :)

@iayanpahwa iayanpahwa requested a review from jepler November 25, 2019 19:06
@iayanpahwa
Copy link
Author

@dhalbert you're right. It was

CIRCUITPY_FULL_BUILD == 1

@jepler all checks passed with the pushed fix.

@iayanpahwa iayanpahwa changed the title [WIP]: Supervisor: create code.py file with sample code Supervisor: create code.py file with sample code Nov 25, 2019
@iayanpahwa iayanpahwa requested a review from dhalbert November 25, 2019 19:44
@iayanpahwa
Copy link
Author

wow this build passed on my machine :/

@tannewt
Copy link
Member

tannewt commented Nov 26, 2019

Sit tight. I'm freeing up some space in pIRkey with PR #2328.

@iayanpahwa
Copy link
Author

@tannewt seems like a plan :)

@iayanpahwa
Copy link
Author

@tannewt it worked.

@jepler , @dhalbert any more changes needed?

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me now. I reviewed the issue discussion: I didn't realize it was consensus to avoid writing the file completely on non-full builds.

@iayanpahwa
Copy link
Author

iayanpahwa commented Nov 27, 2019

@dhalbert creation of even empty file idea was dropped because build was failing for pIRKey due to space constraint, Do you think now we have some space for atleast an empty file, since PR #2328 has been merged? If yes maybe we can include that in a different PR.

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 27, 2019

@iayanpahwa I think we could now have this on by default, after the pirkey fix, even for small boards, and for @deshipu and others who need every last byte, it could still be turned off. I think it would be better for the standard boards to be consistent about this.

@jepler jepler merged commit d9c808d into adafruit:master Nov 27, 2019
@iayanpahwa
Copy link
Author

@dhalbert sounds good to me. Let me know what do to next.

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

Successfully merging this pull request may close these issues.

4 participants