#nrf52 #framing #serde #nordic #cobs #serial-port #send-receive

no-std nrf52-bin-logger

A binary protocol for UARTE logging on the nRF52

6 releases (3 breaking)

0.4.0 Oct 29, 2019
0.3.0 Apr 22, 2019
0.2.1 Apr 17, 2019
0.1.1 Apr 13, 2019

#1367 in Embedded development

MIT/Apache

24KB
346 lines

nrf52-bin-logger

A binary protocol for UARTE logging on the nRF52

Only supports the nrf52832 right now.

Eventually I'll probably just make this an embedded-hal crate. Oops.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

nrf52-bin-logger

This is a handy way to change the nRF52 UART from a byte-stream oriented interface to a "Rust Struct" focused interface. Users can decide if they want to send, receive, or do both over the serial port.

Messages are serialized and deserialized using postcard + serde, and all messages are COBS encoded for framing. This can be used to quickly set up a uni- or bi-directional communications protocol over a serial port for the nRF52.

use serde::{Serialize, Deserialize};
use heapless::consts::*;
use nrf52_bin_logger::{Logger, senders::RealSender, receivers::RealReceiver};

#[derive(Serialize, Deserialize)]
enum MyProtocol {
    MsgA(u32),
    MsgB(f32),
    MsgC(bool),
}

type ModemLogger = Logger<
    // `MyProtocol` outgoing messages, 16 bytes used as a serialization buffer
    RealSender<MyProtocol, U16>,
    // `MyProtocol` incoming messages, 16 bytes used as a deserialization buffer,
    // a max of 8 `MyProtocol` messages can be enqueued
    RealReceiver<MyProtocol, U16, U8>,
>;

Don't need a sender or a receiver? Just replace the type with a NullSender/NullReceiver. No code will be generated for this half of the interface.

use serde::{Serialize, Deserialize};
use heapless::consts::*;
use nrf52_bin_logger::{Logger, senders::RealSender, receivers::NullReceiver};

#[derive(Serialize, Deserialize)]
enum MyProtocol {
    MsgA(u32),
    MsgB(f32),
    MsgC(bool),
}

type ModemLogger = Logger<
    // `MyProtocol` outgoing messages, 16 bytes used as a serialization buffer
    RealSender<MyProtocol, U16>,
    // Nothing will be received
    NullReceiver,
>;

Dependencies

~8MB
~210K SLoC