## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
rahix
@rahix:matrix.org
[m]
So instead of Mutex<T>, to Mutex<Cell<T>> or Mutex<RefCell<T>>
use RefCell when you need a &mut T reference, Cell if you just need a copy of T
first name last name
@igitter_gitlab
ahh okay, good to know, thank you!
first name last name
@igitter_gitlab
Is it possible to use I2c with the atmega_hal crate? I can only find examples which use arduino_hal. When I try to use it with atmega_hal the compiler tells me that I should explicitely set a concrete type for CLOCK. How hasatmega_hal::I2c::new(...) to be called to successfully return I2c?
rahix
@rahix:matrix.org
[m]
yes, should be possible
look at the arduino_hal sources, it defines a type alias for the core clock speed
and then an alias for I2c which uses this core clock type
I would suggest you do the same: define an alias for the clock speed and reference this whereever needed
first name last name
@igitter_gitlab
ahh okay, I probably overlooked that. I am going to investigate further. thx!!
first name last name
@igitter_gitlab
Yes, it works, thx again!!
Stephen
@stephen164_gitlab
Hi, I'm trying to get set up to develop on an AVR64DA48. I've worked through the example in the guidebook to get Blink working on my Arduino Uno, but now I'm not sure where to go from here in terms of getting the same program onto the DA. Can anyone point me to any similar guides / blogs / general-pointers for where I should go from here?
David
@drmorr0:matrix.org
[m]
FYI: I have a custom rustc toolchain for AVR that is based off a modern version of nightly, if anyone is interested. It includes my fix for making memcmp return i16 on AVR, it includes dylanmckay's patch to get around the "unrecognized instruction" issue, and it un-reverts the llvm_asm! removal, since none of the AVR libs have switched over to asm! yet. You can find it here, there are some very basic compilation instructions at the top of the README: https://github.com/drmorr0/rust/tree/drmorr-custom-rustc
Petruha04
@Petruha04

Hi!
Can't compile blank project or blink.
Windows 7 x64
nightly-x86_64-pc-windows-msvc
and
nightly-2021-01-07-x86_64-pc-windows-msvc

main.rs
#![no_std] // from the previous step
#![no_main]

#[no_mangle]
pub extern fn main() {
//let x=1+1;
}

C:!Electro!RUST\projects\avr168>cargo build -Z build-std=core --target avr-atm
ega328p.json --release
Compiling core v0.0.0 (C:!Electro!RUST.rustup\toolchains\nightly-2021-01-0
7-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core)
Compiling compiler_builtins v0.1.36
Compiling rustc-std-workspace-core v1.99.0 (C:!Electro!RUST.rustup\toolcha
ins\nightly-2021-01-07-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc
-std-workspace-core)
Compiling avr168 v0.1.0 (C:!Electro!RUST\projects\avr168)
error: language item required, but not found: eh_personality

error: #[panic_handler] function required, but not found

error: aborting due to 2 previous errors

error: could not compile avr168

How to compile blank project for AVR?

Tnx.

Petruha04
@Petruha04

with other toolchain :
C:!Electro!RUST\projects\avr168>cargo build -Z build-std=core --target avr-atm
ega328p.json --release
Compiling core v0.0.0 (C:!Electro!RUST.rustup\toolchains\nightly-x86_64-pc
-windows-msvc\lib\rustlib\src\rust\library\core)
Compiling compiler_builtins v0.1.71
warning: target json file contains unused fields: no-compiler-rt

Compiling rustc-std-workspace-core v1.99.0 (C:!Electro!RUST.rustup\toolcha
ins\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc-std-worksp
ace-core)
warning: rustc-std-workspace-core (lib) generated 1 warning (1 duplicate)
LLVM ERROR: Not supported instr: <MCInst 323 <MCOperand Reg:1> <MCOperand Imm:13

<MCOperand Reg:43>>
warning: compiler_builtins (lib) generated 1 warning (1 duplicate)
error: could not compile compiler_builtins; 1 warning emitted
warning: build failed, waiting for other jobs to finish...
warning: core (lib) generated 1 warning

Petruha04
@Petruha04

I haven't Arduino (some atmega48 and 168 chips).
Set to 2021-01-07
Get some parts from template (cargo.toml):

[package]
name = "avr168"
version = "0.1.0"
authors = [""]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
panic-halt = "0.2.0"
ufmt = "0.1.0"
nb = "0.1.2"
embedded-hal = "0.2.3"

# Configure the build for minimal size - AVRs have very little program memory
[profile.dev]
panic = "abort"
lto = true
opt-level = "s"

[profile.release]
panic = "abort"
codegen-units = 1
debug = false
lto = true
opt-level = "s"

main.rs

#![no_std] // from the previous step
#![no_main]
#![feature(llvm_asm)]

use panic_halt as _;

#[no_mangle]
pub extern fn main() {
loop {
unsafe {
llvm_asm!("NOP"); }

}

}

Now it's ok, but minimum size 500 byte :(

Petruha04
@Petruha04
What should I connect to use minimal abstraction (PORTB etc.)
Tnx!
Petruha04
@Petruha04
#![no_std] // from the previous step
#![no_main]
#![feature(llvm_asm)]

use panic_halt as _;
extern crate avrd;
use avrd::current::*; // Import constants for the target MCU
//use core::intrinsics::volatile_store;

//#[no_mangle]
fn main() {
unsafe {
llvm_asm!("NOP");
}
let mut number: u8 = 12;
number-=1;
match number {
11 => number-=3,
12 => unsafe {llvm_asm!("NOP;
NOP;
NOP;")},
_ => unsafe {llvm_asm!("NOP")},
}

}
Can't understand how to use.
Sorry, asm (a little bit).
avrd::current::PORTB ???????
Petruha04
@Petruha04
Scheiße
Jeremy Salwen
@jeremysalwen
Hey all, what is the currently recommended version of the rust compiler for use with the avr/the atmega 328?
rahix
@rahix:matrix.org
[m]
latest nightly! the LLVM fixes finally landed so it should be good
Mikhail Trishchenkov
@kriomant
Hi! I'm trying to use blink example (https://github.com/avr-rust/blink/blob/master/src/main.rs) on Arduino Uno. Internal LED turn on but never off. What may be wrong? Equivalent C program loaded via Arduino Studio works fine.
jannic
@jannic:matrix.org
[m]
Without knowing anything avr-rust specific, I would try to check that the delay works as expected. Perhaps the LED is just blinking so fast that you can't see it turn off?
pwychowaniec
@pwychowaniec:matrix.org
[m]
@kriomant: are you using the latest nightly compiler? (if so, then which branch of avr-rust are you using, considering the fact that master/main probably doesn't work, since it's not been updated to the newer compiler 😅)
if you're using some nightly-2021-whatever, then just switch to e.g. today's nightly -- avr-rust most likely won't compile on it, but avr-hal (that has a very similar interface) should work: https://github.com/Rahix/avr-hal/blob/main/examples/arduino-uno/src/bin/uno-blink.rs
Myles Empty Best
@TheEmpty
I'm looking for an example of avr-hal reading a digital input. I don't see anything in the examples for that, closest is a button on interrupt but I don't think that's what I'm looking for. Use-case is checking if a pin is high or low (engine already on) before trying to start a generator.
pwychowaniec
@pwychowaniec:matrix.org
[m]
there's also a lot of examples in https://github.com/Rahix/avr-hal/tree/main/examples! 😄
dirbaio
@dirbaio:matrix.org
[m]
hey guys, what's the state of AVR Rust?
A while ago, someone contributed AVR support to critical-section and atomic-polyfill, pinning a very old nightly because newer ones are apparently broken https://github.com/embassy-rs/critical-section/pull/12#discussion_r845507104
that linked issue is still open, but I see avr-hal is using nightly-2022-06-13, so maybe that's been resolved?
is it OK if I drop support for the old nightly?
rahix
@rahix:matrix.org
[m]
yeah, you should be able to upgrade
although I would still pin it just to make sure you won't see spurious CI failures when latest nightly breaks again
dirbaio
@dirbaio:matrix.org
[m]
yeah I always pin them 👍️
so this means latest nightly should be fine, so I no longer need to pin a special one for AVR
nice! thanks
wonder why that issue is still open though rust-lang/rust#88252
rahix
@rahix:matrix.org
[m]
hm, probably got lost... the real issue was rust-lang/compiler-builtins#400 and that's been closed
dirbaio
@dirbaio:matrix.org
[m]
ahh nice! thanks :)
🥲
dirbaio
@dirbaio:matrix.org
[m]
same with nightly-2022-06-13
rahix
@rahix:matrix.org
[m]
debug build? can you try with the build profile from avr-hal?
dirbaio
@dirbaio:matrix.org
[m]
ahh yep it works with --release
so odd :D
rahix
@rahix:matrix.org
[m]
yeah, we heavily rely on llvm optimizing stuff out before handing the code to the AVR backend...
Carl Peto
@carlos4242
Have any of you guys ever used the mmcu section that simavr reads to know what VCD traces to output from the simulator?