Initializing UART driver causes execution to freeze. #121
-
My setup for this is slightly different from the one shown, but only slightly. I'm using Now after introducing For example, in the fn flush(&self) {
// Execution doesn't enter the loop because on checking the FR, it freezes
while self.registers.FR.matches_all(FR::BUSY::SET) {
cpu::nop();
}
} Similarly, if I comment everything else out from the self.registers.CR.set(0);
// this also causes execution to freeze I'm able to write to the same memory location with // this works
unsafe { core::ptr::write_volatile(0x3F20_1030 as *mut usize, (0b1 << 31)); } I'm now out of ideas on what to try, I've tried looking at the disassembly with Here is my repository if that helps. Right now I've modified the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
The GitHub actions CI has tests for the UART output as provided by QEMU, and it seems that still works, so I assume it must be something local on your setup. Unsure when I will find time to look at it, but I’ll try to check it when I can. |
Beta Was this translation helpful? Give feedback.
-
A little update which doesn't really help a great deal but still something to consider maybe. pub fn init(&mut self) {
// self.flush();
unsafe {
let fr = read_volatile(0x3f20_1018 as *mut u32);
while (fr & (0b1<<3 as u32)) != 0 {
cpu::nop();
}
}
// self.registers.CR.set(0);
unsafe { write_volatile(0x3f20_1030 as *mut u32, 0 as u32) };
// self.registers.ICR.write(ICR::ALL::CLEAR);
unsafe { write_volatile(0x3f20_1044 as *mut u32, 0 as u32) };
// Set the baud rate, 8N1 and FIFO enabled.
unsafe {
// self.registers.IBRD.write(IBRD::BAUD_DIVINT.val(3));
write_volatile(0x3f20_1024 as *mut u32, (
read_volatile(0x3f20_1024 as *mut u32) & 0b1111111111111111
));
// self.registers.FBRD.write(FBRD::BAUD_DIVFRAC.val(16));
write_volatile(0x3f20_1028 as *mut u32, (
read_volatile(0x3f20_1028 as *mut u32) & 0b111111
));
// self.registers.LCR_H.write(LCR_H::WLEN::EightBit + LCR_H::FEN::FifosEnabled);
write_volatile(0x3f20_102c as *mut u32, (
(read_volatile(0x3f20_102c as *mut u32) & 0b11<<5)
+
(read_volatile(0x3f20_102c as *mut u32) & 0b1<<4)
));
}
// Turn the UART on.
// self.registers.CR.write(CR::UARTEN::Enabled + CR::TXE::Enabled + CR::RXE::Enabled);
unsafe {
write_volatile(0x3f20_1030 as *mut u32, (
(0b1<<9 + 0b1<<8 + 0b1) as u32
));
}
} This doesn't cause any issues as such which I suppose is expected. But I still don't know if this is right since this might not be doing the exact same things as |
Beta Was this translation helpful? Give feedback.
-
The problem was being caused by a few misplaced |
Beta Was this translation helpful? Give feedback.
The problem was being caused by a few misplaced
#[cfg(feature = "...")]