Skip to content

Doesn't work properly when added as dependency (for Arduino Mega 2560) #11

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

Closed
Flowneee opened this issue Mar 11, 2021 · 2 comments
Closed

Comments

@Flowneee
Copy link

Hi! I'm trying to use this crate and encountered problem: delay is TOO short when library is added as dependency. I use this code for blink LED:

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

use avrd::current as c;

mod delay; // your source code, copied into file inside project 

#[no_mangle]
pub extern "C" fn main() {
    unsafe {
        *c::DDRB = 0xFF;
        *c::PORTB = 0x00;
    };

    loop {
        unsafe {
            *c::PORTB = 0xFF;
            // here is used local copy of `delay_ms`
            // it works OK, LED is on for about second
            delay::delay_ms(1000); 

            *c::PORTB = 0x00;
            // here is used `delay_ms` from dependency `avr_delay`
            // it is TOO short, blink (off) is barely visible (few milliseconds maybe);
            avr_delay::delay_ms(1000); // h
        };
    }
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

Also interesting thing: when I upload program with avrdude, version with avr_delay dependency is much bigger than version with only local copy:

// Only local copy
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "target/atmega2560/release/blink.elf"
avrdude: writing flash (826 bytes)

// With external dependency
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "target/atmega2560/release/blink.elf"
avrdude: writing flash (2844 bytes)

I also tested:

  • create copy of avr_dude on my machine and import with avr_delay = { path = ... };
  • manually set cpu frequency in source code (instead of avr_config);

but all the same, if I use avr_delay from external dependency, it works way too fast.

I'm using Arduino Mega 2560 (or maybe it is Chinese clone, I'm not sure). My target:

{
    "arch": "avr",
    "atomic-cas": false,
    "cpu": "atmega2560",
    "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
    "eh-frame-header": false,
    "exe-suffix": ".elf",
    "executables": true,
    "is-builtin": true,
    "late-link-args": {
        "gcc": [
            "-lc",
            "-lgcc"
        ]
    },
    "linker": "avr-gcc",
    "linker-flavor": "gcc",
    "linker-is-gnu": true,
    "llvm-target": "avr-unknown-unknown",
    "max-atomic-width": 0,
    "os": "unknown",
    "pre-link-args": {
        "gcc": [
            "-mmcu=atmega2560",
            "-Wl,--as-needed"
        ]
    },
    "target-c-int-width": "16",
    "target-endian": "little",
    "target-pointer-width": "16"
}

Let me know if I could provide anything else.

P.S. Local copy only works properly when opt-level set to 2 or 3, maybe this is somehow helpful.

P.P.S. Code is still super useful, it is very easy and intuitive for beginner like me, thanks!

@stappersg
Copy link
Member

Let me know if I could provide anything else.

Please try again, because much has be changed & improved last fifteen months.

@Flowneee
Copy link
Author

Flowneee commented Jun 9, 2022

Please try again

Thank you, bu unfortunately I am unable to test it now. I am gonna close this issue, if somehow I will be able to try it and something doesn't work, I wil open a new issue

@Flowneee Flowneee closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants