AVRdude firmware size unchanged

I noticed that as I was flashing to an attiny85 over usbtinyisp that the behavior wasn’t changing. So I disconnected my circuit and flashed, plugged it back in and nothing changed. I noticed that my forward hadn’t changed in a while so I defined some oddball ints and hit build. Firmware size didn’t change. Not even a byte.

I went through and deleted the firmware elf files and such to make sure it was creating a new file at least, but the firmware size stayed the same. I must be missing something. It’s like its stuck building an older version of my code. Is there a cached copy somewhere that I’m missing? I’m new to using Platform so it’s entirely possible.

First of all, are you sure you’ve selected the right active project through the project environment switcher?

Yes. It matches what it is in my programio.ini. It remains stuck if I do a clean and rebuild. Even if I create dummy methods, the size remains the same. I know that it is writing to the chip because I get the flashing lights and all from the programmer, but the size should change right?

But if you don’t call them, the optimizer passes of the compiler will sweep them out again. Same with global variables that you define but not use. The default optimization level given to gcc in PlatformIO is -Os (optimize-for-size) after all.

Do you have a reproducable minimal example (code + changes + platformio.ini) of this?

GitHub - TunaLobster/ServoTester: Simple homemade servo tester just for fun and learning is the repo

The trouble is that the chip is doing an old PWM sweep program I was using to test out some libraries. It’s not writing the analogRead() code that I have in there right now.

Yeah these lines

will get completely optimized away since they’re not used in the execution flow of the program (in setup() and loop(). And even if, the compiler would optimize the variable and the entire function away and directly replace with the constant 6 if the return value of the function is needed, which will hardly increase the binary size.

Your variable last_servo_out is weird though. It has no explicit beginning value (so it will be implictly 0), and you check for its value but you never write a new value to it.

But then my code should be doing something other than sweeping the servo, but yet it’s stuck flashing that firmware. The way the code is right now, it would run every loop. That would create a different behavior than sweeping from 800 to 2200 mircos.

I created a few new counters and added them together, that shouldn’t be cleaned up by the optimizer. The thing is that the firmware sized is unchanged. Not even a difference of 1 byte. RAM (40 bytes) or flash (1430 bytes).

Pushed some changes and still getting the same firmware size.

Can you show a screenshot of your VSCode window with the file explorer sidebar opened?

Thank you for sticking with me on this. Trying to jumping to something newer than starting with blank build scripts for each project.

Looks good, it’s also the only project in the workspace.

You’d be suprised by how good the optimizer is. Did you Serial.println() the value to make sure it has outside influence?

You can also just play with optimization level. If you write

debug_unfags = -Os
debug_flags = -O0

you disable optimize-for-size and enable optimize-nothing. (docs). With that, every variable or line of code that you write should have a direct impact on used flash-space.

Not recommended for an actual release build, of course.

In any case, I’d advise that after you

you write myservo.write(val); you do

last_servo_out = now;

to actually implement that // only send to servo when it is time thing.

Yep! Missed that while throwing code in while trying simplify the issue.

I set build_flags to -Os and -O0 in the ini file and still got the same sizes for RAM and flash. Added an analogWrite() for my blah variable to an unused pin and got the same sizes again. Wipe everything and reinstall Windows?

Ah, I see the cause now.

In lib/Servo8Bit/ there is the file example.cpp that defines the main function. You’ve accidentally copied the example file and it overshadows the entire code that you have placed in src/main.cpp, since example.cpp overwrites the main() entry point by itself and doesn’t continue to call into setup() or loop() or anything – remove the file https://github.com/TunaLobster/ServoTester/blob/master/lib/Servo8Bit/example.cpp and things will make start to make sense again.

Note: PlatformIO automatically ignores the “examples” folder of a library, but in the case of a example.cpp file being placed directly next to the library’s source code, it will build it.

facedesk Huh. Should I add a note to the docs for that?

In which docs? The behavior for the examples folder exclusion is already at the official docs.

Looking at the library repository, other people have fallen into this trap as well