663 questions
Advice
0
votes
5
replies
57
views
object file is twice larger than expected
I have a AVR GCC toolchain compiled to work on aarch64-linux-gnu devices (ARM64) and it produced twice larger file (around 35Kb) than almost identical command-line on desktop (mac silicon, around 20Kb)...
4
votes
2
answers
130
views
avr-g++ - Undefined reference to register Y upon linking
I have a weird problem when doing inline asm and compiling/linking with avr-g++ (version 16, fresh from the Git). I think this might be a bug of the tool chain, but I wanted second opinions in case I ...
3
votes
1
answer
72
views
Why does the compiler give strncpy 'stringop-truncation' warning only with -O2?
With avr-gcc 14, the compiler gives this warning:
avrenv.c: In function ‘main’
avrenv.c:12:13: warning: ‘strncpy’ output may be truncated copying 255 bytes from a string of length 509 [-Wstringop-...
0
votes
0
answers
48
views
Proper linking for aarch64-linux-android libstd to fix "improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC"
I'm cross compiling (canadian build) AVR-GCC 7.3.0 to work on aarch64-linux-android (typical 64bit android devices) with Android NDK r29 on Ubuntu. During the build i'm getting:
...
/home/anton/tools/...
0
votes
0
answers
34
views
avr-gcc: error: -fuse-linker-plugin is not supported in this configuration
I'm cross-compiling avr-gcc statically (in order not to depend on Android linker) to work on aarch64 android devices.
gcc is compiled with the flags:
generic_arm64:/data/data/myapp/files/sdk/hardware/...
0
votes
1
answer
92
views
Cross-compiled executable for arm64: "No such file or directory"
I've cross-compiled an executable (AVR GCC) to run on Android arm64 device with aarch64-linux-gnu toolchain (not using Android NDK).
file avr-g++ gives the following in "adb shell":
file avr-...
2
votes
3
answers
127
views
Local and global pointer to PROGMEM
I got:
#include <inttypes.h>
typedef struct dbg_s dbg_t;
struct dbg_s{
const uint8_t size;
const uint8_t* item;
};
#define DBG_SIZE 2
const uint8_t const dbgItems[DBG_SIZE] PROGMEM = {...
0
votes
0
answers
97
views
ATtiny85 software latch with button hold for running / sleeping state change
I'm making a software latch with following features:
ATtiny85 @ 1 MHz, BOD disabled
PB0 = LED, PB3 = Button (with internal pull-up) Interrupt on change
Deep sleep until button press
Change state with ...
2
votes
1
answer
49
views
Can I build an avr-libc static library without specifying target MCU?
I am building an avr-libc static library like this:
avr-gcc -O2 -I. -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -g -ggdb -ffunction-sections -fdata-...
1
vote
2
answers
72
views
Arduino Nano ATmega328P C++; unsigned 8bit shift right generates 16bit code. This wastes time and memory. Can this be fixed or avoided?
With an Arduino Nano ATmega328P (Arduino IDE 1.8), the following C++ code (with 8bit operands):
volatile uint8_t un8 = 123;
volatile uint8_t res8;
res8 = un8 >> 1;
generates a 16bit shift ...
1
vote
1
answer
77
views
Why does AVR-GCC show the line "text+data+bootloader" when compiling the simple LED blinker?
Avr-gcc 7.1, Win10.
When compiling a simple LED blinker C code using avr-gcc, it outputs:
Invoking the avr-gcc is done by hand using:
avr-gcc -g -Os -mmcu=attiny13a -c "Attiny_blink_01.c"
...
1
vote
5
answers
155
views
Passing a non-volatile variable pointer to a function expecting a volatile variable pointer
I'm rewriting an interrupt based I2C driver to avoid internal fixed buffer sizes. To achieve this, I'm passing a buffer pointer into the driver for it to use. This is simple for the transmit case as ...
-3
votes
2
answers
134
views
AVR-GCC macro behaviour
I have a simple C program:
#include <stdint.h>
#define WHEELS_PWM_CYCLES_PER_MS (5)
#define WHEELS_TIME_TO_GO_1_CM_MS (10)
int main(void)
{
for (;;) {
uint32_t x = (uint32_t)...
1
vote
1
answer
82
views
How to reliably determine that current CMake compiler is the avr compiler?
I could of course be lazy and determine it by path alone. But say I want a more reliable approach, like:
if(IS_AVR)
add_compile_options(
--arduino-avr-specific-option
)
endif()
CMake ...
2
votes
2
answers
87
views
Can snprintf format '-0'?
On AVR 8-bit, avoiding floats, I'm dividing a signed integer and formatting it with snprintf:
int16_t tempx10 = -5;
div_t temp = div(tempx10, 10);
char buf[10];
snprintf(buf, sizeof (buf), "%4d.%...
1
vote
1
answer
109
views
Is there a way to create a static array in the .data section, where its length is calculated by the size of the .bss section on the Arduino?
I'm just wondering if there is a way I can tell the compiler that I want to create a static array inside the .data section of the Arduino's SRAM, where the array's size is calculated using the size of ...
0
votes
2
answers
172
views
Binary size bloats 20x if moved from src/main.rs to examples/
I'm making a library for Arduino Uno in Rust from scratch. Currently, there's a basic Serial.write print example in the src/main.rs, which on compilation is around 500 bytes (cargo b --release).
$ avr-...
1
vote
2
answers
107
views
How to get an ATtiny24A MCU into sleep mode?
I am experiencing somewhat a peculiar phenomenon. I am trying to get an ATtiny24A into sleep mode. I had a working code before, but through revisions and testing of other parts of my program it seems ...
3
votes
1
answer
89
views
Calling C function from the .init3 section of a AVR-GCC compiled program
I am working on a project that contains a firmware update failure feature that :
notifies user/host that firmware update failed whenever the device gets unplugged in the middle of a firmware update ...
4
votes
1
answer
76
views
Where is the offset of the Y register from the call/stack frame in avr-gcc coming from?
On the avr-gcc website (https://gcc.gnu.org/wiki/avr-gcc#Frame_Layout) it says that the frame pointer (Y register) is off by one byte so Y+1 points to the bottom of the frame. However when I compiled ...
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. ...
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 ...
0
votes
1
answer
172
views
avr-ld errors; cannot find crtatmega328p, cannot find -lm, ect
I'm trying to link two object files from Makefile, but the linker keeps throwing errors at me. I can't seem to find this errors whe I search the web, so I hope anyone here can help.
In my Makefile, I ...
1
vote
1
answer
285
views
AVR ATtiny1626 bizarre infinite interrupt problem
I have an ATtiny1626 code that I'm in the early stages of just getting the modules going on my custom board for my client.
I had some issues with my interrupts being called indefinitely over and over.
...
0
votes
1
answer
223
views
How to fix a simple error in Atmel studio
I am programming an Atmega chip using Atmel studio 7. I try to define F_CPU on the first line of the main.c file. This F_CPU definition is used inside the other files. However when I compile the ...
0
votes
2
answers
106
views
Template with parameter pack compiles using avr-gcc, but not using Arduino IDE
I'm trying to write a generic template for Print for an Arduino project. In doing so, I encountered a compiler error I didn't understand, so I made a minimum reproducible example.
template <...
1
vote
1
answer
266
views
Issues with Link Time Optimization (LTO) on avr-gcc with ATmega328
I’m working on a project with an ATmega328 and using avr-gcc/g++. I'm trying to enable Link Time Optimization (LTO), but I’m encountering issues during linking.
Here's a simplified example:
• Static ...
0
votes
1
answer
94
views
Compiler Truncates Interrupts Vectors of ATmega328PB in Eclipse AVR Plugin
I would normally use Eclipse avr-gcc plugin and (avr-gcc compiler from zaks https://blog.zakkemble.net/avr-gcc-builds) to develop firmware for AVR MCU.
The MCU ATmega328PB has extra timers (3,4), SPI1,...
2
votes
2
answers
138
views
Saturating addition optimization in avr-gcc
I am programing for ATtiny13 and I have to do a lot of saturating additions.
Trying to optimize them, it seems that avr-gcc just doesn't know how to optimize anything at all. All of this was tried ...
0
votes
3
answers
138
views
How does C compiler or Preprocessor handle MACRO with arguments differently?
I am working on a code for the Atmel Microcontroller and using ATMEL Studio.
You can check the toolchain and studio version from here.
*\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\...
4
votes
1
answer
167
views
Why is 'Placement New' for classes with virtual Members only working when buffer is on local stack?
I have some C++-Code which uses the Placement New operator to create an instance of a class with virtual members in an existing buffer. It works as expected when the buffer is on the local stack of ...
4
votes
2
answers
764
views
char arrays in PROGMEM
In a program, I have a lot of arrays of different length strings, and each array is declared as an array of pointers to those strings, like:
static const char * num_tab[] = {"First", "...
1
vote
2
answers
154
views
AVR128DB28 communication with SD card over SPI failed
I am trying to achieve communication between an AVR128DB28 microcontroller and an SD card over SPI.I'm programming it in Microchip Studio, programming is done through an MPLAB SNAP over UPDI. The ...
0
votes
1
answer
107
views
libgcc subroutines documentation for avr-gcc
I disassembled some C++ code with the avr-gcc compiler in godbolt and often found calls to libgcc subroutines like __udivmodhi4 or __mulhi3.
Where can I find good and insightful documentation about ...
1
vote
1
answer
154
views
Passing string by reference not working in Atmel Studio
MCU: Atmega2560
IDE: Microchip Studio v7.0.2594
Toolchain: WinAVR (also tried with Native)
I am trying communicate with my MCU over UART. I have written two very basic functions over UART to transmit ...
2
votes
1
answer
352
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 ...
0
votes
0
answers
74
views
AVR-GCC (Arduino) - IEEE 754/IEC 559 compliance
Informally, it appears AVR-GCC is IEEE 754 compliant.
In this environment, how do I verify at compile time that floats are indeed IEEE 754 compliant? Much searching yields informative but ...
2
votes
1
answer
1k
views
"avr/io.h" not found when compiling assembly for ATmega128
I'm new to assembler and ATmega128.
The problem I have is I can't compile my assembly file. After this step I'd want to upload the program to an STK-300.
Here's the code
.include "avr/io.h"
...
0
votes
1
answer
241
views
How do I access the "most official" repository for architecture specific GCC runtime source files&tests?
Here&there I find the likes of mulqi3.S & divmodhi4.S.
Is there a reference anywhere on gnu.org on how to browse current official revisions of such architecture specific source code? What is ...
1
vote
2
answers
144
views
Class template with multiple parameters and default parameter
I've a class template like that:
struct Relay
{
int pin;
bool state;
};
template<std::size_t N, uint8_t D = 10>
class RelayArray
{
private:
Relay array[N]; //or std::array<Relay, ...
0
votes
1
answer
237
views
2-wire: TWINT is never set in TWCR after start condition is sent
I'm using the ATmega328P TWI interface as follows.
The problem is that it goes into an infinite loop strobing the LED, and never turns the LED off. If I change the condition to TRUE then it turns the ...
2
votes
3
answers
235
views
C compose unsigned 32-bit integer from four 8-bit integers
On an 8-bit platform, I am composing an unsigned 32-bit integer from 4 8-bit integers like this:
uint8_t buf[4];
uint32_t large = 0;
large |= ((uint32_t)buf[0]) << 24;
large |= ((uint32_t)buf[1])...
1
vote
1
answer
402
views
ATmega328P EEPROM not writing
I'm writing to the ATmega328P EEPROM as follows:
eeprom_write_byte(address, (U8_T) 0);
void eeprom_write_byte(void* address, U8_T data)
{
cli();
/* Wait for previous write to complete */
...
2
votes
1
answer
98
views
Casting a constant to a pointer increases .data size by 1000 bytes
I'm at a total loss with this one, I don't even know what to include in my question.
When I cast a constant to a pointer my (.data + .bss + .noinit) section grows by 1K, exceeding the ATmega328P's ...
1
vote
1
answer
173
views
Is it possible to store the float type results obtained from the code calculation in FLASH memory?
I am using Attiny1616 with Microchip Studio.
I want to store the float type results obtained from the calculation of the code in FLASH memory.
I have looked into PROGMEM, but PROGMEM does not support ...
2
votes
1
answer
384
views
Why are functions executed in the order they are defined and not in the order they are called from the int main() in avr-c?
I am trying to learn AVR C, and was tinkering with the atmega328p microcontroller. I am using the avr-gcc toolchain on Linux Mint to compile and flash my code to the Arduino board.
So I was trying to ...
0
votes
0
answers
56
views
avr-g++ stores temporary variables for function parameters in memory
I am using avr-g++ 10.2.0 on Fedora 37, target is ATmega128.
My project should be optimized for code size and RAM usage.
One 8-bit hardware register port is defined like this:
struct MyPort
{
...
0
votes
0
answers
154
views
`if constexpr` does't compile with `avr-g++ -std=c++17` [duplicate]
In a method in a class I'm working on I have
template <typename T = int_fast16_t, uint8_t Bits = sizeof(T) * 8 - 2>
struct FixedPointFraction {
using value_type = T;
constexpr static uint8_t ...
-1
votes
1
answer
190
views
figure out flash access AVR ATmega2560
EDIT: update learning assembly:
ok so this function causes no compiler warnings and they should all be turned on now. Are my constraint values correct for these inputs and outputs?
void ...
0
votes
2
answers
223
views
Unexpected Timer/Counter B interrupt frequency on ATtiny204
I'm trying to implement a timing system on an ATtiny204 using Timer/Counter B in Microchip studio but I'm getting a very unexpected interrupt frequency based on my register and fuse settings.
I have ...