avr-gcc

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. Are there any tools or libraries out there which can help me with this? Update: There is an Arduino emulator in development which could be useful but it doesn't yet seem to be ready for use. Updat...

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 pure virtual function is called. If you are writing a C++ application that has pure...

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 write: initialize(); but this doesn't compile... Is there a less verbose way to achieve the same effect?...

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 heap? Note: the program is compiled with avr-gcc and uses avr-libc. Update: The actual prob...

How can I prevent the need to copy strings passed to a avr-gcc C++ constructor?

In the ArduinoUnit unit testing library I have provided a mechanism for giving a TestSuite a name. A user of the library can write the following: TestSuite suite("my test suite"); // ... suite.run(); // Suite name is used here This is the expected usage - the name of the TestSuite is a string literal. However to prevent hard-to-find b...

Can I implement the Factory Method pattern in C++ without using new?

I'm working in an embedded environment (Arduino/AVR ATMega328) and want to implement the Factory Method pattern in C++. However, the compiler I'm using (avr-gcc) doesn't support the new keyword. Is there a way of implementing this pattern without using new? ...

avr-gcc: suppress warning "'__progmem__' attribute ignored"

Hi there, does anybody know how this warning can be suppressed? there is no way for me to avoid them (they stem from a framework i use). Thanks! ...

Formatting characters on serial output!!!

Hi Guys, I'm interfacing an SD card to ATmega128 using EFSL. Card gets initialised, but I get an error saying "Unknown error 0xff(see sandisk docs p5-13)"... on serial port output. That's not all, I hv used 'sprintf' to form strings which I display on serial port. The puzzling thing is, I'm also getting the actual formatting characters...

How to get GNU AS to emit per-line debugging info or GDB to single step lines in (AVR) Assembly?

I cannot figure out how to get GAS to emit line number debugging information for gdb in assembly. Note that I'm using the avr-gcc cross compiler, but doubt that is relevant. I'm using the following command line options to assemble: avr-gcc -g -ggdb -Os -mmcu=atmega644 -ffunction-sections -fsigned-char -Winvalid-pch -Wall -Wno-long-lo...

Why is this code being generated by avr-gcc and how does it work?

This is a snippet of disassembled avr code from a C project I'm working on. I noticed this curious code being generated and I can't understand how it works. I'm assuming it's some sort of ridiculous optimization... Can anyone explain? 92: ticks++; +0000009F: 91900104 LDS R25,0x0104 Load direct from data space +0...

8 bit enum, in C

I have to store instuctions, commands that I will be receiving via serial. The commands will be 8 bits long. I'd like to use Enumerations to deal with them in my code. Only a enumeration corresponds to a ... on this platform I think a 16 bit integer. I need to preserve transparancy between command name, and its value. So as to avoid ha...

Function pointer location not getting passed

I've got some C code I'm targeting for an AVR. The code is being compiled with avr-gcc, basically the gnu compiler with the right backend. What I'm trying to do is create a callback mechanism in one of my event/interrupt driven libraries, but I seem to be having some trouble keeping the value of the function pointer. To start, I have ...

Using array of chars as an array of long ints

On my AVR I have an array of chars that hold color intensity information in the form of {R,G,B,x,R,G,B,x,...} (x being an unused byte). Is there any simple way to write a long int (32-bits) to char myArray[4*LIGHTS] so I can write a 0x00BBGGRR number easily? My typecasting is rough, and I'm not sure how to write it. I'm guessing jus...

Is there an alternative for flex/bison that is usable on 8-bit embedded systems?

Hi, 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. However, I'm wondering if there are any open source tools out there that could help me writing the lexer and parser. If I would write this to run on my Linux box, I could use flex/bison. Now th...

Unit tests for interrupt-heavy code

I am writing C code for an AVR chip. The code is heavy on interrupt serivce routines which wait on serial ports, ADCs and timers. The ISRs write to buffers which the main loop examines when it gets to them. I design the buffers so that ISRs can update them while the main loop is reading them. I want to verify that this works. I have uni...

Symbol not found - CUnit on Snow Leopard

Hi, I just installed CUnit on Snow Leopard with MacPorts/DarwinPorts. The installation went fine, however, I get en error when trying to run the unit tests: dyld: Symbol not found: _acs_map Referenced from: /opt/local/lib/libcunit.1.dylib Expected in: flat namespace in /opt/local/lib/libcunit.1.dylib Trace/BPT trap Has anyone co...

AVR Analog Comparator + Internal Pullup?

I have what I hope is a simple question pertaining to the Atmel AVR microcontrollers. So I want to use the ATTiny85's Analog Comparator to determine if a signal is above or below a threshold. This signal is normally "floating" and pulled toward ground when "active" (i.e. it's an active low - open collector signal). If I enable the pullup...

AVR sbi command - Error: number must be positive and less than 32

I've spent a good while getting my AVR development system set up with the full GCC tool chain (everything is the most recent current stable version) and I have solved most issues with it but one. This following code gives me an error which I just don't get. The AVR assembly manual states that the sbi instruction can accept 0-7 as a cons...

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

Hello, 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 something completely different or what? They both seem to have to do with something for boo...

AVR_GCC compile errors delay.h

Instructions in the blinky.zip, gcc-section, Teensy++ v.2. Makefile and blinky.c are in the zip. I modified the blinky.c by defining F_CPU at the start because not using Makefile, please, see below. So why do I get the errs and how can I compile the C-files for at90usb1286 chip? $ avr-gcc -mmcu=atmega88 blinky.c In file included from b...