Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
stm32f4-hal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
stm32f4-hal
Commits
377880ae
Commit
377880ae
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
with helper function
parent
0cbbfba1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dma.rs
+36
-42
36 additions, 42 deletions
src/dma.rs
src/serial.rs
+10
-4
10 additions, 4 deletions
src/serial.rs
with
46 additions
and
46 deletions
src/dma.rs
+
36
−
42
View file @
377880ae
...
@@ -67,11 +67,10 @@ pub trait DmaExt {
...
@@ -67,11 +67,10 @@ pub trait DmaExt {
fn
split
(
self
,
ahb
:
&
mut
AHB1
)
->
Self
::
Streams
;
fn
split
(
self
,
ahb
:
&
mut
AHB1
)
->
Self
::
Streams
;
}
}
//
// ndtr: u16, par: u32, m0: u32
pub
unsafe
trait
StartTransfer
{
pub
unsafe
trait
StartTransfer
{
fn
start_transfer
<
A
,
B
>
(
&
mut
self
,
B
)
fn
_start_transfer
(
&
mut
self
,
u16
,
u32
,
u32
);
where
A
:
Unsize
<
[
u8
]
>
,
B
:
Static
<
A
>
;
}
}
pub
struct
Transfer
<
MODE
,
BUFFER
,
STREAM
,
PAYLOAD
>
{
pub
struct
Transfer
<
MODE
,
BUFFER
,
STREAM
,
PAYLOAD
>
{
...
@@ -123,10 +122,14 @@ pub struct Output<MODE> {
...
@@ -123,10 +122,14 @@ pub struct Output<MODE> {
}
}
//
//
pub
unsafe
trait
UsartTxStream
<
USART
>
{}
pub
unsafe
trait
UsartTxStream
<
USART
>
{
fn
start_transfer
(
&
mut
self
,
ndtr
:
u16
,
par
:
u32
,
m0
:
u32
);
}
pub
unsafe
trait
UsartRxStream
<
USART
>
{}
pub
unsafe
trait
UsartRxStream
<
USART
>
{}
pub
mod
dma1
{
pub
mod
dma1
{
use
core
::
sync
::
atomic
::{
self
,
Ordering
};
use
core
::
marker
::{
PhantomData
,
Unsize
};
use
core
::
marker
::{
PhantomData
,
Unsize
};
use
cast
::
u16
;
use
cast
::
u16
;
...
@@ -191,7 +194,11 @@ pub mod dma1 {
...
@@ -191,7 +194,11 @@ pub mod dma1 {
}
}
}
}
unsafe
impl
super
::
UsartTxStream
<
USART2
>
for
S6
<
C4
>
{}
unsafe
impl
super
::
UsartTxStream
<
USART2
>
for
S6
<
C4
>
{
fn
start_transfer
(
&
mut
self
,
ndtr
:
u16
,
par
:
u32
,
m0
:
u32
)
{
start_transfer_s6_c4
(
ndtr
,
par
,
m0
);
}
}
unsafe
impl
super
::
UsartRxStream
<
USART2
>
for
S5
<
C4
>
{}
unsafe
impl
super
::
UsartRxStream
<
USART2
>
for
S5
<
C4
>
{}
unsafe
impl
super
::
UsartRxStream
<
USART2
>
for
S7
<
C6
>
{}
unsafe
impl
super
::
UsartRxStream
<
USART2
>
for
S7
<
C6
>
{}
...
@@ -208,33 +215,20 @@ pub mod dma1 {
...
@@ -208,33 +215,20 @@ pub mod dma1 {
}
}
}
}
unsafe
impl
super
::
StartTransfer
for
S6
<
C4
>
{
fn
start_transfer_s6_c4
(
ndtr
:
u16
,
par
:
u32
,
m0
:
u32
)
{
fn
start_transfer
<
A
,
B
>
(
&
mut
self
,
buffer
:
B
)
let
dma
=
unsafe
{
&*
DMA1
::
ptr
()
};
where
dma
.s6ndtr
.write
(|
w
|
unsafe
{
w
.ndt
()
.bits
(
ndtr
)
});
A
:
Unsize
<
[
u8
]
>
,
dma
.s6par
.write
(|
w
|
unsafe
{
w
.bits
(
par
)
});
B
:
super
::
Static
<
A
>
,
dma
.s6m0ar
.write
(|
w
|
unsafe
{
w
.bits
(
m0
)
});
{
dma
.s6cr
.modify
(|
_
,
w
|
w
.en
()
.set_bit
());
let
buf
:
&
[
u8
]
=
buffer
.borrow
();
unsafe
{
(
*
DMA1
::
ptr
())
.s6ndtr
.write
(|
w
|
unsafe
{
w
.ndt
()
.bits
(
u16
(
buf
.len
())
.unwrap
())
})
};
}
}
}
// hifcr high interrupt flag clear register
// hisr high interrupt status register
// lifcr low interrupt flag clear register
// lisr low interrupt status register
// impl<CHANNEL> S5<CHANNEL>
impl
DmaExt
for
DMA1
{
impl
DmaExt
for
DMA1
{
type
Streams
=
Streams
;
type
Streams
=
Streams
;
fn
split
(
self
,
ahb
:
&
mut
AHB1
)
->
Streams
{
fn
split
(
self
,
ahb1
:
&
mut
AHB1
)
->
Streams
{
// ahb.enr().modify(|_, w| w.$dmaXen().enabled());
//ahb.ahb1enr().modify(|_, w| w.dma1en().set_bit());
ahb1
.enr
()
.modify
(|
_
,
w
|
w
.dma1en
()
.set_bit
());
// // reset the DMA control registers (stops all on-going transfers)
// // reset the DMA control registers (stops all on-going transfers)
// $(
// $(
...
@@ -258,20 +252,20 @@ pub mod dma1 {
...
@@ -258,20 +252,20 @@ pub mod dma1 {
impl
<
BUFFER
,
PAYLOAD
,
MODE
>
Transfer
<
MODE
,
BUFFER
,
S6
<
C4
>
,
PAYLOAD
>
{
impl
<
BUFFER
,
PAYLOAD
,
MODE
>
Transfer
<
MODE
,
BUFFER
,
S6
<
C4
>
,
PAYLOAD
>
{
pub
fn
wait
(
mut
self
)
->
(
BUFFER
,
S6
<
C4
>
,
PAYLOAD
)
{
pub
fn
wait
(
mut
self
)
->
(
BUFFER
,
S6
<
C4
>
,
PAYLOAD
)
{
//
//
XXX should we check for transfer errors here?
// XXX should we check for transfer errors here?
//
//
The manual says "A DMA transfer error can be generated by reading
// The manual says "A DMA transfer error can be generated by reading
//
//
from or writing to a reserved address space". I think it's impossible
// from or writing to a reserved address space". I think it's impossible
//
//
to get to that state with our type safe API and *safe* Rust.
// to get to that state with our type safe API and *safe* Rust.
// while self.channel.isr().$tcifX().bit_is_clea
r()
{
}
let
dma
=
unsafe
{
&*
DMA1
::
pt
r
()
}
;
// self.channel.ifcr().write(|w| w.$cg
if
X
().
set_bit());
while
dma
.hisr
.read
()
.tc
if
6
()
.
bit_is_clear
()
{}
dma
.hifcr
.write
(|
w
|
w
.ctcif6
()
.set_bit
());
// self.channel.ccr()
.modify(|_, w| w.en().clear_bit());
dma
.s2cr
.modify
(|
_
,
w
|
w
.en
()
.clear_bit
());
//
//
TODO can we weaken this compiler barrier?
// TODO can we weaken this compiler barrier?
//
//
NOTE(compiler_fence) operations on `buffer` should not be reordered
// NOTE(compiler_fence) operations on `buffer` should not be reordered
//
//
before the previous statement, which marks the DMA transfer as done
// before the previous statement, which marks the DMA transfer as done
//
atomic::compiler_fence(Ordering::SeqCst);
atomic
::
compiler_fence
(
Ordering
::
SeqCst
);
(
self
.buffer
,
self
.stream
,
self
.payload
)
(
self
.buffer
,
self
.stream
,
self
.payload
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/serial.rs
+
10
−
4
View file @
377880ae
...
@@ -243,8 +243,8 @@ macro_rules! hal {
...
@@ -243,8 +243,8 @@ macro_rules! hal {
}
}
impl
Tx
<
$USARTX
>
{
impl
Tx
<
$USARTX
>
{
pub
fn
write_all
<
A
,
B
,
S
>
(
pub
fn
write_all
<
A
,
B
,
S
>
(
self
,
self
,
// should be mutable?
mut
stream
:
S
,
mut
tx_
stream
:
S
,
buffer
:
B
,
buffer
:
B
,
)
->
Transfer
<
R
,
B
,
S
,
Self
>
)
->
Transfer
<
R
,
B
,
S
,
Self
>
where
where
...
@@ -253,7 +253,13 @@ macro_rules! hal {
...
@@ -253,7 +253,13 @@ macro_rules! hal {
S
:
UsartTxStream
<
$USARTX
>
S
:
UsartTxStream
<
$USARTX
>
{
{
{
{
let
buffer1
:
&
[
u8
]
=
buffer
.borrow
();
let
buf
:
&
[
u8
]
=
buffer
.borrow
();
tx_stream
.start_transfer
(
u16
(
buf
.len
())
.unwrap
(),
unsafe
{
&
(
*
$USARTX
::
ptr
())
.dr
as
*
const
_
as
usize
as
u32
},
buf
.as_ptr
()
as
u32
);
// stream.ndtr()
// stream.ndtr()
// .write(|w| unsafe { w.ndt().bits(u16(buffer1.len()).unwrap()) });
// .write(|w| unsafe { w.ndt().bits(u16(buffer1.len()).unwrap()) });
// stream.par()
// stream.par()
...
@@ -302,7 +308,7 @@ macro_rules! hal {
...
@@ -302,7 +308,7 @@ macro_rules! hal {
// });
// });
}
}
Transfer
::
r
(
buffer
,
stream
,
self
)
Transfer
::
r
(
buffer
,
tx_
stream
,
self
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment