Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 32

Thread: HOWTO: Store Projects settings (like F_CPU, USB, Keyboard-layout)

  1. #1
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679

    HOWTO: Store Project Settings

    - Advanced users only -

    I found a way to store project-settings.
    Why ?
    I often need different setting for projects, and often I forget to select the correct options in the IDE.

    The following shows a way to store them on a per-project-basis.
    For example: A Sketch needs - or works best - with F_CPU=144Mhz

    Howto:
    Copy the attached platform.txt to Arduino\hardware\teensy\avr\platform.txt (overwrite the existing, but make a backup before)

    - It adds the following command to the commandline of GCC:"@{build.path}\sketch\defs.h"
    - If the file does not exist, it writes an empty defs.h to prevent error-msgs during compilation

    Create a file "defs.h" in your project-directory (where the .ino file is)
    Example file: (overrides the F_CPU setting)
    Code:
    -UF_CPU
    -DF_CPU=144000000
    - The first line undefines the existing definition
    - The second line defines a new F_CPU (144MHz in this case)

    You're done.
    Sketch-example:
    Code:
    void setup() {
     delay(1000);
     Serial.println(F_CPU);
    }
    
    void loop() {}
    1. Create the mentioned defs.h file above in the same directory.
    2. Compile the sketch with - for example 24MHz - and watch the output.

    The file-extension ".h" is not the best - i tried an other one, but it did not work (the file was not copied to the build-directory)
    (ideas?)


    In the attached platform.txt is a line:
    recipe.hooks.sketch.prebuild.1.pattern.windows=cmd /c if not exist "{build.path}\sketch\defs.h" "echo.>{build.path}\sketch\defs.h"
    [edit]We need one more line for MAC:
    recipe.hooks.sketch.prebuild.1.pattern.macosx=

    Would be great if someone can test this and says "Yes, works!"



    EDIT: Replaced platform.txt with a non-TYQT-version

    EDIT: Find platform.txt for Arduino 1.8.5 in this post: https://forum.pjrc.com/threads/38533...l=1#post172835

    EDIT: Find platform.txt for Arduino 1.8.7 in this post: https://forum.pjrc.com/threads/38533-HOWTO-Store-Projects-settings-(like-F_CPU-USB-Keyboard-layout)?p=187712&viewfull=1#post187712





    Attached Files Attached Files
    Last edited by Frank B; 09-19-2018 at 07:05 PM.

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,310
    One was to do it is to use conditional compilation to use #error if the settings aren't right.

    For example TeensyTransfer uses the following to make sure the speed is 120 Mhz or less:

    Code:
    #if F_CPU>120000000
    #error LOWER CPU SPEED TO 120MHz!!! ...or remove this line and know that the printed Serial and MAC will not be correct :)
    #endif

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Yes.
    But, it can be used for *all* other settings, too. And it does it automatically. Without having to choose different settings via menus.
    Imagine, there is a line
    Code:
    -DRX_BUFFER_SIZE=128
    - If Paul tweaks serial1.c (<- example) a bit (=add #ifdef), this can be used to set the buffer-size without touching serial1.c

    Edit: It is possible now: https://github.com/PaulStoffregen/co.../serial1.c#L39
    Last edited by Frank B; 08-27-2017 at 08:49 AM.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Other possibilites:

    Want to use a special optimization-level ?:
    Code:
    -O2
    In addition, it allows to publish projects with a set of options.
    Last edited by Frank B; 10-23-2016 at 03:02 PM.

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,562
    Hi Frank,

    Looks interesting.

    It is sort of along the lines I was asking about yesterday in the posting: https://forum.pjrc.com/threads/38391...l=1#post119829

    In particular if you look at the standard AVR platform.txt file, it has a section in the file:
    Code:
    # This can be overridden in boards.txt
    build.extra_flags=
    
    # These can be overridden in platform.local.txt
    compiler.c.extra_flags=
    compiler.c.elf.extra_flags=
    compiler.S.extra_flags=
    compiler.cpp.extra_flags=
    compiler.ar.extra_flags=
    compiler.objcopy.eep.extra_flags=
    compiler.elf2hex.extra_flags=
    That it looks like there is a setup to be able to use platform.local.txt, but I have not figured out where these files can be setup.

    Then their receipes use these symbols, like:
    Code:
    ## Compile c++ files
    recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
    So was asking if this worked this way, if it made sense to add these to the Teensy version of platform.txt.

    Thanks Frank

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Kurt,

    if this file "platform.local.txt" can be in the sketch-folder that would be a good way, too.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,562
    So far I have not seen any good documentation on it yet, only some forum posts and the like up on Arduino forum... May have to pull out a non-teensy board and see what it does

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    @Paul:
    And, finally, this is a way to prevent inclusion of unused serial-devices and their RAM-consuming buffers.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,562
    Frank: Quick update, I tried making a simple blink program, that allowed me to define the blink rate... tried putting in platform.local.txt into the sketches folder and it was not picked up.

    I see back at the Arduino issues: https://github.com/arduino/Arduino/issues/3371
    Quote Originally Posted by matthijskooijman

    I added platform.local.txt but never got around to documenting it once the PR got merged.

    The main usecase for platform.local.txt is to allow overriding values in a platform.txt file which is being tracked by e.g. git, so you prevent having modified files. I think it does not allow modifying platform.txt from another directory (e.g. I don't think you can put a sketchbook/hardware/arduino/avr/platform.local.txt file to override arduino_install_dir/hardware/arduino/avr/platform.txt).

    You say you cannot override the compiler.c.flags? I think I had an override for that for a while (to add C++11 support), though I'm not entirely sure now. Where is your platform.local.txt?
    So it looks like it is simply a way for you to add your own settings for all projects that use that platform, as to not edit the main github file...

    So I think your approach is looking more promising.

  10. #10
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Well, it is easier to use without that complicated syntax
    Edit: I have to find a way to use an other extension than ".h" - I don't like that.

    Here's the documentation: https://github.com/arduino/Arduino/w...-specification
    Last edited by Frank B; 10-23-2016 at 03:56 PM.

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    LOL

    6 Downloads, and nobody told me that the platform.txt was the TYQT version (does not work without it) ???

    Post #1 updated.
    Last edited by Frank B; 10-23-2016 at 06:55 PM.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,562
    Sorry, I meant to mention it. Also it was specific to I believe the 32 bit version of TyQt...

    Yes - So of hard to decide what file name to use, I understand the idea of the .h as you can then see the file as part of your sketch.

    Actually I wish there was a way that the options could be specified as part of the main .ino file. I believe I remembered some other IDEs in the past where you could have something like either special comments or #pragma like statements that could specify things like, which processor and maybe comm port... But my guess is that would be a lot more work...

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Kurt,

    .h : The builder does not copy other files to the buidl-directory. I tried an other extension, but this does not work.
    But seeing the file in the Ardio-IDE is not bad..

    Other IDEs: Yes.. Arduino is the only "IDE" I know, that does NOT store project settings. It would be so easy to add it. I have no idea why they don't add this feature.
    Last edited by Frank B; 08-27-2017 at 08:51 AM.

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Linux:
    I guess, the line should be something like
    Code:
    recipe.hooks.sketch.prebuild.1.pattern.linux= bash -c "[ -f \"{build.path}/sketch/defs.h\" ] || touch \"{build.path}/sketch/defs.h\""
    But it complains about a missing "]"
    I'm not that linux expert ...

  15. #15
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Ok, I found the problem. Linux works now. I have updated the platform.txt in post #1
    MAC: still a TODO.
    Last edited by Frank B; 10-23-2016 at 08:35 PM.

  16. #16
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,945
    Good work Frank - Everyone should use TYQT - it would have worked for me

    When you build a sketch there is a JSON file in that directory - shown on verbose output:
    "C:\Users\xyzz\AppData\Local\Temp\buildfcbd65d9e8d eac566b2daf204e8c1391.tmp\build.options.json"

    Not sure where this comes from >> That file in my case has this empty entry: >> "customBuildProperties": "",
    {
    "builtInLibrariesFolders": "I:\\arduino-1.6.11\\libraries",
    "customBuildProperties": "",
    "fqbn": "teensy:avr:teensy31:usb=serial,speed=96opt,keys=e n-us",
    "hardwareFolders": "I:\\arduino-1.6.11\\hardware,C:\\Users\\Tim\\AppData\\Local\\A rduino15\\packages",
    "otherLibrariesFolders": "C:\\tCode\\libraries",
    "runtime.ide.version": "10611",
    "sketchLocation": "C:\\tCode\\RTC_time\\RTC_millis\\RTC_millis.i no",
    "toolsFolders": "I:\\arduino-1.6.11\\tools-builder,I:\\arduino-1.6.11\\hardware\\tools\\avr,C:\\Users\\Tim\\AppDa ta\\Local\\Arduino15\\packages"
    }
    There is also this from preferences:: "C:\Users\xyzz\AppData\Local\Arduino15\preferences .txt"

    I didn't catch a hook there?

    But I do see it has a list of not just the '10 recent' sketches - but what looks like a pages long complete list of each sketch I touched. Would be nice if the IDE gave a way to display those.

  17. #17
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Hm, yes, I think i don't understand... how would that be useful, without editing Arduino or Teensyduino-source ?

  18. #18
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Tim, it works with TYQT, too. Just clik "integrate into Arduino" again, after overwriting the file "platform.txt"
    Last edited by Frank B; 10-23-2016 at 09:31 PM.

  19. #19
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,945
    Quote Originally Posted by Frank B View Post
    Hm, yes, I think i don't understand... how would that be useful, without editing Arduino or Teensyduino-source ?
    I just looked there and hoped maybe there was a way to use that I didn't know about - based on the name it seemed like it

    Quote Originally Posted by Frank B View Post
    Tim, it works with TYQT, too. Just clik "integrate into Arduino" again, after overwriting the file "platform.txt"
    Of course I'd do that - and posting without that is right - I was just wondering how many are using TYQT of the 6 downloads - and trying to add something useful to get on the notify list for thread updates.

  20. #20
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,945
    I just found something else that might make a good compile time editable #define value that is currently a constant - DELAY during init:

    in Pins_teensy.c - the 400 in delay(400)::
    Code:
    void _init_Teensyduino_internal_(void)
    {
        // ...
    	// for background about this startup delay, please see these conversations
    	// https://forum.pjrc.com/threads/36606...l=1#post113980
    	// https://forum.pjrc.com/threads/31290...ll=1#post87273
        // Last two lines show this wait to call setup()
    	delay(400);
    	usb_init();
    }
    On my Windows 10 machine (With Beta T_3.6 and a T_3.0) I just replaced this with 40 - and it works to get into setup() at 40 not 400.

    USB is online printing to the newest TYQT in under 500ms [409-434 on a few resets] instead of ~800ms.

    Also this delay() time seems to be ever present, not just when USB is in use.

    Tried again at delay(4) or REMOVED and USB is online even faster at 400ms [395-413 on a few resets].

  21. #21
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    If i remember correctly, this delay was introduced for I2C Chips, mainly.
    But, nevertheless, this sounds good.

  22. #22
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,945
    Indeed this thread is :: - Advanced users only -

    If you click the thread hyper links copied with the code they cover some of that. One issue at the time was T_3.2's not starting right - I didn't have a T_3.2 at this desk.

    THIS WORKS :: Just typing this - Wondering if just reworking those last lines and doing USB_init like this for the same net time delay before setup() - but USB online 300ms faster::

    Code:
    	delay(40);
    	usb_init();
    	delay(360);
    }
    Made a pull request to let Paul consider this. The net USB online time with that is again 405 ms!

    * :: this will need testing on other OS's against the Teensy family

    [Hey KurtE - I did my very only pull request - using online web github again]

    <edit> : temporary fail on github again - here is a PULL to Paul - not to myself :: https://github.com/PaulStoffregen/cores/pull/196
    Last edited by defragster; 11-07-2016 at 10:15 PM.

  23. #23
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Looks like it does not work anymore- because of Arduino 1.8.5 ?
    Any Ideas how to fi this ? I was away some time... Has anyone solved that yet?

  24. #24
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679

    fixed Arduino 1.8.5

    Ok. Fixed.

    Platform.txt for Arduino 1.8.5 as attached.
    Attached Files Attached Files

  25. #25
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,945
    Nice to see you back Frank.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •