Skip to content

Commit

Permalink
Run everything through rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Jul 2, 2022
1 parent 33e369f commit 62cfa8d
Show file tree
Hide file tree
Showing 16 changed files with 425 additions and 405 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update `defmt-test` to `0.3.0`
- Update `panic-probe` to `0.3.0`


## [0.1.2] - 2021-12-01
### Added
- New Board method which takes a user-provided function to configure CCDR: `freeze_clocks_with()`


## [0.1.1] - 2021-04-01
### Changed
- Changed license to MIT
Expand Down
27 changes: 13 additions & 14 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![no_main]
#![no_std]

use panic_semihosting as _;
use cortex_m_rt::entry;
use panic_semihosting as _;

use nucleo_h7xx as nucleo;
use nucleo::hal::prelude::*;
use nucleo::led::Led;

use nucleo_h7xx as nucleo;

#[entry]
fn main() -> ! {
Expand All @@ -17,17 +16,17 @@ fn main() -> ! {

let dp = nucleo::pac::Peripherals::take().unwrap();

let ccdr = board.freeze_clocks(dp.PWR.constrain(),
dp.RCC.constrain(),
&dp.SYSCFG);

let pins = board.split_gpios(dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG));
let ccdr = board.freeze_clocks(dp.PWR.constrain(), dp.RCC.constrain(), &dp.SYSCFG);

let pins = board.split_gpios(
dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG),
);

let mut user_leds = nucleo::led::UserLeds::new(pins.user_leds);

Expand Down
12 changes: 7 additions & 5 deletions examples/blinky_hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use panic_semihosting as _;

use nucleo_h7xx::hal;
use hal::{pac, prelude::*};
use hal::rcc::PllConfigStrategy;
use hal::{pac, prelude::*};
use nucleo_h7xx::hal;

#[cortex_m_rt::entry]
fn main() -> ! {
Expand All @@ -15,9 +15,11 @@ fn main() -> ! {

let pwr = dp.PWR.constrain();
let pwrcfg = pwr.smps().vos0(&dp.SYSCFG).freeze();
let ccdr = dp.RCC.constrain()
.pll1_strategy(PllConfigStrategy::Iterative) // pll1 drives system clock
.sys_ck(480.MHz()) // system clock @ 480 MHz
let ccdr = dp
.RCC
.constrain()
.pll1_strategy(PllConfigStrategy::Iterative) // pll1 drives system clock
.sys_ck(480.MHz()) // system clock @ 480 MHz
.freeze(pwrcfg, &dp.SYSCFG);

// - pins -----------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions examples/blinky_pac.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![no_main]
#![no_std]

use panic_semihosting as _;
use cortex_m_rt::entry;
use panic_semihosting as _;

use nucleo_h7xx::hal::pac;


#[entry]
fn main() -> ! {
// - configuration --------------------------------------------------------
Expand All @@ -24,7 +23,6 @@ fn main() -> ! {
gpioe.pupdr.modify(|_, w| w.pupdr1().pull_up());
gpioe.ospeedr.modify(|_, w| w.ospeedr1().high_speed());


// - main loop ------------------------------------------------------------

loop {
Expand Down
43 changes: 19 additions & 24 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;

use panic_semihosting as _;
use cortex_m_rt::entry;
use panic_semihosting as _;

use nucleo_h7xx as nucleo;
use nucleo::led::Led;
use nucleo_h7xx as nucleo;

use nucleo::hal;
use hal::prelude::*;
use hal::gpio::ExtiPin;
use hal::interrupt;
use hal::prelude::*;
use nucleo::hal;

use nucleo::pac;


// - global static state ------------------------------------------------------

static USER_BUTTON: Mutex<RefCell<Option<hal::gpio::gpioc::PC13<hal::gpio::Input>>>> =
Mutex::new(RefCell::new(None));
static USER_LEDS: Mutex<RefCell<Option<nucleo::led::UserLeds>>> =
Mutex::new(RefCell::new(None));

static USER_LEDS: Mutex<RefCell<Option<nucleo::led::UserLeds>>> = Mutex::new(RefCell::new(None));

// - entry-point --------------------------------------------------------------

Expand All @@ -37,22 +34,21 @@ fn main() -> ! {
let mut cp = cortex_m::Peripherals::take().unwrap();
let mut dp = pac::Peripherals::take().unwrap();

let ccdr = board.freeze_clocks(dp.PWR.constrain(),
dp.RCC.constrain(),
&dp.SYSCFG);
let ccdr = board.freeze_clocks(dp.PWR.constrain(), dp.RCC.constrain(), &dp.SYSCFG);

let pins = board.split_gpios(dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG));
let pins = board.split_gpios(
dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG),
);

let mut user_button = pins.user_button.into_floating_input();
let user_leds = nucleo::led::UserLeds::new(pins.user_leds);


// - configure interrupts -------------------------------------------------

user_button.make_interrupt_source(&mut dp.SYSCFG);
Expand All @@ -69,7 +65,6 @@ fn main() -> ! {
cortex_m::peripheral::NVIC::unmask(interrupt::EXTI15_10);
}


// - main loop ------------------------------------------------------------

loop {
Expand All @@ -80,10 +75,10 @@ fn main() -> ! {
#[interrupt]
fn EXTI15_10() {
cortex_m::interrupt::free(|cs| {
if let (Some(user_button),
Some(user_leds)) = (USER_BUTTON.borrow(cs).borrow_mut().as_mut(),
USER_LEDS.borrow(cs).borrow_mut().as_mut()) {

if let (Some(user_button), Some(user_leds)) = (
USER_BUTTON.borrow(cs).borrow_mut().as_mut(),
USER_LEDS.borrow(cs).borrow_mut().as_mut(),
) {
user_button.clear_interrupt_pending_bit();

if user_button.is_high() {
Expand Down
86 changes: 44 additions & 42 deletions examples/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,35 @@
#![allow(unused_imports)]
#![allow(unused_parens)]
#![allow(unused_variables)]

#![no_main]
#![no_std]

use cortex_m_rt::entry;
use cortex_m;
use cortex_m_rt::entry;

use nucleo_h7xx as nucleo;
use nucleo::loggit;
use nucleo_h7xx as nucleo;

use nucleo::hal as hal;
use hal::prelude::*;
use hal::gpio::Speed::*;
use hal::hal::digital::v2::OutputPin;
use hal::hal::digital::v2::ToggleableOutputPin;
use hal::prelude::*;
use hal::rcc::CoreClocks;
use hal::{ethernet, ethernet::PHY};
use nucleo::hal;

use hal::pac;
use pac::interrupt;

use smoltcp;
use smoltcp::iface::{
Interface, InterfaceBuilder, Neighbor, NeighborCache,
Route, Routes,
};
use smoltcp::socket::{UdpSocket, UdpSocketBuffer, UdpPacketMetadata};
use smoltcp::iface::{Interface, InterfaceBuilder, Neighbor, NeighborCache, Route, Routes};
use smoltcp::socket::{UdpPacketMetadata, UdpSocket, UdpSocketBuffer};
use smoltcp::storage::PacketMetadata;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv6Cidr, IpEndpoint, Ipv4Address};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address, Ipv6Cidr};

use log::{debug, error, info};


/// Simple ethernet example that will respond to icmp pings on
/// `IP_LOCAL` and periodically send a udp packet to
/// `IP_REMOTE:IP_REMOTE_PORT`
Expand All @@ -45,22 +40,19 @@ use log::{debug, error, info};
/// nc -u -l 34254
const MAC_LOCAL: [u8; 6] = [0x02, 0x00, 0x11, 0x22, 0x33, 0x44];
const IP_LOCAL: [u8; 4] = [ 192, 168, 20, 99 ];
const IP_REMOTE: [u8; 4] = [ 192, 168, 20, 114 ];
const IP_LOCAL: [u8; 4] = [192, 168, 20, 99];
const IP_REMOTE: [u8; 4] = [192, 168, 20, 114];
const IP_REMOTE_PORT: u16 = 34254;

mod utilities;


#[entry]
fn main() -> ! {

// - endpoints ------------------------------------------------------------

let local_endpoint = IpEndpoint::new(Ipv4Address::from_bytes(&IP_LOCAL).into(), 1234);
let remote_endpoint = IpEndpoint::new(Ipv4Address::from_bytes(&IP_REMOTE).into(),
IP_REMOTE_PORT);

let remote_endpoint =
IpEndpoint::new(Ipv4Address::from_bytes(&IP_REMOTE).into(), IP_REMOTE_PORT);

// - board setup ----------------------------------------------------------

Expand All @@ -70,62 +62,68 @@ fn main() -> ! {

let dp = pac::Peripherals::take().unwrap();

let ccdr = board.freeze_clocks(dp.PWR.constrain(),
dp.RCC.constrain(),
&dp.SYSCFG);
let ccdr = board.freeze_clocks(dp.PWR.constrain(), dp.RCC.constrain(), &dp.SYSCFG);

let pins = board.split_gpios(dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG));
let pins = board.split_gpios(
dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG),
);

utilities::logger::init();


// - ethernet interface ---------------------------------------------------

info!("Bringing up ethernet interface");

let timeout_timer = dp.TIM17.timer(100.Hz(), ccdr.peripheral.TIM17, &ccdr.clocks);
let timeout_timer = dp
.TIM17
.timer(100.Hz(), ccdr.peripheral.TIM17, &ccdr.clocks);
let timeout_timer = nucleo::timer::CountDownTimer::new(timeout_timer);
let timeout_timer = match nucleo::ethernet::EthernetInterface::start(
pins.ethernet,
&MAC_LOCAL,
&IP_LOCAL,
ccdr.peripheral.ETH1MAC,
&ccdr.clocks,
timeout_timer
timeout_timer,
) {
Ok(tim17) => tim17,
Err(e) => {
error!("Failed to start ethernet interface: {:?}", e);
loop { }
loop {}
}
};

// wait for link to come up
info!("Waiting for link to come up");
nucleo::ethernet::EthernetInterface::interrupt_free(|ethernet_interface| {
while !ethernet_interface.poll_link() { }
});
nucleo::ethernet::EthernetInterface::interrupt_free(
|ethernet_interface| {
while !ethernet_interface.poll_link() {}
},
);

// create and bind socket
let socket_handle = nucleo::ethernet::EthernetInterface::interrupt_free(|ethernet_interface| {
let socket_handle = ethernet_interface.new_udp_socket();
let socket = ethernet_interface.interface.as_mut().unwrap().get_socket::<UdpSocket>(socket_handle);
let socket = ethernet_interface
.interface
.as_mut()
.unwrap()
.get_socket::<UdpSocket>(socket_handle);
match socket.bind(local_endpoint) {
Ok(()) => return socket_handle,
Err(e) => {
error!("Failed to bind socket to endpoint: {:?}", local_endpoint);
loop { }
loop {}
}
}
});


// - main loop ------------------------------------------------------------

info!("Entering main loop");
Expand All @@ -138,10 +136,10 @@ fn main() -> ! {
// poll ethernet interface
let now = nucleo::ethernet::EthernetInterface::interrupt_free(|ethernet_interface| {
match ethernet_interface.poll() {
Ok(result) => {}, // packets were processed or emitted
Ok(result) => {} // packets were processed or emitted
Err(smoltcp::Error::Exhausted) => (),
Err(smoltcp::Error::Unrecognized) => (),
Err(e) => debug!("ethernet::EthernetInterface.poll() -> {:?}", e)
Err(e) => debug!("ethernet::EthernetInterface.poll() -> {:?}", e),
}
ethernet_interface.now()
});
Expand All @@ -155,7 +153,11 @@ fn main() -> ! {

// send something
nucleo::ethernet::EthernetInterface::interrupt_free(|ethernet_interface| {
let socket = ethernet_interface.interface.as_mut().unwrap().get_socket::<UdpSocket>(socket_handle);
let socket = ethernet_interface
.interface
.as_mut()
.unwrap()
.get_socket::<UdpSocket>(socket_handle);
match socket.send_slice("nucleo says hello!\n".as_bytes(), remote_endpoint) {
Ok(()) => (),
Err(smoltcp::Error::Exhausted) => (),
Expand Down
Loading

0 comments on commit 62cfa8d

Please sign in to comment.