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
Added support for atmega1280 and bigavr6 #1
Conversation
I think the pins are not correct, for example the datasheet lists You could also add the other UART peripherals without much more work as well, if you want |
Yeah, I purposely only added what was needed for the examples to run for now. I can add the rest in a few hours if you’d like |
Oh, no, the pl* missing might just have been me overlooking something when copying |
Pins fixed, USARTs added to the hal. in the bsp, should i replace |
I don't know much about BIGAVR6, so I can only guess what is right ... I reexported |
For the pins: I don't think it makes sense to create the Pins struct at all if the names in there are just the same as for the actual chip's pins. Instead, the following "user" code would do the same: let dp = bigavr6::Peripherals::take().unwrap();
let mut porta = dp.PORTA.split();
let led = porta.pa0.into_output(&mut porta.ddr); The only reason for the Now, I don't know how BIGAVR6 looks, so you'll have to decide if there is some sensible naming scheme. If not, then just remove the |
Okay, I'll remove the pin struct, and I'll change the reexport of the USART. All of the USARTs are pinned out on the BIGAVR6, but iirc there is a "Serial1" and "Serial2" with actual Serial Port headers, so exporting those with the same name as on the board might make sense. Thanks for your feedback :) |
By the way, you can remove |
Say what now?! how did I miss this? Will do! btw: the board itself labels two serial ports RS-232 A and B respectively. What do you think would be more understandable? SerialA or RS232A? |
Hmm, I'd argue RS232 is just the name of the connector while the protocol is 'Serial'. From the software side we only care about the protocol, so I'd call it |
Removed pins, correctly specified serial interface (i actually remembered that rs232a and b are actually on the same usart, with dip-switches to choose between them 🙄 ) |
Hmm, when i try to implement the panic example, I get the following output:
|
Hmm, this is really weird ... Technically, the Can you try replacing the hackish initialization with a proper one like let dp = unsafe { bigavr6::Peripherals::steal() };
let mut porte = dp.PORTE.split();
let mut serial = bigavr6::Serial::new(
dp.USART0,
porte.pe0,
porte.pe1.into_output(&mut porte.ddr),
57600,
); please? |
Apparently the problem is somewhere in the formatting. If I don't use all of the elements (for example, only file:line, or file:column), or if i substitute one of them with a constant, it works, but as soon as I use all of them it crashes. I tried the different initialization logic, but it still crashes |
Side note: this is done using an atmega1280 simulator, since I don't have a board here right now. So there could be an issue with the simulator, but I don't think it's that likely. |
Huh, ok ... Try splitting the
I am pretty sure it does. At the beginning of |
I've done this now:
This crashes. A bit of testing showed: whether the file is printed doesn't matter, it only crashes if i use line and column O.o |
Right, this might make sense: |
Try formatting a |
Formatting line/column and a static u32 seems to work though |
I have to go now, I'll probably be back online in an hour or so. Thanks so much for your help! :) |
Oookay, I changed the hello world line to
I think that was just a fluke. It still crashes afterwards |
Okay, I'm getting closer: It crashes anytime I have two u32 formats in my code. But it crashes on the first one. So that might be a problem with the formatter on one hand, but maybe also with the macro itself. |
Hmm ... Can you try using the |
I might have some time this weekend to spin up the avr simulator myself and try to reproduce the issue as well ... |
Using only |
I am able to reproduce your issue ... It is very strange and to be honest feels a lot like a compiler bug. For example, compiling in debug works totally fine. Under some circumstances, in release it works as well, but with others it does not ... |
Does the generated assembly show any hints of why it goes bad sometimes? |
I really don't know ... From what I can see, it only happens if a panic handler is involved, which is really weird. It works perfectly fine if its just in main, but as soon as I add the The observation that it needs two formattings to happen is also interesting. I'd guess this stems from a single formatting being inlined while for two, the compiler creates a separate function. We should definitely submit this upstream, but only after reducing the failing code to a minimal example. Would you be interested in doing that? |
Wow ... After retrying my Arduino Leonardo version, it now stopped working as well (on real hardware as well) ... I have no idea what is different now |
Huh ... So it works with |
Unfortunately I won't have much time next week. If you want to continue tracking this down, I would suggest you try reducing the example so you end up with a minimal version (one core::ptr::volatile_write(0xF0 as *mut u8, 0xBA); (Only if you really feel like torturing yourself like that ...) |
I could not leave it alone ... I took a look with the debugger and found that the #[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let mut serial: bigavr6::Serial<bigavr6::hal::port::mode::Floating> = unsafe {
core::mem::uninitialized()
};
// Using 0x9 instead of 0xA works ...
unsafe { core::ptr::write_volatile(0x3E as *mut u8, 0xA); }
ufmt::uwriteln!(&mut serial, "Firmware panic!\r").unwrap();
if let Some(loc) = info.location() {
ufmt::uwriteln!(
&mut serial,
" At {}:{}:{}\r",
loc.file(),
unsafe { core::ptr::read_volatile(0x3E as *mut u8) } as u8,
unsafe { core::ptr::read_volatile(0x3E as *mut u8) } as u8,
);
}
loop {}
} |
Alright, there it is: We only see this bug in this form when using a panic because the |
I have reported the issue upstream: avr-rust/rust-legacy-fork#148 |
Thanks a lot. I’m currently not in a shape to sit in front of a computer, so I’m thankful you tracked down the bug :) as soon as I’m better I’ll continue fleshing out the pr :) |
Alright, take your time to get better, I wish you the best! I will continue working on getting this fixed upstream. Don't consider the bug blocking for your PR. |
As reported by @peacememories in #1, the hint::unreachable_unchecked intrinsic is leading to a codegen bug if the ufmt usize formatter is not inlined. This bug has to be fixed in the compiler and was reported upstream as avr-rust/rust-legacy-fork#148. Until the actual cause and a solution are found, this fork of ufmt which does not use the above mentioned intrinsic, should be used as a workaround. Signed-off-by: Rahix <rahix@rahix.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have pushed a workaround for the bug you found. I also took another look at this PR. From my perspective, it looks good to merge. Is there anything you still want to work on before I do so?
@peacememories, can we merge this? |
@Rahix sorry for the late reply. Yes it can technically be merged. It's not finished yet, but what is there should be working. Unfortunately I can't work on the PR right now since my avr-rustc is broken^^' |
Completely forgot to mention it here: I went ahead and manually merged your work in commit a8b2a8a. I hope that is ok with you ... So even though this PR will be marked as closed, your work is actually now integrated into master! |
do not merge this yetThis addition does not work yet and crashes the compiler.Both examples work now. The port definitions are not at all complete though.]
Also I don't have any idea yet on how to add stuff like a display that can occupy exactly one set of pins (because it is hardwired there) and is easy to create.