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
Johannes Sjölund
stm32f4-hal
Commits
0ba359bb
Commit
0ba359bb
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
first working blinky (hack)
parent
2bb50852
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
examples/blinky.rs
+45
-0
45 additions, 0 deletions
examples/blinky.rs
src/led.rs
+134
-0
134 additions, 0 deletions
src/led.rs
with
179 additions
and
0 deletions
examples/blinky.rs
0 → 100644
+
45
−
0
View file @
0ba359bb
//! Blinks an LED on the Nucleo 64
//! Led connected to PA5
#![deny(unsafe_code)]
//#![deny(warnings)]
#![no_std]
extern
crate
cortex_m
;
extern
crate
stm32f4x_hal
as
f4
;
use
f4
::
stm32f4x
;
// use f3::hal::delay::Delay;
use
f4
::
prelude
::
*
;
use
f4
::
led
::
Led
;
fn
wait
(
v
:
u32
)
{
for
_
in
0
..
v
{}
}
fn
main
()
{
let
cp
=
cortex_m
::
Peripherals
::
take
()
.unwrap
();
let
dp
=
stm32f4x
::
Peripherals
::
take
()
.unwrap
();
let
mut
flash
=
dp
.FLASH
.constrain
();
let
mut
rcc
=
dp
.RCC
.constrain
();
let
mut
gpioa
=
dp
.GPIOA
.split
(
&
mut
rcc
.ahb1
);
// // clock configuration using the default settings (all clocks run at 8 MHz)
// let clocks = rcc.cfgr.freeze(&mut flash.acr);
// // TRY this alternate clock configuration (all clocks run at 16 MHz)
// // let clocks = rcc.cfgr.sysclk(16.mhz()).freeze(&mut flash.acr);
let
mut
led
:
Led
=
gpioa
.pa5
.into_push_pull_output
(
&
mut
gpioa
.moder
,
&
mut
gpioa
.otyper
)
.into
();
// let mut delay = Delay::new(cp.SYST, clocks);
loop
{
led
.on
();
wait
(
10000
);
// delay.delay_ms(1_000_u16);
led
.off
();
wait
(
10000
);
// delay.delay_ms(1_000_u16);
}
}
This diff is collapsed.
Click to expand it.
src/led.rs
0 → 100644
+
134
−
0
View file @
0ba359bb
//! On-board user LEDs
use
core
::
ops
;
use
prelude
::
*
;
use
gpio
::
gpioa
::{
self
,
PA5
,
PAx
};
use
gpio
::{
Output
,
PushPull
};
/// LED
pub
type
LD1
=
PA5
<
Output
<
PushPull
>>
;
// /// Array of all the user LEDs on the board
// pub struct Leds {
// leds: [Led; 8],
// }
// impl Leds {
// /// Initializes all the user LEDs
// pub fn new(mut gpioa: gpioa::Parts) -> Self {
// let n = gpioe
// .pe9
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let ne = gpioe
// .pe10
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let e = gpioe
// .pe11
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let se = gpioe
// .pe12
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let s = gpioe
// .pe13
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let sw = gpioe
// .pe14
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let w = gpioe
// .pe15
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// let nw = gpioe
// .pe8
// .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// Leds {
// leds: [
// n.into(),
// ne.into(),
// e.into(),
// se.into(),
// s.into(),
// sw.into(),
// w.into(),
// nw.into(),
// ],
// }
// }
// }
// impl ops::Deref for Leds {
// type Target = [Led];
// fn deref(&self) -> &[Led] {
// &self.leds
// }
// }
// impl ops::DerefMut for Leds {
// fn deref_mut(&mut self) -> &mut [Led] {
// &mut self.leds
// }
// }
// impl ops::Index<usize> for Leds {
// type Output = Led;
// fn index(&self, i: usize) -> &Led {
// &self.leds[i]
// }
// }
// impl ops::Index<Direction> for Leds {
// type Output = Led;
// fn index(&self, d: Direction) -> &Led {
// &self.leds[d as usize]
// }
// }
// impl ops::IndexMut<usize> for Leds {
// fn index_mut(&mut self, i: usize) -> &mut Led {
// &mut self.leds[i]
// }
// }
// impl ops::IndexMut<Direction> for Leds {
// fn index_mut(&mut self, d: Direction) -> &mut Led {
// &mut self.leds[d as usize]
// }
// }
/// One of the on-board user LEDs
pub
struct
Led
{
pax
:
PAx
<
Output
<
PushPull
>>
,
}
macro_rules!
ctor
{
(
$
(
$ldx:ident
),
+
)
=>
{
$
(
impl
Into
<
Led
>
for
$ldx
{
fn
into
(
self
)
->
Led
{
Led
{
pax
:
self
.downgrade
(),
}
}
}
)
+
}
}
ctor!
(
LD1
);
impl
Led
{
/// Turns the LED off
pub
fn
off
(
&
mut
self
)
{
self
.pax
.set_low
()
}
/// Turns the LED on
pub
fn
on
(
&
mut
self
)
{
self
.pax
.set_high
()
}
}
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