Noob trying to get started with ATmega32 and C++

Hi
I am an electronics engineer that does software. I am new to PlatformIO, but not new to MCUs.

I have a custom board design that will run an ATmega32U4 and code someone else has written in C++ from here: https://github.com/xyphro/UsbGpib. I have forked the hardware and I want to modify the software also.

The path of least resistance is to just use a Ubuntu CLI tool chain (gcc, avrdude). They aren’t much different to what I was using 40 years ago, old school style.
The Linux command line looks like this:

avrdude -c usbasp -p m32u4 -e -Ulock:w:0x3F:m -Uefuse:w:0xcb:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m
avrdude -c usbasp -p m32u4 -U flash:w:BootLoader.hex -B 10

I have been trying to jump into this century and make a start with PlatformIO in Windows 10 but I having some beginner issues with setting up the ini file. At present the ini file only includes:

[env:ATMEGA32u4_16m]

platform = atmelavr

board = ATmega32

board_build.f_cpu = 16000000L ;16MHz clock

My problems include:

All of the examples I have found are Arduino based, even the avr examples, so I haven’t found a pure C++ example to follow.

I am using a USBasp programmer but this is being reported as a libusb-win32 device and not as a serial port (it is not connected to a target board).

I need to program the ATmega fuses. Is that something I can setup/do from within PlatformIO or not?

Can someone please point me to a similar project that I can use as a template to follow?

You can still have a baremetal project (which is platformio.ini without a framework = .. setting, exactly as your current one) and just put .cpp in the src/ folder. They will be compiled using avr-g++. Nothing too different.

And no, AVR libC only examples are available. The program should compile the same when you rename main.cmain.cpp, making that a C++ project.

Configuration of USBasp as your programmer is per documentation.

Fuse programming is per documentation.

OK thanks.
May I suggest that “native blink” is renamed to something like “C blink”, “bare metal C blink” or “native C blink” to make it easier to recognise what it is.

I was looking in the Getting Started and Configuration sections so I never got to the Instrumentation section where all your links point.

What you have provided should be enough to get me started.

Hi
I am using the ATmega32U4-AU MCU.
The nearest definition is at this link: https://github.com/platformio/platform-atmelavr/blob/master/boards/ATmega32.json

This definition includes:

“frameworks”: [
“arduino”
],

whereas I want bare metal C++
and no flags for fuses.

So it appears that a custom board definition would be appropriate and I think I could write one for a generic custom ATmega32U4 board. If I wrote a custom definition, it would only exist on my pc. I would prefer to add this back into the repository for others, like me, to use but the process for raising a “new board” issue : Adding a Custom Board
doesn’t seem to be working.

Also the ATmega board definitions include variants of the line:
“extra_flags”: “-DARDUINO_AVR_ATmega32”,

A search of “platformio” and “extra_flags” does not yield any results.
The values of these extra flags includes:
“-DARDUINO_AVR_ATmega…” which again includes the ARDUINO word that I don’t want for a bare metal system.

What this means is that I don’t know why the extra-flags value is there, and the consequences of removing it for a custom generic board that does not use Arduino.

Doesn’t matter because again “bare metal C++” is a project without a framework = .. line, and no framework is always valid. This just lists all the available framework = .. values, where as no framework settings is always also available, which is baremetal.

Doesn’t matter because it can be configured through the platformio.ini as per documentation above.

Doesn’t matter because in your baremetal project, there will be no code to listen to this definition of the macro. You control the entire source code.

If you have a ATmega32, your already posted platformio.ini will work just fine as a base, just add in fuse and upload settings per docs above, no custom board definition needed.