Skip to main content
17 votes
Accepted

_delay_ms() is much slower than expected (by a factor of 6) on TinyAVR 0/1 (ATTiny1604)

Your toolchain is not broken. In the ATTiny804/1604 datasheet, page 77, it shows the CPU clock is divided from the 20/16 MHz oscillator by a prescaler (the ATTiny1614 datasheet shows the same clock ...
比尔盖子's user avatar
5 votes
Accepted

MEGA 2560: Simple program - One analogWrite turns off the other

As you are using using ArduinoIDE >=1.8.10 its an "optimization" problem by the compiler for the Mega try to replace the line void setup() with void setup() __attribute__((optimize("-O0"))); ...
Codebreaker007's user avatar
5 votes
Accepted

Porting code from Arduino IDE to other IDEs - expected code size reduction

You don't need to abandon the Arduino IDE. Let me quote from my forum post about sketch sizes. Introduction Every now and again this subject pops up on the Arduino forum. Why does it take 1000 ...
Nick Gammon's user avatar
  • 38.7k
5 votes

Equivalent to POSIX mmap() in AVR-libc

No. First, mmap() makes almost no sense on an AVR, as there's no memory management unit or concept of process memory to configure. Some related concepts like sbrk() are occasionally implemented in a ...
Chris Stratton's user avatar
3 votes
Accepted

Interleave disassembly + source with avr-objdump

The .stabs section contains debugging info, not actual code. There is no point in trying to “disassemble” it. The -D option of avr-objdump means “disassemble everything, whether or not you believe it'...
Edgar Bonet's user avatar
  • 44.3k
3 votes
Accepted

AVR-GCC can't call function located on fixed address

I've tried this code with arduino and it worked (i taught, of course, i can't add the "-Wl,--section-start=.app_start=0xFA0" flag to the compilation process so the function not gonna be moved to other ...
Dankó Dávid's user avatar
2 votes
Accepted

programming arduino in pure c

In file included from led.c:3:0: /usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from won't work as designed" You should start by fixing this....
Edgar Bonet's user avatar
  • 44.3k
2 votes

Can I port a project built on Arduino Uno to a standalone ATmega328 using the exact same code?

Almost all of my projects are roll-your-own-duinos with Atmega 328p chips, with code generated for an "Arduino/Genuino Uno" board. Many of them use an ESP8266-01 board as a WiFi interface. I either ...
JRobert's user avatar
  • 15.3k
2 votes
Accepted

avr-gcc -D is ignored

You are using $(CPPFLAGS) for *.cpp files but only $(CXXFLAGS) are defined. This should be obvious from command line (if you enable showing executed commands for make) And also: CC = using $(CPP) ...
KIIV's user avatar
  • 4,777
2 votes

How would I include Arduino libraries using AVR-gcc without the IDE?

Since you will end up using a significant portion of the Arduino core library, the easiest path is to accept the idea that you are now writing “Arduino sketches” rather than plain C++ code. Don't ...
Edgar Bonet's user avatar
  • 44.3k
2 votes

Porting code from Arduino IDE to other IDEs - expected code size reduction

If you like the Arduino IDE, you also can do the following: Do not use the library functions, but use registers directly. The compiler is smart enough that it does not link functions you do not use ...
Michel Keijzers's user avatar
2 votes

Multiple defintion error, Linker error

You forgot the -c flag to your first command. That means you have first compiled your program into a full elf file. Then you try to link that elf file with the standard startup libraries again (it ...
Majenko's user avatar
  • 106k
2 votes
Accepted

ISR definition causing boot loop?

Your problem is not with your code. It's with how you're linking your elf file. You haven't specified the chip to link for. $ avr-gcc -mmcu=atmega328p boot_loop.o -o boot_loop.elf
Majenko's user avatar
  • 106k
2 votes
Accepted

What else is consuming Data Segment reported by avr-size?

Most of the missing data section is probably made of string literals. When you write something like Serial.println("Hello, World!"); the string "Hello, World!" is implemented by ...
Edgar Bonet's user avatar
  • 44.3k
2 votes
Accepted

What's Memory Allocation technique in Arduino

Use the source, Luke! The AVR-based Arduinos rely on the avr-libc library, which provides malloc() and friends. You can read the source code online. It is generously commented, and you can understand ...
Edgar Bonet's user avatar
  • 44.3k
2 votes
Accepted

How do I build and upload a C++ program without the Arduino Library or IDE?

Create a new file called Makefile in your project directory. Populate it with the following contents: TEMPDIR := $(shell mktemp -d) all: avr-g++ -DF_CPU=<CLK> -mmcu=<PARTNO> -fno-...
glibg10b's user avatar
  • 317
2 votes
Accepted

AVRdude does not read the FUSE byte values correctly

A couple of things. That you can't change fuses from the bootloader and that optiboot can't report fuse values correctly, even if you change them. No self-programming of fuses A bootloader can't ...
timemage's user avatar
  • 5,414
2 votes

What happens when you call malloc()/free()/new/delete?

There are some hardware-specific abstractions (they mostly define the maximum memory available), but otherwise these are functions are implemented by the C/C++ runtime (on arduinos an implementation ...
PMF's user avatar
  • 1,306
1 vote

What's Memory Allocation technique in Arduino

Long answer short, it used both first-fit and best-fit. The malloc function in the avr-libc makes use of a so-called free list to track the free spaces in the memory. When there is a memory request, ...
Mostafa Wael's user avatar
1 vote
Accepted

Why is Toolchain Not Updated with Arduino IDE Install on Mac

The boards packages maintained by Boards Manager and associated tools are installed in .arduino15 folder. The AVR boards package bundled with IDE is only used when there is no AVR boards package ...
Juraj's user avatar
  • 18.2k
1 vote
Accepted

My software serial code won't work at > 4800bps

At 1MHz and 9600 baud, you have a total of 104 clock cycles available to run your interrupt routine in. A quick count up of the assembly instructions generated comes to more than that (around 126 at ...
Majenko's user avatar
  • 106k
1 vote
Accepted

avr_g++ compiler error: expected primary-expression before '.' token (C code in .ino)

.ino is compiled as C++. your test is C code. put the C code in a .c file and the declaration in .h file and include the .h in .ino I created a test.c, copied the content of your main.c into it and ...
Juraj's user avatar
  • 18.2k
1 vote

avr/io.h No such file or directory error when compiling using avr-gcc

I’m guessing you started with the toolchain Arduino put on your machine. Try explicitly including the header files on the include path with the -I switch. avr-gcc -mmcu=atmega328p -I /path/to/avr/...
RubberDuck's user avatar
1 vote

Porting code from Arduino IDE to other IDEs - expected code size reduction

I have managed some 33% downsizing, hurrah! Adding to the current answers: the biggest reduction came by ridding the floating points. I have come across the answer here and put avr-objdump to good ...
kellogs's user avatar
  • 137
1 vote
Accepted

Compiling source with Arduino.h with avr-g++

You need to do a whole lot more than just run the one command. You need to compile each individual source file for the libraries you want (using -c to just compile and not link), then (ideally) ...
Majenko's user avatar
  • 106k

Only top scored, non community-wiki answers of a minimum length are eligible