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

Just posted this here Overriding-Core-defines with an updated platform.txt below that worked for two of us.

Confirmed '-Ucatfood' versus '-Dcatfood' in defs.h triggers this or not in the sketch:
Code:
void setup() {
  Serial.begin(9600);
  while ( !Serial && millis()<3000 );
#ifdef catfood
      Serial.println("Found catfood");
#endif
}
>> That is -U to Undefine or -D to Define the 'catfood'


Also looking at : ...\hardware\teensy\avr\cores\teensy4\HardwareSerial1.cpp::
Code:
#ifndef SERIAL1_TX_BUFFER_SIZE
#define SERIAL1_TX_BUFFER_SIZE     64 // number of outgoing bytes to buffer
#endif
#ifndef SERIAL1_RX_BUFFER_SIZE
#define SERIAL1_RX_BUFFER_SIZE     64 // number of incoming bytes to buffer
#endif
#define IRQ_PRIORITY  64  // 0 = highest priority, 255 = lowest
>> With code like this the -U to undefine isn't needed - other values that are defined need a -U before a new -D

And here is the file in use:

Frank B : hope you see this and it looks right
 
Just to clarify, I tested it on Mac. This is for version 1.8.9 of the IDE. Not yet tested on T4. Just starting to solder pins and SPI2 for underside of T4 board.
 
My tests involved using the following settings in defs.h:
Code:
-DSERIAL1_RX_BUFFER_SIZE=345
-DSERIAL1_TX_BUFFER_SIZE=123
-DF_CPU=144000000
The test code was simply:
Code:
void setup() {
  Serial.begin(115200);
  elapsedMillis waiting;
  while (!Serial && waiting < 1000) {} // Wait for output //
  Serial.print("*** init ***");
  
  #ifdef SERIAL1_RX_BUFFER_SIZE
    Serial.print("SERIAL1_RX_BUFFER_SIZE: " + String(SERIAL1_RX_BUFFER_SIZE));
  #endif
  #ifdef SERIAL1_TX_BUFFER_SIZE
    Serial.print("SERIAL1_TX_BUFFER_SIZE: " + String(SERIAL1_TX_BUFFER_SIZE));
  #endif
  #ifdef F_CPU
    Serial.print("F_CPU: " + String(F_CPU));
  #endif
}
Tested on Mac platform using T3.6 and T4. Both responded with the correct values output.

Next, I tried to verify a different project, not using the defs.h key-value file and got errors. It made me think that the bash script was not working, it's function being to create the file if not present. I checked the platform.txt file above and found the macosx line was commented out! Removing the # comment fixed it, and now projects can be build whether or not they have an associated defs.h file or not. Yay! See attached:View attachment platform.txt

I think this solution is amazing and I'm surprised it has so few takers. I can only think that folks don't realise how simple-to-use and powerful it really is.

Many thanks @Frank B for building a project-level override for system settings.
 
For the record, on the Mac, the platform.txt file is the one that lives at: Arduino.app/Contents/Java/hardware/teensy/avr/platform.txt
 
Back
Top