Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
app
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
app
Commits
8716f3f4
Commit
8716f3f4
authored
Feb 25, 2019
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
usb (pin setup, hal improved)
parent
4af85868
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/usb.rs
+42
-15
42 additions, 15 deletions
examples/usb.rs
with
42 additions
and
15 deletions
examples/usb.rs
+
42
−
15
View file @
8716f3f4
...
...
@@ -36,10 +36,10 @@ fn main() -> ! {
let
p
=
hal
::
stm32
::
Peripherals
::
take
()
.unwrap
();
// enable
usb
// enable
USB
p
.RCC.ahb2enr
.modify
(|
_
,
w
|
w
.otgfsen
()
.set_bit
());
// reset
usb
// reset
USB
p
.RCC.ahb2rstr
.modify
(|
_
,
w
|
w
.otgfsrst
()
.set_bit
());
p
.RCC.ahb2rstr
.modify
(|
_
,
w
|
w
.otgfsrst
()
.clear_bit
());
...
...
@@ -47,28 +47,37 @@ fn main() -> ! {
let
gpiod
=
p
.GPIOD
.split
();
// enables clock to gpio d
// for the
usb connect
// for the
USB FS Detection
let
gpiog
=
p
.GPIOG
.split
();
// enables cloc to gpio g
let
mut
usb_connect
=
gpiog
.pg6
.into_push_pull_output
();
let
mut
usb_fs
=
gpiog
.pg6
.into_push_pull_output
();
usb_fs
.set_high
();
//let mut usb_fs = gpiog.pg6.into_input().internal_pull_up(true);
//usb_fs.set_high();
// for the usb D+/D-, page 68 data sheet
// USB Pin Setup
// PA8,..PA12, page 68 data sheet
let
gpioa
=
p
.GPIOA
.split
();
// enables clock to gpio a
let
mut
pa12
=
gpioa
.pa12
.into_alternate_af10
()
.set_speed
(
stm32f4xx_hal
::
gpio
::
Speed
::
VeryHigh
)
.internal_pull_up
(
false
);
// api broken, false implies 00 neither pull up/pull down
// Notice, API broken, internal_pull_up(false) implies 00 neither pull no pull down
let
mut
pa9
=
gpioa
.pa9
.into_analog
();
// USB_FS_VBUS input
let
mut
pa8
=
gpioa
.pa8
.into_alternate_af10
();
// USB_FS_SOF
let
mut
pa10
=
gpioa
.pa10
.into_alternate_af10
();
// USB_FS_ID
let
mut
pa11
=
gpioa
.pa11
.into_alternate_af10
()
.set_speed
(
stm32f4xx_hal
::
gpio
::
Speed
::
VeryHigh
)
.internal_pull_up
(
false
);
// api broken, false implies 00 neither pull up/pull down
.internal_pull_up
(
false
);
// USB_FS_DM
let
mut
pa12
=
gpioa
.pa12
.into_alternate_af10
()
.set_speed
(
stm32f4xx_hal
::
gpio
::
Speed
::
VeryHigh
)
.internal_pull_up
(
false
);
// USB_FS_DP
let
clocks
=
rcc
.cfgr
.use_hse
(
8
.mhz
())
.sysclk
(
96
.mhz
())
// to itm
.sysclk
(
96
.mhz
())
// to
core/
itm
.pclk1
(
48
.mhz
())
.pclk2
(
96
.mhz
())
.use_usb
()
...
...
@@ -76,6 +85,22 @@ fn main() -> ! {
iprintln!
(
stim
,
"after freeze"
);
// Setup sequence according to 33.6.1
// Glabal interrupt
// p.OTG_FS_GLOBAL
// .fs_gahbcfg
// .modify(|_, w| w.gint().set_bit().txfelvl().set_bit());
// glabal interrupt enable
p
.OTG_FS_GLOBAL.fs_gahbcfg
.modify
(|
_
,
w
|
w
.gint
()
.set_bit
());
// otgp->PCGCCTL = 0;
p
.OTG_FS_PWRCLK.fs_pcgcctl
.write
(|
w
|
unsafe
{
w
.bits
(
0
)
});
// otgp->GOTGCTL = GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL;
// // p.OTG_FS_GLOBAL.fs_gintsts.modify(|_,w| w.gint().set_bit());
// was not possible to understand, follow chibi
//
// /* - Forced device mode.
// - USB turn-around time = TRDT_VALUE_FS.
// - Full Speed 1.1 PHY.*/
...
...
@@ -92,10 +117,12 @@ fn main() -> ! {
// otgp->DCFG = 0x02200000 | DCFG_DSPD_FS11;
// $6 = 0x0220 0003
// reset value + 3 = fs
// should have enum
p
.OTG_FS_DEVICE
.fs_dcfg
.write
(|
w
|
unsafe
{
w
.dspd
()
.bits
(
0b11
)
});
// Seral
let
tx
=
gpiod
.pd8
.into_alternate_af7
();
let
rx
=
gpiod
.pd9
.into_alternate_af7
();
...
...
@@ -110,9 +137,9 @@ fn main() -> ! {
// disconnect usb
// usb_connect.
iprintln!
(
stim
,
"before delay"
);
usb_connect
.set_low
(
);
p
.OTG_FS_DEVICE.fs_dctl
.modify
(|
_
,
w
|
w
.sdis
()
.clear_bit
()
);
cortex_m
::
asm
::
delay
(
clocks
.sysclk
()
.0
);
usb_connect
.set_high
(
);
p
.OTG_FS_DEVICE.fs_dctl
.modify
(|
_
,
w
|
w
.sdis
()
.set_bit
()
);
iprintln!
(
stim
,
"after delay"
);
// Separate out the sender and receiver of the serial port
...
...
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