64 questions
93
votes
4
answers
88k
views
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 ...
81
votes
10
answers
80k
views
How can I 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 ...
68
votes
3
answers
58k
views
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 ...
230
votes
21
answers
85k
views
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 ...
27
votes
8
answers
34k
views
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 ...
9
votes
7
answers
5k
views
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 ...
8
votes
8
answers
16k
views
AVR linker error, "relocation truncated to fit"
I'm trying to compile some code for an ATmega328 micro, and I want use the libraries and the core of Arduino. I'm using CMake. I have gotten to compile the core library and all objects of my code and ...
3
votes
2
answers
2k
views
Avr asm label*2
Hi i am new in avr asm programming,in the example below, i have few questions:
1) Is it label: 8 bit or 16bit long?
2) Why multiplication label with 2 is needed?
3) Instruction LPM is placing ...
3
votes
6
answers
40k
views
Convert two ASCII Hexadecimal Characters (Two ASCII bytes) in one byte
I want to convert two ASCII bytes to one hexadecimal byte.
eg.
0x30 0x43 => 0x0C , 0x34 0x46 => 0x4F ...
The ASCII bytes are a number between 0 and 9 or a letter between A and F (upper case ...
3
votes
2
answers
4k
views
Android cannot talk to Arduino using AVRDUDE
I am using AVRDUDE for Android (http://code.google.com/p/andavr/). I can compile the C code. I can run
$ avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o led.o led.c
$ avr-gcc -mmcu=atmega328p ...
1
vote
1
answer
1k
views
Linking binary against functions/data in specific location in memory
I'm currently in the process of writing an intermediate-memory bootloader for an ATMega.
I'd like to place a section of commonly used functions and data in a specific location in memory, such that:
...
13
votes
9
answers
12k
views
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'...
12
votes
1
answer
18k
views
-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 ...
8
votes
1
answer
7k
views
Macro defined in main.c not visible in another included file
I have multiple C and H files
In main.c I defined a macro, and in ws_driver.c I want to use it.
ws_driver.h is included in main.c.
main.c
#define WS_PORT PORT_D8
#define WS_BIT D8
#define WS_DDR ...
8
votes
3
answers
9k
views
Problems with printf() on AVR in C with floating-point
I've been getting back into C, and I've been working on an 'academic' exercise to sharpen some old skills again. My project revolves around the rather simple process of generating sines. I started out ...
7
votes
2
answers
2k
views
snprintf not working as expected with avr-gcc
During a debugging session, I found out that snprintf is not working as expected when compiling the code with avr-gcc. The example code should simply convert the floating point value 3999.9f into its ...
3
votes
1
answer
10k
views
How to write a custom reset() function in C for AVR-Studio?
so I've been assigned the task of writing a custom reset() function for an AVR compilation.
I'm given this info - "Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a ...
2
votes
3
answers
10k
views
Atmel / Arduino: ISR(TIMER0_OVF_vect) won't compile ("first defined" in __vector_16)
I'm currently working on a PWM modulator to "simulate" a car engine ignition commutation. Then, I will use it to drive another microcontroller which handles the conversion from a raw signal (engine's ...
2
votes
1
answer
2k
views
GCC linking / symbol name mangling with C++ and assembler files
I'm having some trouble compiling and linking a library that's written in assembler with my program code which is in C++. In my case it's for an AVR microcontroller using the avr-gcc suite, but I ...
1
vote
1
answer
3k
views
How to link against just symbols correctly
I guess this is a continuation of this question.
I've compiled my intermediate bootloader library and have verified it working, now it's time to write some application code against it.
I'm able to ...
45
votes
1
answer
22k
views
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 ...
25
votes
4
answers
85k
views
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:
...
9
votes
4
answers
604
views
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 ...
9
votes
2
answers
7k
views
Avr-GCC with Arduino
How can I program my Arduino in C on Ubuntu. I've heard of avr-gcc but all online tutorials seem extremely tedious and don't have options for an AVR chip with the Arduino bootloader. Can anyone help ...
6
votes
2
answers
1k
views
Extern variable only in header unexpectedly working, why?
I'm currently updating a C++ library for Arduino (Specifically 8-bit AVR processors compiled using avr-gcc).
Typically the authors of the default Arduino libraries like to include an extern variable ...
5
votes
4
answers
41k
views
cast unsigned char * (uint8_t *) to const char *
I've a function which take an uint8_t * argument :
uint8_t* ihex_decode(uint8_t *in, size_t len, uint8_t *out)
{
uint8_t i, hn, ln;
for (i = 0; i < len; i+=2) {
hn = in[i] > '9'...
5
votes
2
answers
12k
views
Arduino (Uno) Ethernet client connection fails after many client prints
I'm using an Arduino Uno with Ethernet Shield.
After sending many HTTP requests, client.println(...), the client starts to fail when connecting. The time to failure appears to be random, and the ...
4
votes
1
answer
3k
views
Does gnu ld link in whole object files or only the needed functions?
We have a library and an executable, that is to be statically linked to the lib. We want to minimize the program space of the final executable.
According to avr-libc's documentation:
the linker ...
4
votes
3
answers
3k
views
Does AVR-GCC properly work with 16-bit AVR I/O registers?
Preamble
It's known that for atomic and simultaneous reading/writing high and low part of 16-bit I/O registers (timer-counters, ICR/OCR, ADC...) AVR uses a shadow temporary register. E.g. reading ...
3
votes
1
answer
4k
views
AVR-GCC: Error: garbage at end of line
I have problem with stack init lines because avr-gcc returns
LED_Blink.asm:10: Error: garbage at end of line
On lines:
ldi r17, low(RAMEND)
ldi r17, high(RAMEND)
And I am confused. I have already ...
3
votes
1
answer
96
views
Problem with avr-g++ 13.3.0 passing const char array as parameter in ATmega4809 (40 pins)
The following code doesn't work in ATmega4809:
#include <avr/io.h>
#include <util/delay.h>
void f(const char str[])
{
if (str[0] == 'a'){ // <-- here is the problem!!! The program ...
2
votes
1
answer
357
views
ATmega328P USART Transmit character printed repeatedly
I am encountering an issue with USART communication on an ATmega328P microcontroller and would appreciate some assistance with debugging.
The problem I'm facing is as follows:
I have implemented USART ...
2
votes
1
answer
2k
views
undefined references to functions in linked avrfix library using avr-gcc compiler/linker
I am trying to use the avrfix library in a project, using Eclipse (v4.2.2) as the IDE and avr-gcc as the compiler. Both the header file (avrfix.h) and the library file (libavrfix.a) are included in ...
2
votes
3
answers
12k
views
Undefined reference to in AVR-GCC
My main.c is as below
#include <avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#include <string.h>
#include "main.h"
#include "globle.h"
#include "LCD.h"
int ...
2
votes
3
answers
8k
views
Changing a global variable in C
I am running a C program on an AVR chip. Whenever a serial signal is heard, it runs the serial interrupt ISR (USART_RX_vect). In this method it should turn on change to = 1;. Then in my main while ...
2
votes
1
answer
617
views
Can GNU ld be instructed to print which .o files are needed during a link?
A little background: I'm trying to build an AVR binary for an embedded sensor system, and I'm running close to my size limit. I use a few external libraries to help me, but they are rather large when ...
2
votes
3
answers
2k
views
Call const function address passed to gcc inline assembler (avr-gcc)
I'm writing an RPC library for AVR and need to pass a function address to some inline assembler code and call the function from within the assembler code. However the assembler complains when I try to ...
2
votes
6
answers
935
views
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(); ...
2
votes
4
answers
8k
views
avr-gcc: variable must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
I am trying to reproduce this 4-key-keyboard and for that I am trying to compile its source by compiling it with avr-gcc on my Linux box.
I managed to solve a couple errors thrown by the compiler by ...
1
vote
1
answer
635
views
avr-gcc 8.1.0 uses `as` instead of `avr-as`
I want to use the newest version of avr-gcc (8.1.0) for a new project, which is not available from ubuntu's package-manager. So I compiled it myself using the build-script from this site: https://gist....
1
vote
1
answer
1k
views
ATTiny85 - Software UART with Timer1
So recently I tried to implement Software UART (TX only) for the ATTiny85. I want to drive it with the internal Timer1.
The timer shall interrupt with the frequency of the Baudrate. Every ISR one bit ...
1
vote
2
answers
887
views
How to find the address of a variable when using AVR?
I am trying to write a program that detects pixel level collision of bitmaps on a Teensy micro controller compiling with AVR-GCC. I am trying to work out how to calculate the position of a single byte ...
1
vote
2
answers
365
views
How can i add a architecture which is available in new version of gcc to a old version of gcc?
I want to add Atmega1281 architecture to my current version of gcc that i am using i.e. v3.3.
The Atmega1281 is not supported in the v3.3 and its support got added in v4.2.1 .
I cannot upgrade the ...
1
vote
1
answer
4k
views
memcpy_P function AVR?
void * memcpy_P( void * dest, PGM_VOID_P src, size_t n )
Could someone please tell me where the above function is implemented in the avr libc library?
I can only seem to find a definition for the ...
1
vote
2
answers
275
views
C Preprocessor output int at Build
i want to see output of Preprocessor calculating. Only with strings it works so:
#define XSTR(x) STR(x)
#define STR(x) #x
#define BEGIN "test"
#pragma message ".text= " XSTR(...
1
vote
1
answer
769
views
EEPROM Memory management on AVR XMEGAs
I'm having some difficulties understanding how EEPROM address space is managed.
Fact is (as far as I understood):
it is possible to have local variables on the EEPROM (e.g. using the EEMEM macro of ...
1
vote
1
answer
313
views
Encountering "Launch failed as no binaries could be found"
In AVR32 Studio (2.6) I'm trying to debug an AVR project and I get the error message "Launch failed as no binaries could be found".
I can see in the console that Build is complete (an executable .elf ...
1
vote
1
answer
85
views
avr-gcc ATmega4809 problem with `.rodata` section
(This is a follow up of this question)
The following program doesn't work (in ATmega4809)
#include <avr/io.h>
void f(const char str[])
{
if (str[0] == 'a') // <-- here is the problem. ...
1
vote
1
answer
2k
views
How to convince avr-gcc, that the memory position of a global byte array is a constant
I writing a fast "8 bit reverse"-routine for an avr-project with an ATmega2560 processor.
I'm using
GNU C (WinAVR 20100110) version 4.3.3 (avr) / compiled by GNU C version 3.4.5 (mingw-vista special ...
1
vote
1
answer
4k
views
Multiple definitions of - GCC bogus error
I have a header file lcd.h with this (shortened):
#pragma once
// ...
const uint8_t LCD_ROW_ADDR[] = {0x00, 0x40, 0x14, 0x54};
// ... other prototypes and macros...
And a file lcd.c where this ...