Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DC motor driver hat
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Software
DC motor driver hat
Commits
57c754fb
Commit
57c754fb
authored
8 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Use window watchdog
parent
4ba5a893
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controller/src/logic.rs
+28
-3
28 additions, 3 deletions
controller/src/logic.rs
controller/src/main.rs
+3
-2
3 additions, 2 deletions
controller/src/main.rs
with
31 additions
and
5 deletions
controller/src/logic.rs
+
28
−
3
View file @
57c754fb
...
...
@@ -3,8 +3,8 @@ use crate::{
tb6612fng
::{
Movement
,
Tb6612fng
},
};
use
core
::
sync
::
atomic
::{
AtomicU32
,
Ordering
};
use
embassy_stm32
::
time
::
hz
;
use
embassy_time
::{
Instant
,
Ti
m
er
};
use
embassy_stm32
::
{
pac
::{
self
,
wwdg
::
vals
::
Wdgtb
},
peripherals
::
WWDG
,
time
::
hz
}
;
use
embassy_time
::{
Duration
,
Instant
,
Ti
ck
er
};
use
heapless
::
Deque
;
use
i2c2_target
::{
I2C2
,
MESSAGE_SIZE
};
...
...
@@ -94,19 +94,44 @@ fn current_millis() -> u32 {
Instant
::
now
()
.as_millis
()
as
u32
}
fn
wwdg_configure
()
{
// With PCLK1 at 36MHz, 63 as a timeout value with wdgtb at /8
// means 58.25ms. Comparing with a value of 31 means that at
// least 29.125ms must have passed before the watchdog can be
// petted.
pac
::
WWDG
.cfr
()
.write
(|
w
|
{
w
.set_wdgtb
(
Wdgtb
::
DIV8
);
w
.set_w
((
1
<<
6
)
|
31
);
});
wwdg_pet
();
}
fn
wwdg_pet
()
{
// Reset watchdog and start it if not started yet
pac
::
WWDG
.cr
()
.modify
(|
w
|
{
w
.set_t
((
1
<<
6
)
|
63
);
w
.set_wdga
(
true
);
});
}
#[allow(clippy::used_underscore_binding)]
// Clippy bug
#[embassy_executor::task]
pub
async
fn
start_i2c_target
(
i2c2
:
I2C2
,
mut
motors
:
Tb6612fng
<
'static
>
,
encoders
:
Encoders
<
'static
>
,
_wwdg
:
WWDG
,
)
{
motors
.standby_enter
();
unsafe
{
STATE
=
Some
(
State
::
new
(
i2c2
,
motors
,
encoders
));
STATE
.as_mut
()
.unwrap
()
.i2c
.start
(
&
i2c_callback
);
}
wwdg_configure
();
let
mut
ticker
=
Ticker
::
every
(
Duration
::
from_millis
(
50
));
loop
{
Timer
::
after_millis
(
100
)
.await
;
ticker
.next
()
.await
;
wwdg_pet
();
if
current_millis
()
>=
WATCHDOG_EXPIRATION
.load
(
Ordering
::
Relaxed
)
{
State
::
with_critical_section
(|
state
|
{
if
state
.is_moving
()
...
...
This diff is collapsed.
Click to expand it.
controller/src/main.rs
+
3
−
2
View file @
57c754fb
...
...
@@ -34,7 +34,7 @@ async fn main(spawner: Spawner) {
prediv
:
PllPreDiv
::
DIV1
,
mul
:
PllMul
::
MUL9
,
});
// APB1 speed is max 36MHz (SysClk/2)
// APB1 speed
(PCLK1)
is max 36MHz (SysClk/2)
, use that
config
.rcc.apb1_pre
=
APBPrescaler
::
DIV2
;
let
p
=
embassy_stm32
::
init
(
config
);
...
...
@@ -62,8 +62,9 @@ async fn main(spawner: Spawner) {
let
encoders
=
Encoders
::
new
(
p
.PA0
,
p
.PA1
,
p
.PA6
,
p
.PA7
,
p
.TIM2
,
p
.TIM3
);
let
i2c2
=
i2c2_target
::
I2C2
::
new
(
p
.I2C2
,
p
.PB10
,
p
.PB11
,
0x57
,
Priority
::
P3
);
spawner
.spawn
(
logic
::
start_i2c_target
(
i2c2
,
motors
,
encoders
))
.spawn
(
logic
::
start_i2c_target
(
i2c2
,
motors
,
encoders
,
p
.WWDG
))
.unwrap
();
}
...
...
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