-
Notifications
You must be signed in to change notification settings - Fork 139
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 interrupt driven UARTE (open for feedback, do not merge yet) #102
Open
korken89
wants to merge
47
commits into
nrf-rs:master
Choose a base branch
from
korken89:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7233780
Added interrupt driven UARTE
korken89 dce32c3
Updated heapless dep, added missing exports
korken89 4fcd3bf
transmit queue generic over size S
42e2039
DMA_SIZE now parametrised
perlindgren c64c41d
uarte interrupt example from https://github.com/korken89/rtfm_worksho…
jacobrosenthal afda33b
add missing .cargo for rtfm-uarte-interrupts example
jacobrosenthal ccc77d6
default build target
jacobrosenthal 3eb1cae
fix to original example
jacobrosenthal 65f56b2
Use release RTFM version
korken89 9e21101
Added plumbing for timeout Timer in UARTE
korken89 552035a
Fixed so there is an extra way to enable the timers interrupts
korken89 ad0d255
Timeout almost done, need to handle non full packets being read
korken89 7ea8d88
Now working with sizes of packets added
korken89 d36946e
Added check for 0 sized chunks being sent
korken89 8593b58
Cleanup of chunk check
korken89 4229a18
Handle DMA pool inside the driver
korken89 cdea379
Updated timeout to 10 ms
korken89 a7d470a
Renaming to better describing names
korken89 902f322
Updated UARTE interrupt example
korken89 3d5112b
Cleanup of UARTE interrupt example, added timeout handling
korken89 3991477
Added commented pin definitions for DWM1001 dev board
korken89 7c8285b
Changed the Node struct to use MaybeUninit, added documentation
korken89 dcc8a73
Cleared out panics, replaced with debug_assert, added Debug impl
korken89 705eeee
Fixed miss in merge
korken89 dea2e73
Small renaming for easier readability
korken89 8c76072
Removed POOL flag
korken89 5dd0147
All interrupt driven code in its own module, this should fix nRF9160 …
korken89 f84e5ec
few more fixes
jacobrosenthal 759f676
Implemented fmt::write for UarteDMAPoolNode
korken89 b243ac5
split renamed to into_interrupt_driven to convey meaning
korken89 9c9fbb2
Fixed UarteDMAPoolNode::max_len()
korken89 5dd16d6
Fixed pub for max_len
korken89 63a5806
Testing a direct write interface
korken89 c7daa97
Added transmission status to help in event based systems to load the …
korken89 949bd38
Fix spelling error
korken89 9b51304
Updated uarte example with write!
korken89 4882755
More clear example
korken89 07ee0b1
Updated heapless for armv8 support
korken89 73f7292
Now using the optional NVIC API for enabling interrupts
korken89 9dee224
Fixed use of write_slice
korken89 cac02d3
Fix for nrf9160
korken89 09a98a0
Minor update if uninit initialization
korken89 bf1733c
Added size check in write_str
korken89 3bf3ecd
Documentation update
korken89 90c0861
Merge branch 'master' into master
korken89 bd650ba
Merge remote-tracking branch 'upstream/master'
korken89 f46e00c
Merge branch 'master' into master
korken89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ authors = ["James Munns <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
cortex-m-rtfm = "0.4.3" | ||
cortex-m-rtfm = "0.4" | ||
panic-semihosting = "0.5.1" | ||
cortex-m-semihosting = "0.3.3" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[target.thumbv7em-none-eabihf] | ||
runner = "arm-none-eabi-gdb -tui" | ||
|
||
[build] | ||
target = "thumbv7em-none-eabihf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set remotetimeout 60000 | ||
target remote :2331 | ||
set arm force-mode thumb | ||
|
||
# Uncomment to enable semihosting, when necessary | ||
monitor semihosting enable | ||
|
||
layout split | ||
monitor reset | ||
load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[package] | ||
name = "rtfm-uarte-interrupts" | ||
version = "0.1.0" | ||
authors = ["Per Lindgren <[email protected]>", | ||
"Emil Fresk <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
cortex-m-rtfm = "0.4" | ||
panic-semihosting = "0.5.1" | ||
cortex-m-semihosting = "0.3.3" | ||
heapless = ">= 0.5.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
|
||
[dependencies.nrf52810-hal] | ||
version = "0.8.0" | ||
path = "../../nrf52810-hal" | ||
optional = true | ||
features = ["UARTE_DMA_SIZE_16"] | ||
|
||
[dependencies.nrf52832-hal] | ||
version = "0.8.0" | ||
path = "../../nrf52832-hal" | ||
optional = true | ||
features = ["xxAB-package", "UARTE_DMA_SIZE_16"] | ||
|
||
[dependencies.nrf52840-hal] | ||
version = "0.8.0" | ||
path = "../../nrf52840-hal" | ||
optional = true | ||
features = ["UARTE_DMA_SIZE_16"] | ||
|
||
[features] | ||
52810 = ["nrf52810-hal"] | ||
52832 = ["nrf52832-hal"] | ||
52840 = ["nrf52840-hal"] | ||
default = ["52832"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
// panic handler | ||
extern crate panic_semihosting; | ||
|
||
use cortex_m_semihosting::hprintln; | ||
|
||
#[cfg(feature = "52810")] | ||
use nrf52810_hal as hal; | ||
|
||
#[cfg(feature = "52832")] | ||
use nrf52832_hal as hal; | ||
|
||
#[cfg(feature = "52840")] | ||
use nrf52840_hal as hal; | ||
|
||
use hal::gpio::{p0, Level}; | ||
use hal::target::{interrupt, TIMER0 as TIM0, UARTE0}; | ||
use hal::timer::*; | ||
use hal::{ | ||
uarte::{ | ||
self, | ||
interrupt_driven::{RXError, UarteDMAPool, UarteDMAPoolNode, UarteRX, UarteTX}, | ||
}, | ||
Uarte, | ||
}; | ||
|
||
use heapless::{ | ||
consts, | ||
pool::singleton::Box, | ||
spsc::{Producer, Queue}, | ||
}; | ||
|
||
// Needed for the write! example code | ||
// use core::fmt::Write; | ||
// use heapless::pool::singleton::Pool; | ||
|
||
use rtfm::app; | ||
|
||
const NR_PACKAGES: usize = 10; | ||
const DMA_MEM: usize = core::mem::size_of::<UarteDMAPoolNode>() * NR_PACKAGES; | ||
|
||
// Using power-of-2 constants is faster (see the crate heapless for details) | ||
type TXQSize = consts::U4; | ||
|
||
#[app(device = crate::hal::target)] | ||
const APP: () = { | ||
static mut RX: UarteRX<UARTE0, TIM0> = (); | ||
static mut TX: UarteTX<UARTE0, TXQSize> = (); | ||
static mut PRODUCER: Producer<'static, Box<UarteDMAPool>, TXQSize> = (); | ||
|
||
#[init(spawn = [])] | ||
fn init() -> init::LateResources { | ||
// for the actual DMA buffers | ||
static mut MEMORY: [u8; DMA_MEM] = [0; DMA_MEM]; | ||
// for the producer/consumer of TX | ||
static mut TX_RB: Queue<Box<UarteDMAPool>, TXQSize> = Queue(heapless::i::Queue::new()); | ||
|
||
hprintln!("init").unwrap(); | ||
|
||
let port0 = p0::Parts::new(device.P0); | ||
|
||
let uarte0 = Uarte::new( | ||
device.UARTE0, | ||
uarte::Pins { | ||
// adafruit-nrf52-bluefruit-le, adafruit_nrf52pro, nRF52-DK, nRF52840-DK | ||
txd: port0.p0_06.into_push_pull_output(Level::High).degrade(), | ||
rxd: port0.p0_08.into_floating_input().degrade(), | ||
// Use the following for DWM-1001 dev board | ||
// txd: port0.p0_05.into_push_pull_output(Level::High).degrade(), | ||
// rxd: port0.p0_11.into_floating_input().degrade(), | ||
cts: None, | ||
rts: None, | ||
}, | ||
uarte::Parity::EXCLUDED, | ||
uarte::Baudrate::BAUD115200, | ||
); | ||
|
||
let timer = Timer::new(device.TIMER0); | ||
let (txp, txc) = TX_RB.split(); | ||
let (rx, tx) = uarte0.into_interrupt_driven(txc, timer, MEMORY); | ||
|
||
init::LateResources { | ||
RX: rx, | ||
TX: tx, | ||
PRODUCER: txp, | ||
} | ||
} | ||
|
||
// // we can get Box<P> us being now the owner | ||
#[task(capacity = 2, resources = [PRODUCER])] | ||
fn printer(data: Box<UarteDMAPool>) { | ||
// enqueue a test message | ||
// let mut node = UarteDMAPool::alloc().unwrap().init(UarteDMAPoolNode::new()); | ||
// write!(&mut node, "test").unwrap(); // Using the write! trait | ||
// node.write_slice(&b"test"[..]); // Using raw slice writing | ||
// resources.PRODUCER.enqueue(node).unwrap(); | ||
// hprintln!("{:?}", &data).unwrap(); | ||
|
||
// Echo the buffer back without any changes or copying | ||
resources.PRODUCER.enqueue(data).unwrap(); | ||
rtfm::pend(interrupt::UARTE0_UART0); | ||
} | ||
|
||
#[task] | ||
fn rx_error(err: RXError) { | ||
hprintln!("rx_error {:?}", err).unwrap(); | ||
} | ||
|
||
#[interrupt(priority = 2, resources = [RX])] | ||
fn TIMER0() { | ||
resources.RX.process_timeout_interrupt(); | ||
} | ||
|
||
#[interrupt(priority = 2, resources = [RX, TX], spawn = [printer, rx_error])] | ||
fn UARTE0_UART0() { | ||
// probe RX | ||
match resources.RX.process_interrupt() { | ||
Ok(Some(b)) => { | ||
// delegate data to printer | ||
match spawn.printer(b) { | ||
Err(_) => spawn.rx_error(RXError::OOM).unwrap(), | ||
_ => (), | ||
}; | ||
} | ||
Ok(None) => (), // no | ||
Err(err) => spawn.rx_error(err).unwrap(), | ||
} | ||
|
||
resources.TX.process_interrupt(); | ||
} | ||
|
||
extern "C" { | ||
fn SWI1_EGU1(); | ||
fn SWI2_EGU2(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why make the version requirement less specific? I think it can be useful to see what the latest version was, when a dependency was added or last updated.
I also think being less specific can make breakage more likely in some scenarios, although this is unlikely to be the case here.