pw_arduino_build#

Pigweed AI summary: The pw_arduino_build module includes the arduino_builder command line utility and an Arduino Main Wrapper. The Arduino Main Wrapper renames main() to ArduinoMain() to allow Pigweed executables to define main() without conflicting with the Arduino core's main(). The arduino_builder utility extracts compile and tooling information from an Arduino core and can be used with other build systems. The Arduino target documentation lists supported hardware.

The pw_arduino_build module contains both the arduino_builder command line utility and an Arduino Main Wrapper.

See also

See the Arduino target documentation for a list of supported hardware.

Arduino Main Wrapper#

Pigweed AI summary: The Arduino Main Wrapper implements the standard setup() and loop() functions that are expected in Arduino sketches. However, Pigweed executables rely on being able to define the main() function, which is a problem for Arduino code as each core defines its own main(). To get around this, the Pigweed Arduino target renames main() to ArduinoMain() using a preprocessor macro. Most Arduino cores will do some internal initialization before calling setup() followed by loop(). To make sure Pigweed main() is

arduino_main_wrapper.cc implements the standard setup() and loop() functions [1] that are expected in Arduino sketches.

Pigweed executables rely on being able to define the main() function. This is a problem for Arduino code as each core defines it’s own main(). To get around this the Pigweed Arduino target renames main() to ArduinoMain() using a preprocessor macro: -Dmain(...)=ArduinoMain(). This macro only applies when compiling Arduino core source files. That frees up main() to be used elsewhere.

Most Arduino cores will do some internal initialization before calling setup() followed by loop(). To make sure Pigweed main() is started after that early init we run it within setup():

void setup() {
  pw_arduino_Init();
  // Start Pigweed main()
  main();
}

void loop() {}

Note

pw_arduino_Init() initializes the pw_sys_io_arduino module.

Warning

You may notice loop() is empty in arduino_main_wrapper.cc and never called. This will cause any code appearing after loop() in an Arduino core to never be executed. For most cores this should be ok but may cause issues in some scenarios.

arduino_builder#

Pigweed AI summary: The arduino_builder is a utility that can extract compile and tooling information from an Arduino core. It is used within Pigweed to shovel compiler flags into the GN build system and can also be used with other build systems. Full documentation is not yet available, but running "arduino_builder --help" will provide details. The Arduino Reference documentation on setup() and loop() can be consulted for more information.

arduino_builder is utility that can extract compile and tooling information from an Arduino core. It’s used within Pigweed to shovel compiler flags into the GN build system. It will also work without Pigweed and can be used with other build systems.

Full documentation is pending. For now run arduino_builder --help for details.

Footnotes