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
77bdf590
Commit
77bdf590
authored
1 year ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Print hello world on serial port
parent
2799ea8e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+28
-2
28 additions, 2 deletions
src/main.rs
with
28 additions
and
2 deletions
src/main.rs
+
28
−
2
View file @
77bdf590
...
@@ -14,6 +14,7 @@ mod app {
...
@@ -14,6 +14,7 @@ mod app {
gpio
::{
Output
,
PinState
,
PB15
},
gpio
::{
Output
,
PinState
,
PB15
},
pac
,
pac
,
prelude
::
*
,
prelude
::
*
,
serial
::{
self
,
Serial
},
};
};
#[shared]
#[shared]
...
@@ -32,7 +33,11 @@ mod app {
...
@@ -32,7 +33,11 @@ mod app {
// Configure sysclk at 72MhZ, from HSI
// Configure sysclk at 72MhZ, from HSI
let
rcc
=
dp
.RCC
.constrain
();
let
rcc
=
dp
.RCC
.constrain
();
let
mut
flash
=
dp
.FLASH
.constrain
();
let
mut
flash
=
dp
.FLASH
.constrain
();
let
clocks
=
rcc
.cfgr
.sysclk
(
72
.MHz
())
.freeze
(
&
mut
flash
.acr
);
let
clocks
=
rcc
.cfgr
.use_hse
(
8
.MHz
())
.sysclk
(
72
.MHz
())
.freeze
(
&
mut
flash
.acr
);
let
systick_token
=
rtic_monotonics
::
create_systick_token!
();
let
systick_token
=
rtic_monotonics
::
create_systick_token!
();
Systick
::
start
(
cp
.SYST
,
72_000_000
,
systick_token
);
Systick
::
start
(
cp
.SYST
,
72_000_000
,
systick_token
);
...
@@ -65,6 +70,17 @@ mod app {
...
@@ -65,6 +70,17 @@ mod app {
);
);
calibrate_motors
::
spawn
(
motors
)
.ok
()
.unwrap
();
calibrate_motors
::
spawn
(
motors
)
.ok
()
.unwrap
();
let
tx
=
gpioa
.pa2
.into_alternate_push_pull
(
&
mut
gpioa
.crl
);
let
rx
=
gpioa
.pa3
;
let
mut
serial
=
Serial
::
new
(
dp
.USART2
,
(
tx
,
rx
),
&
mut
afio
.mapr
,
serial
::
Config
::
default
()
.baudrate
(
115200
.bps
()),
&
clocks
,
);
serial
.tx
.bwrite_all
(
b"Hello, world
\r\n
"
)
.unwrap
();
(
Shared
{},
Local
{})
(
Shared
{},
Local
{})
}
}
...
@@ -86,16 +102,26 @@ mod app {
...
@@ -86,16 +102,26 @@ mod app {
Systick
::
delay
(
1
.secs
())
.await
;
Systick
::
delay
(
1
.secs
())
.await
;
motors
.move_both
(
Movement
::
Stop
,
Movement
::
Stop
);
motors
.move_both
(
Movement
::
Stop
,
Movement
::
Stop
);
motors
.standby_leave
();
motors
.standby_leave
();
let
speed
=
(
max
/
10
)
as
i32
;
let
speed
=
(
max
/
2
)
as
i32
;
let
(
forward
,
backward
)
=
(
Movement
::
Advance
(
speed
),
Movement
::
Advance
(
-
speed
));
let
(
forward
,
backward
)
=
(
Movement
::
Advance
(
speed
),
Movement
::
Advance
(
-
speed
));
defmt
::
info!
(
"Left motor, forward 10%"
);
defmt
::
info!
(
"Left motor, forward 10%"
);
motors
.move_both
(
forward
,
Movement
::
Stop
);
motors
.move_both
(
forward
,
Movement
::
Stop
);
Systick
::
delay
(
1
.secs
())
.await
;
defmt
::
info!
(
"Left motor, backward 10%"
);
defmt
::
info!
(
"Left motor, backward 10%"
);
motors
.move_both
(
backward
,
Movement
::
Stop
);
motors
.move_both
(
backward
,
Movement
::
Stop
);
Systick
::
delay
(
1
.secs
())
.await
;
defmt
::
info!
(
"Right motor, forward 10%"
);
defmt
::
info!
(
"Right motor, forward 10%"
);
motors
.move_both
(
Movement
::
Stop
,
forward
);
motors
.move_both
(
Movement
::
Stop
,
forward
);
Systick
::
delay
(
1
.secs
())
.await
;
defmt
::
info!
(
"Right motor, backward 10%"
);
defmt
::
info!
(
"Right motor, backward 10%"
);
motors
.move_both
(
Movement
::
Stop
,
backward
);
motors
.move_both
(
Movement
::
Stop
,
backward
);
Systick
::
delay
(
1
.secs
())
.await
;
for
i
in
0
..
100
{
let
val
=
max
as
i32
*
i
as
i32
/
100
;
motors
.move_both
(
Movement
::
Advance
(
val
),
Movement
::
Advance
(
val
));
Systick
::
delay
(
30
.millis
())
.await
;
}
motors
.move_both
(
Movement
::
Brake
,
Movement
::
Brake
);
defmt
::
info!
(
"Returning to standby mode"
);
defmt
::
info!
(
"Returning to standby mode"
);
motors
.standby_enter
();
motors
.standby_enter
();
}
}
...
...
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