Questions tagged [avr-gcc]

avr-gcc is a suite of executable software development tools for Atmel AVR RISC processors

avr-gcc is a suite of executable software development tools for Atmel AVR RISC processors, hosted on the Windows platform, has GNU GCC compiler for C/C++.

Atmel provides also an AVR Toolchain, which is a collection of tools/libraries used to create applications for AVR microcontrollers. The collection includes compiler, assembler, linker and Standard C & other math libraries.

Most of these tools are based on efforts from GNU (www.gnu.org), and some are developed by Atmel.

614 questions
224
votes
20 answers

How can I unit test Arduino code?

I'd like to be able to unit test my Arduino code. Ideally, I would be able to run any tests without having to upload the code to the Arduino. What tools or libraries can help me with this? There is an Arduino emulator in development which could be…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
90
votes
4 answers

Writing a parser like Flex/Bison that is usable on 8-bit embedded systems

I'm writing a small interpreter for a simple BASIC like language as an exercise on an AVR microcontroller in C using the avr-gcc toolchain. If I were writing this to run on my Linux box, I could use flex/bison. Now that I restricted myself to an…
Johan
  • 3,072
  • 3
  • 27
  • 27
79
votes
9 answers

How to prevent GCC from optimizing out a busy wait loop?

I want to write a C code firmware for Atmel AVR microcontrollers. I will compile it using GCC. Also, I want to enable compiler optimizations (-Os or -O2), as I see no reason to not enable them, and they will probably generate a better assembly way…
Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
66
votes
2 answers

What is the purpose of __cxa_pure_virtual?

Whilst compiling with avr-gcc I have encountered linker errors such as the following: undefined reference to `__cxa_pure_virtual' I've found this document which states: The __cxa_pure_virtual function is an error handler that is invoked when a…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
43
votes
1 answer

crt0.o and crt1.o -- What's the difference?

Recently I've been trying to debug some low-level work and I could not find the crt0.S for the compiler (avr-gcc) but I did find a crt1.S (and the same with the corresponding .o files). What is the difference between these two files? Is crt1…
Earlz
  • 62,085
  • 98
  • 303
  • 499
26
votes
6 answers

8 bit enum, in C

I have to store instructions, commands that I will be receiving via serial. The commands will be 8 bits long. I need to preserve transparency between command name, and its value. So as to avoid having to translate an 8-bit number received in serial…
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
25
votes
4 answers

Undefined reference to 'operator delete(void*)'

I'm new to C++ programming, but have been working in C and Java for a long time. I'm trying to do an interface-like hierarchy in some serial protocol I'm working on, and keep getting the error: Undefined reference to 'operator delete(void*)' The…
Bracket
  • 432
  • 1
  • 4
  • 9
24
votes
8 answers

How can I visualise the memory (SRAM) usage of an AVR program?

I have encountered a problem in a C program running on an AVR microcontroller (ATMega328P). I believe it is due to a stack/heap collision but I'd like to be able to confirm this. Is there any way I can visualise SRAM usage by the stack and the…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
12
votes
3 answers

How to implement a compile-time [dispatch] table for AVR?

I have the same prerequisites as Dave Durbin in How can I implement a dynamic dispatch table in C... except my target is AVR. Here are my constraints: modules are to be picked in a list, much like Linux compiled-in kernel modules the number of C…
user4113344
11
votes
9 answers

How can I perform pre-main initialization in C/C++ with avr-gcc?

In order to ensure that some initialization code runs before main (using Arduino/avr-gcc) I have code such as the following: class Init { public: Init() { initialize(); } }; Init init; Ideally I'd like to be able to simply…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
11
votes
3 answers

AVR Studio 5: compile C++ code

When creating a project in AVR Studio 5, it creates a .c file with following content: #include int main(void) { while(1) { //TODO:: Please write your application code } } Building this C program works just…
Mot
  • 28,248
  • 23
  • 84
  • 121
9
votes
1 answer

GCC fails to report an ill-formed constexpr lambda call

Below are two test-cases for Undefined Behaviour, expressed as IIFE (Immediately Called Lambda-Axpression): constexpr auto test3 = []{ int* p{}; { int x{}; p = &x; } return *p; // Undefined Behaviour }(); //…
wimalopaan
  • 4,838
  • 1
  • 21
  • 39
9
votes
4 answers

How to make two otherwise identical pointer types incompatible

On certain architectures it may be necessary to have different pointer types for otherwise identical objects. Particularly for a Harvard architecture CPU, you may need something like: uint8_t const ram* data1; uint8_t const rom* data2; Particularly…
Jubatian
  • 2,171
  • 16
  • 22
9
votes
1 answer

-gc-sections discards used data

Using avr-gcc, avr-ld I'm attempting to severely reduce the size of the output file by using fdata-sections -ffunction-sections and gc-sections. When compiled without these options I have an output of ~63KB, and with these options its ~30KB, so it…
Brandon Schaefer
  • 451
  • 1
  • 4
  • 12
9
votes
2 answers

Using 'typedef' to ensure logical type safety

typedef int A; typedef int B; void foo(A arg){} void main(void){ B wrongvar = 7; foo(wrongvar); } Is this construction supposed to return a warning/error, according to the standard? What about the most popular compilers? Example: we have…
Vorac
  • 8,726
  • 11
  • 58
  • 101
1
2 3
40 41