rust-osdev / uart_16550 Goto Github PK
View Code? Open in Web Editor NEWMinimal support for uart_16550 serial output.
License: MIT License
Minimal support for uart_16550 serial output.
License: MIT License
Stumbled over this crate while writing a toy OS.
Currently only x86
is supported (via x86_64::...::Port
).
Would PR with RISC-V support be accepted?
I tried following the test part of the Rust OSDev Tutorial but when i try using serial_port.init();
I get this error.
error[E0599]: no method named `init` found for unit type `()` in the current scope
--> src/serial.rs:9:21
|
9 | serial_port.init();
| ^^^^ method not found in `()`
I am using uart_16550 version 0.2.0
I don't know if this is the right place.
please... since I cannot implement Write on your types
Line 12 in 520b9d6
Error:
error[E0557]: feature has been removed
--> C:\Users\chknm\.cargo\registry\src\github.com-1ecc6299db9ec823\x86_64-0.12.3\src\lib.rs:9:43
|
9 | #![cfg_attr(feature = "const_fn", feature(const_in_array_repeat_expressions))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
|
= note: removed due to causing promotable bugs
error: could not compile `x86_64`
An update is required to work.
I'll preface this by saying that it's very possible that I've totally misunderstood how this all works.
As I understand it from reading https://wiki.osdev.org/Serial_Ports#Port_Addresses, it's possible that not even COM1
may exist, and so it's recommended to always test a port via loopback and the "scratch pad register". There's some example code further down the page that appears to do this:
#define PORT 0x3f8 // COM1
static int init_serial() {
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
// Check if serial is faulty (i.e: not same byte as sent)
if(inb(PORT + 0) != 0xAE) {
return 1;
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
outb(PORT + 4, 0x0F);
return 0;
}
I was thinking it might be nice if this crate, rather than marking SerialPort::new
as unsafe
, instead rolled init
into new
(I don't see that there would ever be a reason not to call init
?), and that it does the loopback + scratch pad register test. new
could then return a Result
depending on the outcome.
In one of my own projects, I had a case where binary data is transmitted through UART. But later I discovered that the code in this crate silently escapes the backspace character \x08
to \x08\x20\x08
, which causes data corruption in my code:
match data {
8 | 0x7F => {
wait_for!(self.line_sts().contains(LineStsFlags::OUTPUT_EMPTY));
self.data.write(8);
wait_for!(self.line_sts().contains(LineStsFlags::OUTPUT_EMPTY));
self.data.write(b' ');
wait_for!(self.line_sts().contains(LineStsFlags::OUTPUT_EMPTY));
self.data.write(8)
}
[...]
}
Maybe this behavior should be clearly described in the documentation, and another method which disables escaping should be added?
The const_ptr_offset
feature was stabilized in rust-lang/rust#93957. We removed that feature gate from this crate in #22. Right now, we still need the stable
and nightly
features of this crate to make MmioSerialPort::new
a const function on nightly, but on Rust 1.61 this should be supported on stable as well. So we should remove the crate features when 1.61 is released.
Line 83 in d401ea1
I have tried to add this crate to an empty project with rust nightly.
When trying to build compilation fails with error:
error[E0658]: use of unstable library feature 'renamed_spin_loop'
It also recommends to add the crate attribute #![feature(renamed_spin_loop)]
However, adding this to my crate does nothing.
I have then tried to clone this crate and build it directly.
This causes the same error.
However compilation is successfull after adding the crate attribute to the top of uart_16550's lib.rs.
Is this an error on my end?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.