jkristell / nucleo-f401re

Rust BSP crate for the STM Nucleo-F401RE development board
BSD Zero Clause License
24 stars 10 forks source link

add UART for host communication? #20

Open rursprung opened 2 years ago

rursprung commented 2 years ago

the board has a UART connection via USB which can e.g. be used to send messages to the host (if it's connected via USB, of course).

it might make sense to offer this in this crate? the function would then have to do something like this:

        let gpioa = dp.GPIOA.split();
        let tx_pin = gpioa.pa2.into_alternate();
        let mut tx = dp
            .USART2
            .tx(
                tx_pin,
                Config::default()
                    .baudrate(115200.bps()) // would probably have to be configurable
                    .wordlength_8()
                    .parity_none(),
                &clocks,
            )
            .unwrap();

note that the example code is only for the TX pin (to send information to the host), RX should be set up in a similar way.

this can then e.g. be used as a simple logging functionality (though using something like defmt in combination with e.g. probe-run makes more sense in most cases):

writeln!(tx, "hello world!").unwrap();

using PuTTY (listening on the correct COM port) you can then read the messages being sent there.

jkristell commented 1 year ago

Hi

Yes that make total sense. A thought about adding it earlier, but as you write, rtt and defmt make more sense in most cases, but the functionality is there anyway so why not add it? Feel free to send a pull request!

rursprung commented 1 year ago

Feel free to send a pull request!

i won't be doing this any time soon - if at all - as i'm currently not using the crate (i stumbled over it by chance, but decided not to use it as my use-case is not actually bound to this board, so i'm better off using more generic crates to avoid unnecessary dependencies) and don't have time right now. just thought that i'd place the idea here so that it isn't forgotten - maybe it'll be useful to somebody else who'll use this crate.

huntr3ss commented 1 year ago

@rursprung Do you have links to other crates which have realized this feature. This would help a future developer (maybe myself) to realize this feature.

rursprung commented 1 year ago

Do you have links to other crates which have realized this feature.

i'm afraid not - but i haven't look at a lot of BSP crates yet (i'm still relatively new to the embedded world with rust (and in general)).