Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2019
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
Henrik Theolin
e7020e_2019
Commits
2eaa561a
Commit
2eaa561a
authored
6 years ago
by
Henrik Theolin
Browse files
Options
Downloads
Patches
Plain Diff
bare10_3
parent
b6b85d3d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare10.rs
+95
-13
95 additions, 13 deletions
examples/bare10.rs
with
95 additions
and
13 deletions
examples/bare10.rs
+
95
−
13
View file @
2eaa561a
...
@@ -14,10 +14,10 @@ use cortex_m::{asm, iprintln};
...
@@ -14,10 +14,10 @@ use cortex_m::{asm, iprintln};
extern
crate
stm32f4xx_hal
as
hal
;
extern
crate
stm32f4xx_hal
as
hal
;
use
crate
::
hal
::
prelude
::
*
;
use
crate
::
hal
::
prelude
::
*
;
use
crate
::
hal
::
serial
::{
config
::
Config
,
Event
,
Rx
,
Serial
,
Tx
};
use
crate
::
hal
::
serial
::{
config
::
Config
,
Event
,
Rx
,
Serial
,
Tx
};
use
hal
::
stm32
::
ITM
;
use
hal
::
stm32
::
{
ITM
}
;
use
hal
::
gpio
::{
PushPull
,
Output
,
gpioa
::
PA5
};
use
nb
::
block
;
use
nb
::
block
;
use
rtfm
::
app
;
use
rtfm
::
{
app
,
Instant
}
;
// Our error type
// Our error type
#[derive(Debug)]
#[derive(Debug)]
...
@@ -33,9 +33,11 @@ const APP: () = {
...
@@ -33,9 +33,11 @@ const APP: () = {
static
mut
TX
:
Tx
<
hal
::
stm32
::
USART2
>
=
();
static
mut
TX
:
Tx
<
hal
::
stm32
::
USART2
>
=
();
static
mut
RX
:
Rx
<
hal
::
stm32
::
USART2
>
=
();
static
mut
RX
:
Rx
<
hal
::
stm32
::
USART2
>
=
();
static
mut
ITM
:
ITM
=
();
static
mut
ITM
:
ITM
=
();
static
mut
TIMEOFFSET
:
u32
=
1
;
static
mut
PA5
:
PA5
<
Output
<
PushPull
>>
=
();
static
mut
IS_ON
:
bool
=
true
;
// init runs in an interrupt free section>
// init runs in an interrupt free section>
#[init]
#[init
(schedule
=
[
on]
)
]
fn
init
()
{
fn
init
()
{
let
stim
=
&
mut
core
.ITM.stim
[
0
];
let
stim
=
&
mut
core
.ITM.stim
[
0
];
iprintln!
(
stim
,
"bare10"
);
iprintln!
(
stim
,
"bare10"
);
...
@@ -49,6 +51,7 @@ const APP: () = {
...
@@ -49,6 +51,7 @@ const APP: () = {
let
tx
=
gpioa
.pa2
.into_alternate_af7
();
let
tx
=
gpioa
.pa2
.into_alternate_af7
();
let
rx
=
gpioa
.pa3
.into_alternate_af7
();
// try comment out
let
rx
=
gpioa
.pa3
.into_alternate_af7
();
// try comment out
let
pa5out
=
gpioa
.pa5
.into_push_pull_output
();
let
mut
serial
=
Serial
::
usart2
(
let
mut
serial
=
Serial
::
usart2
(
device
.USART2
,
device
.USART2
,
...
@@ -63,16 +66,19 @@ const APP: () = {
...
@@ -63,16 +66,19 @@ const APP: () = {
// Separate out the sender and receiver of the serial port
// Separate out the sender and receiver of the serial port
let
(
tx
,
rx
)
=
serial
.split
();
let
(
tx
,
rx
)
=
serial
.split
();
schedule
.on
(
Instant
::
now
()
+
8_000_000
.cycles
())
.unwrap
();
// Our split serial
// Our split serial
TX
=
tx
;
TX
=
tx
;
RX
=
rx
;
RX
=
rx
;
PA5
=
pa5out
;
// For debugging
// For debugging
ITM
=
core
.ITM
;
ITM
=
core
.ITM
;
}
}
// idle may be interrupted by other interrupt/tasks in the system
// idle may be interrupted by other interrupt/tasks in the system
#[idle]
#[idle
(resources
=
[
ITM]
)
]
fn
idle
()
->
!
{
fn
idle
()
->
!
{
loop
{
loop
{
asm
::
wfi
();
asm
::
wfi
();
...
@@ -83,9 +89,9 @@ const APP: () = {
...
@@ -83,9 +89,9 @@ const APP: () = {
fn
trace_data
(
byte
:
u8
)
{
fn
trace_data
(
byte
:
u8
)
{
let
stim
=
&
mut
resources
.ITM.stim
[
0
];
let
stim
=
&
mut
resources
.ITM.stim
[
0
];
iprintln!
(
stim
,
"data {}"
,
byte
);
iprintln!
(
stim
,
"data {}"
,
byte
);
for
_
in
0
..
10000
{
//
for _ in 0..10000 {
asm
::
nop
();
//
asm::nop();
}
//
}
}
}
#[task(priority
=
1
,
resources
=
[
ITM]
)]
#[task(priority
=
1
,
resources
=
[
ITM]
)]
...
@@ -94,6 +100,82 @@ const APP: () = {
...
@@ -94,6 +100,82 @@ const APP: () = {
iprintln!
(
stim
,
"{:?}"
,
error
);
iprintln!
(
stim
,
"{:?}"
,
error
);
}
}
#[task(priority
=
1
,
capacity
=
10
,
resources
=
[
ITM]
,
spawn
=
[
on
,
off
,
set_frequency
])]
fn
line_interpretor
(
byte
:
u8
)
{
static
mut
B
:
[
u8
;
10
]
=
[
0u8
;
10
];
static
mut
ITERATOR
:
usize
=
0
;
static
mut
IS_SET
:
bool
=
false
;
B
[
*
ITERATOR
]
=
byte
;
if
*
ITERATOR
<
B
.len
()
-
1
{
*
ITERATOR
+=
1
;
}
else
{
B
.iter_mut
()
.for_each
(|
x
|
*
x
=
0
);
*
ITERATOR
=
0
;
}
if
B
.starts_with
(
&
[
'o'
as
u8
,
'n'
as
u8
,
13
])
||
B
.starts_with
(
&
[
'o'
as
u8
,
'n'
as
u8
,
10
])
{
spawn
.on
()
.unwrap
();
B
.iter_mut
()
.for_each
(|
x
|
*
x
=
0
);
*
ITERATOR
=
0
;
}
else
if
B
.starts_with
(
&
[
'o'
as
u8
,
'f'
as
u8
,
'f'
as
u8
,
13
])
||
B
.starts_with
(
&
[
'o'
as
u8
,
'f'
as
u8
,
'f'
as
u8
,
10
])
{
spawn
.off
()
.unwrap
();
B
.iter_mut
()
.for_each
(|
x
|
*
x
=
0
);
*
ITERATOR
=
0
;
}
else
if
B
.starts_with
(
&
[
's'
as
u8
,
'e'
as
u8
,
't'
as
u8
,
' '
as
u8
])
{
*
IS_SET
=
true
;
}
if
B
.contains
(
&
13
)
||
B
.contains
(
&
10
)
{
if
*
IS_SET
{
let
mut
value
:
u32
=
0
;
for
i2
in
&
B
[
4
..*
ITERATOR
-
1
]
{
if
i2
.is_ascii_digit
()
{
value
=
value
*
10
;
value
=
value
+
(
u32
::
from
(
*
i2
-
48
));
}
if
value
!=
0
{
spawn
.set_frequency
(
value
)
.unwrap
();
}
}
*
IS_SET
=
false
;
}
B
.iter_mut
()
.for_each
(|
x
|
*
x
=
0
);
*
ITERATOR
=
0
;
}
}
#[task(priority
=
4
,
schedule
=
[
on]
,
resources
=
[
PA5
,
TIMEOFFSET
,
IS_ON
])]
fn
on
()
{
static
mut
TOGGLE
:
bool
=
false
;
if
*
TOGGLE
{
resources
.PA5
.set_high
();
}
else
{
resources
.PA5
.set_low
();
}
*
TOGGLE
=
!*
TOGGLE
;
if
*
resources
.IS_ON
{
schedule
.on
(
Instant
::
now
()
+
(
8_000_000
/
*
resources
.TIMEOFFSET
)
.cycles
())
.unwrap
();
}
else
{
resources
.PA5
.set_low
();
*
TOGGLE
=
false
;
}
*
resources
.IS_ON
=
true
;
}
#[task(priority
=
4
,
schedule
=
[
on]
,
resources
=
[
PA5
,
IS_ON
,
TIMEOFFSET
],
spawn
=
[
set_frequency
])]
fn
off
()
{
*
resources
.IS_ON
=
false
;
}
#[task(priority
=
2
,
resources
=
[
TIMEOFFSET]
)]
fn
set_frequency
(
freq
:
u32
)
{
resources
.TIMEOFFSET
.lock
(|
timeoffset
|
{
*
timeoffset
=
freq
;
});
}
#[task(priority
=
2
,
resources
=
[
TX]
,
spawn
=
[
trace_error
])]
#[task(priority
=
2
,
resources
=
[
TX]
,
spawn
=
[
trace_error
])]
fn
echo
(
byte
:
u8
)
{
fn
echo
(
byte
:
u8
)
{
let
tx
=
resources
.TX
;
let
tx
=
resources
.TX
;
...
@@ -101,17 +183,16 @@ const APP: () = {
...
@@ -101,17 +183,16 @@ const APP: () = {
if
block!
(
tx
.write
(
byte
))
.is_err
()
{
if
block!
(
tx
.write
(
byte
))
.is_err
()
{
let
_
=
spawn
.trace_error
(
Error
::
UsartSendOverflow
);
let
_
=
spawn
.trace_error
(
Error
::
UsartSendOverflow
);
}
}
}
}
#[interrupt(priority
=
3
,
resources
=
[
RX]
,
spawn
=
[
trace_data
,
trace_error
,
echo
])]
#[interrupt(priority
=
3
,
resources
=
[
RX]
,
spawn
=
[
line_interpretor
,
trace_error
,
echo
])]
fn
USART2
()
{
fn
USART2
()
{
let
rx
=
resources
.RX
;
let
rx
=
resources
.RX
;
match
rx
.read
()
{
match
rx
.read
()
{
Ok
(
byte
)
=>
{
Ok
(
byte
)
=>
{
let
_
=
spawn
.echo
(
byte
);
let
_
=
spawn
.echo
(
byte
);
if
spawn
.
trace_data
(
byte
)
.is_err
()
{
if
spawn
.
line_interpretor
(
byte
)
.is_err
()
{
let
_
=
spawn
.trace_error
(
Error
::
RingBufferOverflow
);
let
_
=
spawn
.trace_error
(
Error
::
RingBufferOverflow
);
}
}
}
}
...
@@ -126,6 +207,7 @@ const APP: () = {
...
@@ -126,6 +207,7 @@ const APP: () = {
extern
"C"
{
extern
"C"
{
fn
EXTI0
();
fn
EXTI0
();
fn
EXTI1
();
fn
EXTI1
();
fn
EXTI2
();
}
}
};
};
...
...
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