Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modulo operator error #148

Closed
davystrong opened this issue Feb 27, 2021 · 2 comments
Closed

Modulo operator error #148

davystrong opened this issue Feb 27, 2021 · 2 comments
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM

Comments

@davystrong
Copy link

Not sure if this is the correct place to report this or even if this is a known issue, but the modulo operator seems to have a problem. It works as expected when used with powers of two, but returns 1 when used with other numbers. This doesn't happen when running on my laptop. The following code demonstrates the issue on the Arduino Uno:

#![no_std]
#![no_main]
#![feature(abi_avr_interrupt)]

extern crate panic_halt;

use arduino_uno::prelude::*;

const PWM_PERIOD: i32 = 200;

#[arduino_uno::entry]
fn main() -> ! {
    let dp = arduino_uno::Peripherals::take().unwrap();

    let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);

    let mut serial = arduino_uno::Serial::new(
        dp.USART0,
        pins.d0,
        pins.d1.into_output(&mut pins.ddr),
        57600.into_baudrate(),
    );

    let mut val: i32 = 0;

    loop {
        ufmt::uwriteln!(&mut serial, "{}\r", (val % PWM_PERIOD)).void_unwrap();
        val += PWM_PERIOD / 2;
        arduino_uno::delay_ms(100);
    }
}

Let me know if this should be reported somewhere else.

@Rahix Rahix added the compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM label Feb 27, 2021
@Rahix
Copy link
Owner

Rahix commented Feb 27, 2021

Hey!

This is probably related to rust-lang/rust#82242 ...

@davystrong
Copy link
Author

Great, thanks. I'll watch that issue for updates. And thanks for your work implementing this package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM
Projects
None yet
Development

No branches or pull requests

2 participants