Does it let us select a c compiler for AVR?

Is there a Big Picture Top Down explanation of how PIO is supposed to work? My mental model so far is: I want to write an avr c program. I know that the arduino ide uses the gcc compiler, but I dont want to use digitalwrite and setup and loop. I really liked the imagecraft ide where you make a new project, add files to the project and hit compile. Used it for a decade. Seems like I should be able to pick an avr cpu, add a uart, an oled, an sd card, and compile it up. Then I might do the same thing with a blue pill, just pick an stm32 instead of an avr, use the same c files, and out comes binary for a blue pill. Then do the same thing for an nxp/freescale cpu. Or an esp8266. Obviously it has to compile c using the compiler for that cpu, but I dont see how to select it. Anyone think this is the intended application?
Thanks for reading this.

When you create a project in the VSCode editor (or Atom), or using the command line, you must pick a board. Uno, Bluepill etc.

That causes the appropriate framework and toolchain to be downloaded and used as soon as PlatformIO needs to. Usually when you first compile.

So, the board in use picks the compiler tools.

Also, you can import or write Arduino style code in your projects, but equally, you can drop the Arduino stuff and write plain AVR, for example, C/C++ as well. Just delete the framework = arduino line from the platformio.ini file in the project directory. (For AVR boards!)



But using the GCC compiler does not coincide with having to use the Arduino-framework APIs like digitalWrite(), it’s just the compiler. You also can’t choose any other than a AVR-GCC compiler, but you’re free to use different versions (here, here), but the default should be absolutely fine. PlatformIO uses mostly the GCC compilers for ARM, AVR, etc. Only for select legacy stuff like Intel 8051 it’s using sdcc and related stuff.

As @normandunbar says

An example project and code is available at platform-atmelavr/examples/native-blink at develop · platformio/platform-atmelavr · GitHub.

Well, that won’t work unless the C code (or C++ code) is targeted at a general framework which abstracts away your target chip. If your C code is directly writing into an AVR’s UART registers and you’re trying to compile that for an ARM-Cortex M3 based STM32F103C8 (bluepill) chip it will of course fail. Unless you’re using a framework like Arduino in which you just call Serial.println() and under the hood differen Arduino-Core implementations to the right thing for your board.