avr-hal icon indicating copy to clipboard operation
avr-hal copied to clipboard

Very weird error when compiling a very basic program: __addsf3 multiple defenitions

Open itamarsch opened this issue 1 year ago • 10 comments

image

#![no_std]
#![no_main]
use arduino_hal::clock::MHz16;
use arduino_hal::hal::delay::Delay;
use arduino_hal::{delay_ms, i2c};
use arduino_hal::{I2c, Peripherals};
use lcd_lcm1602_i2c::Lcd;
use numtoa::NumToA;
use panic_serial;
const PHI: f64 = 1.61803398;

type LCD<'a> = Lcd<'a, I2c, Delay<MHz16>>;
const LCD_ADDRESS: u8 = 0x3f;
//
panic_serial::impl_panic_handler!(
  arduino_hal::usart::Usart<
    arduino_hal::pac::USART0,
    arduino_hal::port::Pin<arduino_hal::port::mode::Input, arduino_hal::hal::port::PD0>,
    arduino_hal::port::Pin<arduino_hal::port::mode::Output, arduino_hal::hal::port::PD1>
  >
);

fn lcd_init<'a>(i2c: &'a mut I2c, delay: &'a mut Delay<MHz16>) -> Result<LCD<'a>, i2c::Error> {
    let mut lcd = lcd_lcm1602_i2c::Lcd::new(i2c, delay)
        .address(LCD_ADDRESS)
        .rows(2) // two rows
        .init()?;

    lcd.backlight(lcd_lcm1602_i2c::Backlight::On)?;
    lcd.clear()?;
    lcd.set_cursor(0, 0)?;
    Ok(lcd)
}

#[arduino_hal::entry]
fn main() -> ! {
    let dp = Peripherals::take().unwrap();
    let pins = arduino_hal::pins!(dp);
    let serial = arduino_hal::default_serial!(dp, pins, 57600);
    let serial = share_serial_port_with_panic(serial);

    let mut i2c = arduino_hal::I2c::new(
        dp.TWI,
        pins.a4.into_pull_up_input(),
        pins.a5.into_pull_up_input(),
        50000,
    );

    let mut delay = arduino_hal::Delay::new();

    let mut lcd = lcd_init(&mut i2c, &mut delay).unwrap();

    let mut i: f64 = 1.0;
    let mut buf = [0u8; 100];

    loop {
        i = libm::round(i * PHI);
        let u32v = i as u32;
        delay_ms(10);
        lcd.clear().unwrap();
        lcd.set_cursor(0, 0).unwrap();
        lcd.write_str(u32v.numtoa_str(10, &mut buf)).unwrap();
    }
}

itamarsch avatar Apr 30 '24 22:04 itamarsch

I think:

  • There should a git repository with the above main.rs PLUS Cargo.toml and such files for reproducablity
  • This should be in a discussion

stappersg avatar May 01 '24 10:05 stappersg

First of all, you really should be avoiding the use of f64 on AVR microcontrollers. This will eat up tons and tons of memory because all floating point operations need to be implemented in software. If you really need floats, f32 is at least not quite as bloaty...

That said, the error still shouldn't happen. It is most likely a compiler issue of some sorts, though. Ping @Patryk27 maybe you know something?

Rahix avatar May 04 '24 12:05 Rahix

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created https://github.com/rust-lang/compiler-builtins/pull/601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

Patryk27 avatar May 04 '24 17:05 Patryk27

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created https://github.com/rust-lang/compiler-builtins/pull/601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

In rustc where is the version of compiler-builtins defined? I'm not really familiar with the rustc codebase

itamarsch avatar May 07 '24 13:05 itamarsch

Right here :-)

Patryk27 avatar May 07 '24 15:05 Patryk27

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created https://github.com/rust-lang/compiler-builtins/pull/601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

@Patryk27 Have you bumped up compiler-builtins?

itamarsch avatar May 11 '24 11:05 itamarsch

I'm on it, but there are some (AVR-unrelated) crashes that I need to investigate.

Patryk27 avatar May 12 '24 10:05 Patryk27

Status: together with my AVR fix, bumping compiler-builtins brought some extra (non-AVR-related) f16 & f128 changes which need special handling in the compiler, so it's not as easy of a merge as usual - the current pull request is:

https://github.com/rust-lang/rust/pull/125016

Patryk27 avatar May 18 '24 09:05 Patryk27

Status: same as https://github.com/Rahix/avr-hal/issues/566#issuecomment-2276373883.

Patryk27 avatar Aug 08 '24 18:08 Patryk27

Okie, it should work on the newest toolchain 🙂

Patryk27 avatar Sep 24 '24 11:09 Patryk27