From 911d467672071b12968b1f18dbbc4f17f197ea8c Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 27 Apr 2018 13:21:50 +0200 Subject: [PATCH 1/4] Update to nightly-2018-04-27 --- Cargo.lock | 8 ++++---- Dockerfile | 2 +- src/lib.rs | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c9fa430..ff1db7ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cortex-m 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "linked_list_allocator 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "linked_list_allocator 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "linked_list_allocator" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -133,7 +133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "stb_truetype" version = "0.2.1" -source = "git+https://github.com/phil-opp/stb_truetype-rs.git#6d546c1b9c6c880d8e0eeca6a8592c50f66b91e0" +source = "git+https://github.com/phil-opp/stb_truetype-rs.git#beb75d81c74dd3fa42d31f2197cc4b696752dcfb" dependencies = [ "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -178,7 +178,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cortex-m 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "de9b334d0778b1ace2dfb63672594d0c0db093a3924617ad4e2f1669d32832dc" "checksum embedded 0.3.0 (git+https://github.com/embed-rs/embedded-rs.git)" = "" "checksum embedded_stm32f7 0.1.0 (git+https://github.com/embed-rs/embedded_stm32f7.git)" = "" -"checksum linked_list_allocator 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "925213be33864ccbee7c713930ff9f598b18029c5cc5b3764600826a08ece0d3" +"checksum linked_list_allocator 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1ee3eeeadfa301cf51b59684c034ad47a9796d03a8b70650d46b6b400a4a3258" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum odds 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "4eae0151b9dacf24fcc170d9995e511669a082856a91f958a2fe380bfab3fb22" diff --git a/Dockerfile b/Dockerfile index 92f43aa6..e4aaf4b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN set -ex; \ apt-get clean -q -y; \ rm -rf /var/lib/apt/lists/*; \ cd ..; \ - rustup default nightly-2018-04-19; \ + rustup default nightly-2018-04-27; \ rustup target add thumbv7em-none-eabihf; \ cd myapp; diff --git a/src/lib.rs b/src/lib.rs index ca29e490..4b734869 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,11 @@ pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: }) } +#[lang = "oom"] +fn oom() -> ! { + panic!("Out of memory!"); +} + use alloc_cortex_m::CortexMHeap; From c2819ebc6109217546c96514b723d0370973e436 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 27 Apr 2018 13:22:40 +0200 Subject: [PATCH 2/4] Run rustfmt --- src/audio.rs | 6 +- src/ethernet/init.rs | 8 +-- src/ethernet/mod.rs | 53 +++++++++----- src/ethernet/phy.rs | 2 +- src/ethernet/tx.rs | 5 +- src/exti.rs | 20 +++--- src/i2c.rs | 20 ++---- src/interrupts/mod.rs | 118 ++++---------------------------- src/interrupts/primask_mutex.rs | 1 - src/lcd/color.rs | 13 ++-- src/lcd/font.rs | 6 +- src/lcd/init.rs | 10 +-- src/lcd/mod.rs | 26 ++----- src/lcd/stdout.rs | 4 +- src/lib.rs | 25 +++---- src/main.rs | 63 ++++++++--------- src/random.rs | 14 +--- src/sd/error.rs | 18 ++--- src/sd/init.rs | 59 ++++++++-------- src/sd/mod.rs | 109 +++++++++++++++++------------ src/sd/sdmmc_cmd.rs | 59 ++++++++++------ src/sdram.rs | 48 ++----------- src/system_clock.rs | 5 +- src/touch.rs | 2 +- 24 files changed, 283 insertions(+), 411 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index feea1e2e..4e1e73a9 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -120,7 +120,6 @@ pub fn init_sai_2(sai: &mut Sai, rcc: &mut Rcc) { // Flush the fifo sai.bcr2.update(|r| r.set_fflus(true)); // fifo_flush - // PLL clock is set depending on the AudioFreq (44.1khz vs 48khz groups) // I2S clock config @@ -151,7 +150,6 @@ pub fn init_sai_2(sai: &mut Sai, rcc: &mut Rcc) { rcc.cr.update(|r| r.set_plli2son(true)); while !rcc.cr.read().plli2srdy() {} - // configure sai registers // disable synchronization outputs @@ -281,9 +279,9 @@ pub fn init_sai_2(sai: &mut Sai, rcc: &mut Rcc) { } pub fn init_sai_2_pins(gpio: &mut Gpio) { - use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; + use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; // block A (master) let sai2_fs_a = (PortI, Pin7); diff --git a/src/ethernet/init.rs b/src/ethernet/init.rs index cee900da..0e5049f2 100644 --- a/src/ethernet/init.rs +++ b/src/ethernet/init.rs @@ -1,10 +1,10 @@ -use board::rcc::Rcc; -use board::syscfg::Syscfg; +use super::phy; use board::ethernet_dma::EthernetDma; use board::ethernet_mac::EthernetMac; +use board::rcc::Rcc; +use board::syscfg::Syscfg; use embedded::interfaces::gpio::Gpio; use system_clock; -use super::phy; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Error { @@ -195,8 +195,8 @@ pub fn start(ethernet_mac: &mut EthernetMac, ethernet_dma: &mut EthernetDma) { } pub fn init_pins(gpio: &mut Gpio) { - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; // RMII pins diff --git a/src/ethernet/mod.rs b/src/ethernet/mod.rs index 3cff175f..2a46a850 100644 --- a/src/ethernet/mod.rs +++ b/src/ethernet/mod.rs @@ -1,17 +1,17 @@ -use core::fmt; use alloc::boxed::Box; use alloc::Vec; +use core::fmt; -use board::{rcc, syscfg}; use board::ethernet_dma::{self, EthernetDma}; use board::ethernet_mac::{self, EthernetMac}; +use board::{rcc, syscfg}; use embedded::interfaces::gpio; use volatile::Volatile; -use smoltcp::wire::{EthernetAddress, Ipv4Address, IpCidr, Ipv4Cidr}; -use smoltcp::phy::{Device, DeviceCapabilities}; use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder}; +use smoltcp::phy::{Device, DeviceCapabilities}; use smoltcp::time::Instant; +use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address, Ipv4Cidr}; mod init; mod phy; @@ -93,8 +93,8 @@ impl EthernetDevice { } pub fn into_interface<'a>(self, ip_address: Ipv4Address) -> EthernetInterface<'a, 'a, Self> { - use smoltcp::iface::NeighborCache; use alloc::BTreeMap; + use smoltcp::iface::NeighborCache; let neighbor_cache = NeighborCache::new(BTreeMap::new()); let ethernet_address = self.ethernet_address; @@ -118,15 +118,25 @@ impl<'a> Device<'a> for EthernetDevice { type TxToken = TxToken<'a>; fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { - if !self.rx.new_data_received() { return None } - let rx = RxToken { rx: &mut self.rx, }; - let tx = TxToken { tx: &mut self.tx, ethernet_dma: &mut self.ethernet_dma, }; + if !self.rx.new_data_received() { + return None; + } + let rx = RxToken { rx: &mut self.rx }; + let tx = TxToken { + tx: &mut self.tx, + ethernet_dma: &mut self.ethernet_dma, + }; Some((rx, tx)) } fn transmit(&'a mut self) -> Option { - if !self.tx.descriptor_available() { return None } - Some(TxToken { tx: &mut self.tx, ethernet_dma: &mut self.ethernet_dma, }) + if !self.tx.descriptor_available() { + return None; + } + Some(TxToken { + tx: &mut self.tx, + ethernet_dma: &mut self.ethernet_dma, + }) } fn capabilities(&self) -> DeviceCapabilities { @@ -142,7 +152,8 @@ pub struct RxToken<'a> { impl<'a> ::smoltcp::phy::RxToken for RxToken<'a> { fn consume(self, _timestamp: Instant, f: F) -> ::smoltcp::Result - where F: FnOnce(&[u8]) -> ::smoltcp::Result + where + F: FnOnce(&[u8]) -> ::smoltcp::Result, { self.rx.receive(f) } @@ -155,7 +166,8 @@ pub struct TxToken<'a> { impl<'a> ::smoltcp::phy::TxToken for TxToken<'a> { fn consume(mut self, _timestamp: Instant, len: usize, f: F) -> ::smoltcp::Result - where F: FnOnce(&mut [u8]) -> ::smoltcp::Result + where + F: FnOnce(&mut [u8]) -> ::smoltcp::Result, { let mut data = vec![0; len].into_boxed_slice(); let ret = f(&mut data)?; @@ -270,8 +282,11 @@ impl RxDevice { // Descriptors wrap around, but we don't want packets to wrap around. So we require // that the last descriptor in the list is large enough to hold all received packets. // This assertion checks that no wraparound occurs. - assert!(descriptor_index + i < self.descriptors.len(), "buffer of last descriptor in \ - list must be large enough to hold received packets without wrap-around"); + assert!( + descriptor_index + i < self.descriptors.len(), + "buffer of last descriptor in \ + list must be large enough to hold received packets without wrap-around" + ); last_descriptor = self.descriptors[descriptor_index + i].read(); if last_descriptor.own() { return Err(::smoltcp::Error::Exhausted); // packet is not fully received @@ -322,7 +337,9 @@ impl RxDevice { let descriptor = self.descriptors[next].read(); self.descriptors[next].update(|d| d.reset()); next = (next + 1) % self.descriptors.len(); - if descriptor.is_last_descriptor() { break } + if descriptor.is_last_descriptor() { + break; + } } self.next_descriptor = next; @@ -375,8 +392,10 @@ impl TxDevice { pub fn cleanup(&mut self) { let mut c = 0; for descriptor in self.descriptors.iter_mut() { - descriptor.update(|d| if !d.own() && d.buffer().is_some() { - c += 1; + descriptor.update(|d| { + if !d.own() && d.buffer().is_some() { + c += 1; + } }); } if c > 0 { diff --git a/src/ethernet/phy.rs b/src/ethernet/phy.rs index 6289b250..d4405121 100644 --- a/src/ethernet/phy.rs +++ b/src/ethernet/phy.rs @@ -1,5 +1,5 @@ -use board::ethernet_mac::{self, EthernetMac}; use bit_field::BitField; +use board::ethernet_mac::{self, EthernetMac}; use system_clock; const LAN8742A_PHY_ADDRESS: u8 = 0; diff --git a/src/ethernet/tx.rs b/src/ethernet/tx.rs index e9815c6d..52f349dd 100644 --- a/src/ethernet/tx.rs +++ b/src/ethernet/tx.rs @@ -1,6 +1,6 @@ +use alloc::boxed::Box; use bit_field::BitField; use core::{mem, slice}; -use alloc::boxed::Box; #[derive(Debug, Clone, Copy)] #[repr(C)] @@ -93,7 +93,6 @@ impl TxDescriptor { fn set_buffer_1_size(&mut self, size: usize) { assert_eq!(size as u32 as usize, size); - self.word_1 - .set_bits(0..13, size as u32); + self.word_1.set_bits(0..13, size as u32); } } diff --git a/src/exti.rs b/src/exti.rs index a11ff273..f13e8f20 100644 --- a/src/exti.rs +++ b/src/exti.rs @@ -1,10 +1,9 @@ -use board::embedded::interfaces::gpio::Port; +use bit_field::BitField; use board::embedded::components::gpio::stm32f7::Pin; -use board::syscfg::Syscfg; +use board::embedded::interfaces::gpio::Port; use board::exti; +use board::syscfg::Syscfg; use volatile::ReadWrite; -use bit_field::BitField; - pub struct Exti { exti: &'static mut exti::Exti, @@ -33,7 +32,6 @@ impl Exti { self.lines_used.set_bit($number, true); - syscfg.$resyscfg.update(|r| r.$multi($port as u8)); self.exti.imr.update(|r| r.$imr(true)); @@ -44,15 +42,15 @@ impl Exti { RisingEdge => { self.exti.rtsr.update(|r| r.$tr(true)); self.exti.ftsr.update(|r| r.$tr(false)); - }, + } FallingEdge => { self.exti.ftsr.update(|r| r.$tr(true)); self.exti.rtsr.update(|r| r.$tr(false)); - }, + } BothEdges => { self.exti.rtsr.update(|r| r.$tr(true)); self.exti.ftsr.update(|r| r.$tr(true)); - }, + } } }}; ($number:expr, $imr:ident, $tr:ident) => {{ @@ -70,15 +68,15 @@ impl Exti { RisingEdge => { self.exti.rtsr.update(|r| r.$tr(true)); self.exti.ftsr.update(|r| r.$tr(false)); - }, + } FallingEdge => { self.exti.ftsr.update(|r| r.$tr(true)); self.exti.rtsr.update(|r| r.$tr(false)); - }, + } BothEdges => { self.exti.rtsr.update(|r| r.$tr(true)); self.exti.ftsr.update(|r| r.$tr(true)); - }, + } } }}; } diff --git a/src/i2c.rs b/src/i2c.rs index 9b4d86f0..8227ba4f 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -1,10 +1,10 @@ #![allow(dead_code)] -use board::rcc::Rcc; use board::i2c; -use embedded::interfaces::gpio::Gpio; -use core::marker::PhantomData; +use board::rcc::Rcc; use core::iter::TrustedLen; +use core::marker::PhantomData; +use embedded::interfaces::gpio::Gpio; pub struct I2C(&'static mut i2c::I2c); @@ -23,9 +23,9 @@ impl Address { } pub fn init_pins_and_clocks(rcc: &mut Rcc, gpio: &mut Gpio) { - use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; + use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; // enable clocks rcc.apb1enr.update(|r| { @@ -45,14 +45,7 @@ pub fn init_pins_and_clocks(rcc: &mut Rcc, gpio: &mut Gpio) { let i2c4_sda = (PortD, Pin13); let pins = [ - i2c1_scl, - i2c1_sda, - i2c2_scl, - i2c2_sda, - i2c3_scl, - i2c3_sda, - i2c4_scl, - i2c4_sda, + i2c1_scl, i2c1_sda, i2c2_scl, i2c2_sda, i2c3_scl, i2c3_sda, i2c4_scl, i2c4_sda, ]; gpio.to_alternate_function_all( &pins, @@ -291,7 +284,6 @@ impl I2C { self.stop() } - pub fn stop(&mut self) -> Result<(), Error> { self.0.cr2.update(|r| r.set_stop(true)); diff --git a/src/interrupts/mod.rs b/src/interrupts/mod.rs index 462e4dc7..2590fea9 100644 --- a/src/interrupts/mod.rs +++ b/src/interrupts/mod.rs @@ -16,13 +16,13 @@ //! unregistered at the end of the scope. Thus it is safe to access the parent stack in the //! interrupt service routine. +use self::interrupt_request::InterruptRequest; use alloc::boxed::Box; use board::nvic::Nvic; use board::nvic::Stir; -use core::marker::PhantomData; use core::intrinsics::transmute; +use core::marker::PhantomData; use core::ptr; -use self::interrupt_request::InterruptRequest; pub mod interrupt_request; pub mod primask_mutex; @@ -51,106 +51,14 @@ unsafe extern "C" fn dispatcher() { #[allow(private_no_mangle_statics)] static INTERRUPTS: [unsafe extern "C" fn(); 98] = [dispatcher; 98]; - static mut ISRS: [Option>; 98] = [ - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, ]; /// Default interrupt handler @@ -368,9 +276,9 @@ impl<'a> InterruptTable<'a> { // and alway only one isr can access the data (Send is not needed for closure) let isr = unsafe { let parameter = &mut *(self.data[irq as usize] as *mut T); - transmute::, Box>( - Box::new(move || { isr(parameter); }), - ) + transmute::, Box>(Box::new(move || { + isr(parameter); + })) }; let interrupt_handle = self.insert_boxed_isr(irq, isr)?; self.set_priority(&interrupt_handle, priority); @@ -537,7 +445,6 @@ impl<'a> InterruptTable<'a> { } } - /// Sets the priority of the interrupt corresponding to the `interrupt_handle`. pub fn set_priority(&mut self, interrupt_handle: &InterruptHandle, priority: Priority) { let irq = interrupt_handle.irq; @@ -550,7 +457,6 @@ impl<'a> InterruptTable<'a> { self.nvic.ipr[irq as usize].update(|r| r.set(priority)); } - /// Returns the priority of the interrupt corresponding to the `interrupt_handle`. pub fn get_priority(&self, interrupt_handle: &InterruptHandle) -> Priority { let irq = interrupt_handle.irq; diff --git a/src/interrupts/primask_mutex.rs b/src/interrupts/primask_mutex.rs index fc04b748..57a2c854 100644 --- a/src/interrupts/primask_mutex.rs +++ b/src/interrupts/primask_mutex.rs @@ -7,7 +7,6 @@ //! the current code in the critical section) the mutex implements `Send` and `Sync` when //! the synchronized data implements `Send`. - use core::cell::UnsafeCell; /// Mutex that uses the `primask` core register from the cortem m processor to disable diff --git a/src/lcd/color.rs b/src/lcd/color.rs index 720a600a..5ca7e9e0 100644 --- a/src/lcd/color.rs +++ b/src/lcd/color.rs @@ -56,8 +56,8 @@ impl Color { } pub fn to_argb1555(&self) -> u16 { - (u16::from(self.alpha) & 0x80) << 8 | (u16::from(self.red) & 0xf8) << 7 | - (u16::from(self.green) & 0xf8) << 2 | (u16::from(self.blue) & 0xf8) >> 3 + (u16::from(self.alpha) & 0x80) << 8 | (u16::from(self.red) & 0xf8) << 7 + | (u16::from(self.green) & 0xf8) << 2 | (u16::from(self.blue) & 0xf8) >> 3 } pub fn from_argb1555(color: u16) -> Color { @@ -68,7 +68,7 @@ impl Color { blue: ((color << 3) & 0xf8) as u8, } } - + pub fn from_hsv(hue: i32, saturation: f32, value: f32) -> Color { let mut h = hue % 360; if h < 0 { @@ -106,8 +106,9 @@ impl Color { rgb.2 += m; Color::rgb( - (255f32 * rgb.0) as u8, - (255f32 * rgb.1) as u8, - (255f32 * rgb.2) as u8) + (255f32 * rgb.0) as u8, + (255f32 * rgb.1) as u8, + (255f32 * rgb.2) as u8, + ) } } diff --git a/src/lcd/font.rs b/src/lcd/font.rs index 8649efd8..3adc5791 100644 --- a/src/lcd/font.rs +++ b/src/lcd/font.rs @@ -1,6 +1,6 @@ -use rusttype::{point, Font, FontCollection, PositionedGlyph, Scale}; use alloc::Vec; use rusttype::stb_truetype::float_impls::FloatImpls; +use rusttype::{point, Font, FontCollection, PositionedGlyph, Scale}; pub struct FontRenderer<'a> { font: Font<'a>, @@ -49,9 +49,7 @@ impl<'a> FontRenderer<'a> { let width = glyphs .iter() .rev() - .map(|g| { - g.position().x as f32 + g.unpositioned().h_metrics().advance_width - }) + .map(|g| g.position().x as f32 + g.unpositioned().h_metrics().advance_width) .next() .unwrap_or(0.0) .ceil() as usize; diff --git a/src/lcd/init.rs b/src/lcd/init.rs index e1e4d120..444fda0b 100644 --- a/src/lcd/init.rs +++ b/src/lcd/init.rs @@ -1,14 +1,13 @@ -use board::rcc::Rcc; +use super::{LAYER_1_START, LAYER_2_START, Lcd}; use board::ltdc::Ltdc; +use board::rcc::Rcc; use embedded::interfaces::gpio::{Gpio, OutputPin}; -use super::{LAYER_1_START, LAYER_2_START, Lcd}; const HEIGHT: u16 = super::HEIGHT as u16; const WIDTH: u16 = super::WIDTH as u16; const LAYER_1_OCTETS_PER_PIXEL: u16 = super::LAYER_1_OCTETS_PER_PIXEL as u16; const LAYER_2_OCTETS_PER_PIXEL: u16 = super::LAYER_2_OCTETS_PER_PIXEL as u16; - pub fn init(ltdc: &'static mut Ltdc, rcc: &mut Rcc, gpio: &mut Gpio) -> Lcd { // init gpio pins let (mut display_enable, mut backlight_enable) = init_pins(gpio); @@ -73,7 +72,6 @@ pub fn init(ltdc: &'static mut Ltdc, rcc: &mut Rcc, gpio: &mut Gpio) -> Lcd { // set background color ltdc.bccr.update(|r| r.set_bc(0x0000ff)); // background_color blue - // enable the transfer error interrupt and the FIFO underrun interrupt ltdc.ier.update(|r| { r.set_terrie(true); // TRANSFER_ERROR_INTERRUPT_ENABLE @@ -164,8 +162,6 @@ pub fn init(ltdc: &'static mut Ltdc, rcc: &mut Rcc, gpio: &mut Gpio) -> Lcd { // init DMA2D graphic - - // enable display and backlight display_enable.set(true); backlight_enable.set(true); @@ -202,8 +198,8 @@ pub fn init(ltdc: &'static mut Ltdc, rcc: &mut Rcc, gpio: &mut Gpio) -> Lcd { } pub fn init_pins(gpio: &mut Gpio) -> (OutputPin, OutputPin) { - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; // Red diff --git a/src/lcd/mod.rs b/src/lcd/mod.rs index 1e1db235..0cd0f355 100644 --- a/src/lcd/mod.rs +++ b/src/lcd/mod.rs @@ -1,19 +1,19 @@ #![allow(dead_code)] pub use self::color::Color; +pub use self::font::FontRenderer; pub use self::init::init; pub use self::stdout::init as init_stdout; -pub use self::font::FontRenderer; use board::ltdc::Ltdc; -use embedded::interfaces::gpio::OutputPin; use core::{fmt, ptr}; +use embedded::interfaces::gpio::OutputPin; #[macro_use] pub mod stdout; -mod init; mod color; pub mod font; +mod init; const HEIGHT: usize = 272; const WIDTH: usize = 480; @@ -89,7 +89,6 @@ pub struct FramebufferAl88 { base_addr: usize, } - impl FramebufferAl88 { fn new(base_addr: usize) -> Self { Self { base_addr } @@ -111,14 +110,7 @@ pub struct Layer { impl Layer { pub fn horizontal_stripes(&mut self) { let colors = [ - 0xffffff, - 0xcccccc, - 0x999999, - 0x666666, - 0x333333, - 0x0, - 0xff0000, - 0x0000ff, + 0xffffff, 0xcccccc, 0x999999, 0x666666, 0x333333, 0x0, 0xff0000, 0x0000ff, ]; // horizontal stripes @@ -135,14 +127,7 @@ impl Layer { pub fn vertical_stripes(&mut self) { let colors = [ - 0xcccccc, - 0x999999, - 0x666666, - 0x333333, - 0x0, - 0xff0000, - 0x0000ff, - 0xffffff, + 0xcccccc, 0x999999, 0x666666, 0x333333, 0x0, 0xff0000, 0x0000ff, 0xffffff, ]; // vertical stripes @@ -249,7 +234,6 @@ impl<'a, T: Framebuffer + 'a> AudioWriter<'a, T> { self.layer.print_point_color_at(self.next_col, i, color); } - self.next_col = (self.next_col + 1) % WIDTH; self.prev_value = (value0, value1); } diff --git a/src/lcd/stdout.rs b/src/lcd/stdout.rs index fa988ea8..c61cdbd6 100644 --- a/src/lcd/stdout.rs +++ b/src/lcd/stdout.rs @@ -1,6 +1,6 @@ -use spin::Mutex; -use core::fmt; use super::{FramebufferAl88, Layer, TextWriter}; +use core::fmt; +use spin::Mutex; static STDOUT: Mutex>> = Mutex::new(None); diff --git a/src/lib.rs b/src/lib.rs index 4b734869..c37a4c15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,8 +23,8 @@ extern crate alloc_cortex_m; extern crate arrayvec; extern crate bit_field; extern crate byteorder; -extern crate smoltcp; extern crate rusttype; +extern crate smoltcp; extern crate spin; extern crate volatile; #[macro_use] @@ -34,18 +34,18 @@ extern crate bitflags; pub mod semi_hosting; #[macro_use] pub mod lcd; -pub mod exceptions; -pub mod interrupts; -pub mod system_clock; -pub mod sdram; -pub mod i2c; pub mod audio; -pub mod touch; pub mod ethernet; +pub mod exceptions; +pub mod exti; pub mod heap; +pub mod i2c; +pub mod interrupts; pub mod random; -pub mod exti; pub mod sd; +pub mod sdram; +pub mod system_clock; +pub mod touch; #[cfg(not(test))] #[lang = "panic_fmt"] @@ -64,9 +64,11 @@ pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: hprintln_err!(" {}", fmt); unsafe { lcd::stdout::force_unlock() } - lcd::stdout::with_stdout(|stdout| if let Some(ref mut stdout) = *stdout { - let _ = writeln!(stdout, "\nPANIC in {} at line {}:", file, line); - let _ = writeln!(stdout, " {}", fmt); + lcd::stdout::with_stdout(|stdout| { + if let Some(ref mut stdout) = *stdout { + let _ = writeln!(stdout, "\nPANIC in {} at line {}:", file, line); + let _ = writeln!(stdout, " {}", fmt); + } }); loop {} @@ -78,7 +80,6 @@ fn oom() -> ! { panic!("Out of memory!"); } - use alloc_cortex_m::CortexMHeap; #[global_allocator] diff --git a/src/main.rs b/src/main.rs index b76512c4..04e6e392 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,12 +16,12 @@ extern crate r0; extern crate smoltcp; // hardware register structs with accessor methods -use stm32f7::{audio, board, embedded, ethernet, lcd, sdram, system_clock, touch, i2c, sd}; +use alloc::Vec; use smoltcp::socket::{Socket, SocketSet, TcpSocket, TcpSocketBuffer}; -use smoltcp::socket::{UdpSocket, UdpPacketMetadata, UdpSocketBuffer}; -use smoltcp::wire::{IpEndpoint, IpAddress, EthernetAddress, Ipv4Address}; +use smoltcp::socket::{UdpPacketMetadata, UdpSocket, UdpSocketBuffer}; use smoltcp::time::Instant; -use alloc::Vec; +use smoltcp::wire::{EthernetAddress, IpAddress, IpEndpoint, Ipv4Address}; +use stm32f7::{audio, board, embedded, ethernet, i2c, lcd, sd, sdram, system_clock, touch}; pub const ETH_ADDR: EthernetAddress = EthernetAddress([0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef]); pub const IP_ADDR: Ipv4Address = Ipv4Address([141, 52, 46, 198]); @@ -55,8 +55,8 @@ pub unsafe extern "C" fn reset() -> ! { // WORKAROUND: rust compiler will inline & reorder fp instructions into #[inline(never)] // reset() before the FPU is initialized fn main(hw: board::Hardware) -> ! { - use embedded::interfaces::gpio::{self, Gpio}; use alloc::Vec; + use embedded::interfaces::gpio::{self, Gpio}; let x = vec![1, 2, 3, 4, 5]; assert_eq!(x.len(), 5); @@ -91,17 +91,7 @@ fn main(hw: board::Hardware) -> ! { } = hw; let mut gpio = Gpio::new( - gpio_a, - gpio_b, - gpio_c, - gpio_d, - gpio_e, - gpio_f, - gpio_g, - gpio_h, - gpio_i, - gpio_j, - gpio_k, + gpio_a, gpio_b, gpio_c, gpio_d, gpio_e, gpio_f, gpio_g, gpio_h, gpio_i, gpio_j, gpio_k, ); system_clock::init(rcc, pwr, flash); @@ -198,8 +188,8 @@ fn main(hw: board::Hardware) -> ! { let mut audio_writer = layer_1.audio_writer(); let mut last_led_toggle = system_clock::ticks(); - use stm32f7::board::embedded::interfaces::gpio::Port; use stm32f7::board::embedded::components::gpio::stm32f7::Pin; + use stm32f7::board::embedded::interfaces::gpio::Port; use stm32f7::exti::{EdgeDetection, Exti, ExtiLine}; let mut exti = Exti::new(exti); @@ -209,19 +199,21 @@ fn main(hw: board::Hardware) -> ! { syscfg, ).unwrap(); - use stm32f7::interrupts::{scope, Priority}; use stm32f7::interrupts::interrupt_request::InterruptRequest; + use stm32f7::interrupts::{scope, Priority}; scope( nvic, |_| {}, |interrupt_table| { - let _ = interrupt_table.register(InterruptRequest::Exti10to15, Priority::P1, move || { - exti_handle.clear_pending_state(); - // choose a new background color - let new_color = ((system_clock::ticks() as u32).wrapping_mul(19801)) % 0x1000000; - lcd.set_background_color(lcd::Color::from_hex(new_color)); - }); + let _ = + interrupt_table.register(InterruptRequest::Exti10to15, Priority::P1, move || { + exti_handle.clear_pending_state(); + // choose a new background color + let new_color = + ((system_clock::ticks() as u32).wrapping_mul(19801)) % 0x1000000; + lcd.set_background_color(lcd::Color::from_hex(new_color)); + }); loop { let ticks = system_clock::ticks(); @@ -234,7 +226,6 @@ fn main(hw: board::Hardware) -> ! { last_led_toggle = ticks; } - // poll for new touch data for touch in &touch::touches(&mut i2c_3).unwrap() { audio_writer @@ -242,12 +233,14 @@ fn main(hw: board::Hardware) -> ! { .print_point_at(touch.x as usize, touch.y as usize); } - // handle new ethernet packets if let Ok(ref mut eth) = ethernet_interface { - match eth.poll(&mut sockets, Instant::from_millis(system_clock::ticks() as i64)) { + match eth.poll( + &mut sockets, + Instant::from_millis(system_clock::ticks() as i64), + ) { Err(::smoltcp::Error::Exhausted) => continue, - Err(::smoltcp::Error::Unrecognized) => {}, + Err(::smoltcp::Error::Unrecognized) => {} Err(e) => println!("Network error: {:?}", e), Ok(socket_changed) => if socket_changed { for mut socket in sockets.iter_mut() { @@ -278,20 +271,22 @@ fn poll_socket(socket: &mut Socket) -> Result<(), smoltcp::Error> { match socket.recv() { Ok((data, remote_endpoint)) => { let mut data = Vec::from(data); - let len = data.len()-1; + let len = data.len() - 1; data[..len].reverse(); reply = (data, remote_endpoint); - }, + } Err(smoltcp::Error::Exhausted) => break, Err(err) => return Err(err), } socket.send_slice(&reply.0, reply.1)?; - } + }, _ => {} - } + }, &mut Socket::Tcp(ref mut socket) => match socket.local_endpoint().port { 15 => { - if !socket.may_recv() { return Ok(()); } + if !socket.may_recv() { + return Ok(()); + } let reply = socket.recv(|data| { if data.len() > 0 { let mut reply = Vec::from("tcp: "); @@ -308,7 +303,7 @@ fn poll_socket(socket: &mut Socket) -> Result<(), smoltcp::Error> { } } _ => {} - } + }, _ => {} } Ok(()) diff --git a/src/random.rs b/src/random.rs index 690505f0..4d44f144 100644 --- a/src/random.rs +++ b/src/random.rs @@ -25,11 +25,9 @@ //! //! Iter is currently not implemented. Pull Requests welcome! - -use core::result::Result; -use core::ops::Drop; use board; - +use core::ops::Drop; +use core::result::Result; /// Contains state as well as the Rng Struct from embedded::board. pub struct Rng { @@ -38,7 +36,6 @@ pub struct Rng { board_rng: &'static mut board::rng::Rng, } - ///Any of the errors (except AlreadyEnabled) can usually be resolved by initializing this ///struct again. #[derive(Debug)] @@ -51,7 +48,6 @@ pub enum ErrorType { NotReady, } - impl Rng { ///! This will take semi-ownership (with &'static) for the rng struct /// from board::rng. @@ -79,13 +75,11 @@ impl Rng { Ok(rng) } - /// For Testing purposes. Do not use except for debugging! pub fn tick(&mut self) -> u32 { self.poll_and_get().unwrap_or(0) } - /// Actually try to acquire some random number /// Returns Ok(number) or Err! pub fn poll_and_get(&mut self) -> Result { @@ -124,21 +118,18 @@ impl Rng { Err(ErrorType::NotReady) } - pub fn reset(&mut self) { self.board_rng.cr.update(|r| r.set_rngen(false)); self.board_rng.cr.update(|r| r.set_ie(false)); self.board_rng.cr.update(|r| r.set_rngen(true)); } - fn disable_cr(&mut self, rcc: &mut board::rcc::Rcc) { self.board_rng.cr.update(|r| r.set_rngen(false)); self.board_rng.cr.update(|r| r.set_ie(false)); rcc.ahb2enr.update(|r| r.set_rngen(false)); } - pub fn disable(mut self, rcc: &mut board::rcc::Rcc) { use core::mem; self.disable_cr(rcc); @@ -146,7 +137,6 @@ impl Rng { } } - impl Drop for Rng { /// PANICS EVERYTIME! Use .disable(rcc) explicitly! fn drop(&mut self) { diff --git a/src/sd/error.rs b/src/sd/error.rs index a421ecde..5633400d 100644 --- a/src/sd/error.rs +++ b/src/sd/error.rs @@ -1,12 +1,12 @@ #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Error { - Error, // Unknown Error - NoSdCard, // No SD Card - Timeout, // Timeout while waiting for a response - InvalidVoltrange, // Voltage Trial failed - CardError { t: CardStatusFlags }, // Card Error, see CardStatusFlags - SdmmcError { t: SdmmcErrorType }, // Response to a failed command - RWError { t: RWErrorType }, // Error during reading from/writing to the card + Error, // Unknown Error + NoSdCard, // No SD Card + Timeout, // Timeout while waiting for a response + InvalidVoltrange, // Voltage Trial failed + CardError { t: CardStatusFlags }, // Card Error, see CardStatusFlags + SdmmcError { t: SdmmcErrorType }, // Response to a failed command + RWError { t: RWErrorType }, // Error during reading from/writing to the card } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -20,8 +20,8 @@ pub enum RWErrorType { AddressOutOfRange, DataTimeout, DataCrcFailed, - TxUnderrun, // FIFO underrun - RxOverrun, // FIFO overrun + TxUnderrun, // FIFO underrun + RxOverrun, // FIFO overrun } // See Documentation Table 207 and Table 228 diff --git a/src/sd/init.rs b/src/sd/init.rs index ffa978db..5c450517 100644 --- a/src/sd/init.rs +++ b/src/sd/init.rs @@ -1,5 +1,5 @@ -use super::{Sd, CardType, sdmmc_cmd, CardInfo}; use super::error::Error; +use super::{sdmmc_cmd, CardInfo, CardType, Sd}; use board::rcc::Rcc; use board::sdmmc::Sdmmc; use embedded::interfaces::gpio::Gpio; @@ -49,12 +49,12 @@ use embedded::interfaces::gpio::Gpio; pub fn init(sd: &mut Sd) -> Result<(), Error> { // Check for SD card if !sd.card_present() { - return Err(Error::NoSdCard) + return Err(Error::NoSdCard); } // Card already initialized if sd.card_initialized() { - return Ok(()) + return Ok(()); } // default clock configuration @@ -78,10 +78,12 @@ pub fn init(sd: &mut Sd) -> Result<(), Error> { sdmmc_cmd::send_csd(sd.sdmmc, u32::from(card_info.rca) << 16)?; - let csd = [sd.sdmmc.resp1.read().cardstatus1(), - sd.sdmmc.resp2.read().cardstatus2(), - sd.sdmmc.resp3.read().cardstatus3(), - sd.sdmmc.resp4.read().cardstatus4()]; + let csd = [ + sd.sdmmc.resp1.read().cardstatus1(), + sd.sdmmc.resp2.read().cardstatus2(), + sd.sdmmc.resp3.read().cardstatus3(), + sd.sdmmc.resp4.read().cardstatus4(), + ]; get_card_csd(&mut card_info, csd); @@ -107,21 +109,21 @@ pub fn init_hw(gpio: &mut Gpio, rcc: &mut Rcc) { rcc.ahb1enr.update(|r| { r.set_gpiocen(true); // Data and clock port r.set_gpioden(true); // CMD port - // r.set_gpioben(true); // only needed in mmc 8bit mode + // r.set_gpioben(true); // only needed in mmc 8bit mode }); // wait for enabling - while !rcc.apb2enr.read().sdmmc1en() - || !rcc.ahb1enr.read().gpiocen() - || !rcc.ahb1enr.read().gpioden() {} - // || !rcc.ahb1enr.read().gpioben() {} + while !rcc.apb2enr.read().sdmmc1en() || !rcc.ahb1enr.read().gpiocen() + || !rcc.ahb1enr.read().gpioden() + {} + // || !rcc.ahb1enr.read().gpioben() {} init_pins(gpio); } fn init_pins(gpio: &mut Gpio) { - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; - use embedded::interfaces::gpio::{AlternateFunction, OutputType, OutputSpeed, Resistor}; + use embedded::interfaces::gpio::Port::*; + use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; // Data ports. For Default Bus mode only d0 is needed. let d0 = (PortC, Pin8); @@ -139,22 +141,15 @@ fn init_pins(gpio: &mut Gpio) { // sdmmc_cmd let cmd = (PortD, Pin2); - let pins = [d0, - d1, - d2, - d3, - d4, - d5, - d6, - d7, - ck, - cmd]; - - gpio.to_alternate_function_all(&pins, - AlternateFunction::AF12, - OutputType::PushPull, - OutputSpeed::High, - Resistor::PullUp).unwrap(); + let pins = [d0, d1, d2, d3, d4, d5, d6, d7, ck, cmd]; + + gpio.to_alternate_function_all( + &pins, + AlternateFunction::AF12, + OutputType::PushPull, + OutputSpeed::High, + Resistor::PullUp, + ).unwrap(); } fn power_on(sdmmc: &mut Sdmmc) -> Result { @@ -177,7 +172,7 @@ fn power_on(sdmmc: &mut Sdmmc) -> Result { // voltage trial for card V2 while !valid_voltage { if count == max_volt_trial { - return Err(Error::InvalidVoltrange) + return Err(Error::InvalidVoltrange); } count += 1; @@ -200,7 +195,7 @@ fn power_on(sdmmc: &mut Sdmmc) -> Result { } else { while !valid_voltage { if count == max_volt_trial { - return Err(Error::InvalidVoltrange) + return Err(Error::InvalidVoltrange); } count += 1; diff --git a/src/sd/mod.rs b/src/sd/mod.rs index c673dc50..214a6dba 100644 --- a/src/sd/mod.rs +++ b/src/sd/mod.rs @@ -1,15 +1,15 @@ -pub use self::init::{init, de_init}; +pub use self::init::{de_init, init}; pub mod error; mod init; mod sdmmc_cmd; -use board::sdmmc::Sdmmc; -use board::rcc::Rcc; -use embedded::interfaces::gpio::{Gpio, InputPin}; use self::error::*; -use core::cmp::min; use alloc::vec::Vec; +use board::rcc::Rcc; +use board::sdmmc::Sdmmc; +use core::cmp::min; +use embedded::interfaces::gpio::{Gpio, InputPin}; /// SD handle. pub struct Sd { @@ -39,8 +39,8 @@ impl Sd { /// } /// ``` pub fn new(sdmmc: &'static mut Sdmmc, gpio: &mut Gpio, rcc: &mut Rcc) -> Sd { - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Resistor; rcc.ahb1enr.update(|r| r.set_gpiocen(true)); @@ -141,12 +141,22 @@ impl Sd { /// loop {} /// } /// ``` - pub fn write_blocks(&mut self, data: &[u32], block_add: u32, number_of_blks: u16) -> Result<(), Error> { + pub fn write_blocks( + &mut self, + data: &[u32], + block_add: u32, + number_of_blks: u16, + ) -> Result<(), Error> { // This is a wrapper function for the write_blocks_h() function. The write_blocks_h() // function can only write single blocks to the card, because the multi-block mode of the // SDMMC-Controller doesn't work. for i in 0..u32::from(number_of_blks) { - self.write_blocks_h(&data[min((i as usize)*128, data.len())..], block_add + i, 1, 5000)?; + self.write_blocks_h( + &data[min((i as usize) * 128, data.len())..], + block_add + i, + 1, + 5000, + )?; } Ok(()) @@ -157,21 +167,24 @@ impl Sd { &mut self, block_add: u32, number_of_blks: u16, - timeout: u32) -> Result, Error> { + timeout: u32, + ) -> Result, Error> { // No blocks to read -> return empty vector if number_of_blks == 0 { - return Ok(vec![]) + return Ok(vec![]); } // Check if a SD Card is inserted. if !self.card_present() { - return Err(Error::NoSdCard) + return Err(Error::NoSdCard); } let mut block_add = block_add; let card_info = self.card_info.as_ref().unwrap(); // Check if the blocks to read are in bounds. if block_add + u32::from(number_of_blks) > card_info.log_blk_number { - return Err( Error::RWError { t: RWErrorType::AddressOutOfRange } ) + return Err(Error::RWError { + t: RWErrorType::AddressOutOfRange, + }); } // On high capacity cards the block_add has to be in bytes and not the block number itself. @@ -195,18 +208,16 @@ impl Sd { self.sdmmc.dtimer.update(|d| d.set_datatime(0xFFFF_FFFF)); self.sdmmc.dctrl.update(|d| { d.set_dblocksize(0x09); // blocksize = 2^n => blocksize = 2^9 = 512 - d.set_dtdir(true); // direction: false -> write, true -> read - d.set_dtmode(false); // mode: false -> block, true -> stream - d.set_dten(true); // enable data transfer + d.set_dtdir(true); // direction: false -> write, true -> read + d.set_dtmode(false); // mode: false -> block, true -> stream + d.set_dten(true); // enable data transfer }); // Read data from the SD Card, until dataend is reached or an error occurs let mut data = vec![]; let timeout = ::system_clock::ticks() as u32 + timeout; - while (::system_clock::ticks() as u32) < timeout - && !self.sdmmc.sta.read().rxoverr() - && !self.sdmmc.sta.read().dcrcfail() - && !self.sdmmc.sta.read().dtimeout() + while (::system_clock::ticks() as u32) < timeout && !self.sdmmc.sta.read().rxoverr() + && !self.sdmmc.sta.read().dcrcfail() && !self.sdmmc.sta.read().dtimeout() && !self.sdmmc.sta.read().dataend() { if self.sdmmc.sta.read().rxfifohf() { @@ -228,20 +239,25 @@ impl Sd { // Check for errors if self.sdmmc.sta.read().dtimeout() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::DataTimeout }); + return Err(Error::RWError { + t: RWErrorType::DataTimeout, + }); } if self.sdmmc.sta.read().dcrcfail() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::DataCrcFailed }); + return Err(Error::RWError { + t: RWErrorType::DataCrcFailed, + }); } if self.sdmmc.sta.read().rxoverr() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::RxOverrun }); + return Err(Error::RWError { + t: RWErrorType::RxOverrun, + }); } // If there is still valid data in the FIFO, empty the FIFO - while (::system_clock::ticks() as u32) < timeout - && self.sdmmc.sta.read().rxdavl() { + while (::system_clock::ticks() as u32) < timeout && self.sdmmc.sta.read().rxdavl() { data.push(self.sdmmc.fifo.read().fifodata()); } @@ -260,21 +276,24 @@ impl Sd { data: &[u32], block_add: u32, number_of_blks: u16, - timeout: u32) -> Result<(), Error> { + timeout: u32, + ) -> Result<(), Error> { // No blocks to read -> return empty vector if number_of_blks == 0 { - return Ok(()) + return Ok(()); } // Check if a SD Card is inserted. if !self.card_present() { - return Err(Error::NoSdCard) + return Err(Error::NoSdCard); } let mut block_add = block_add; let card_info = self.card_info.as_ref().unwrap(); // Check if the blocks to read are in bounds. if block_add + u32::from(number_of_blks) > card_info.log_blk_number { - return Err( Error::RWError { t: RWErrorType::AddressOutOfRange } ) + return Err(Error::RWError { + t: RWErrorType::AddressOutOfRange, + }); } // On high capacity cards the block_add has to be in bytes and not the block number itself. @@ -298,18 +317,16 @@ impl Sd { self.sdmmc.dtimer.update(|d| d.set_datatime(0xFFFF_FFFF)); self.sdmmc.dctrl.update(|d| { d.set_dblocksize(0x09); // blocksize = 2^n => blocksize = 2^9 = 512 - d.set_dtdir(false); // direction: false -> write, true -> read - d.set_dtmode(false); // mode: false -> block, true -> stream - d.set_dten(true); // enable data transfer + d.set_dtdir(false); // direction: false -> write, true -> read + d.set_dtmode(false); // mode: false -> block, true -> stream + d.set_dten(true); // enable data transfer }); // Write data to the SD Card, until dataend is reached or an error occurs let mut data_counter = 0; let timeout = ::system_clock::ticks() as u32 + timeout; - while (::system_clock::ticks() as u32) < timeout - && !self.sdmmc.sta.read().txunderr() - && !self.sdmmc.sta.read().dcrcfail() - && !self.sdmmc.sta.read().dtimeout() + while (::system_clock::ticks() as u32) < timeout && !self.sdmmc.sta.read().txunderr() + && !self.sdmmc.sta.read().dcrcfail() && !self.sdmmc.sta.read().dtimeout() && !self.sdmmc.sta.read().dataend() { if self.sdmmc.sta.read().txfifohe() { @@ -342,15 +359,21 @@ impl Sd { // Check for errors if self.sdmmc.sta.read().dtimeout() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::DataTimeout }); + return Err(Error::RWError { + t: RWErrorType::DataTimeout, + }); } if self.sdmmc.sta.read().dcrcfail() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::DataCrcFailed }); + return Err(Error::RWError { + t: RWErrorType::DataCrcFailed, + }); } if self.sdmmc.sta.read().txunderr() { sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); - return Err(Error::RWError { t: RWErrorType::TxUnderrun }); + return Err(Error::RWError { + t: RWErrorType::TxUnderrun, + }); } sdmmc_cmd::clear_all_static_status_flags(self.sdmmc); @@ -369,11 +392,11 @@ pub enum CardType { #[derive(Debug)] pub struct CardInfo { card_type: CardType, - rca: u16, // Relative Card Address - blk_number: u32, // Number of physical blocks - blk_size: u32, // Physical block size - log_blk_number: u32, // Number of logical blocks - log_blk_size: u32, // Logical block size + rca: u16, // Relative Card Address + blk_number: u32, // Number of physical blocks + blk_size: u32, // Physical block size + log_blk_number: u32, // Number of logical blocks + log_blk_size: u32, // Logical block size } impl Default for CardInfo { diff --git a/src/sd/sdmmc_cmd.rs b/src/sd/sdmmc_cmd.rs index 65783fd3..2f14c42a 100644 --- a/src/sd/sdmmc_cmd.rs +++ b/src/sd/sdmmc_cmd.rs @@ -7,8 +7,7 @@ pub fn idle(sdmmc: &mut Sdmmc, timeout: u32) -> Result<(), Error> { send_cmd(sdmmc, 0, 0x00, true, false, 0x00); let timeout = ::system_clock::ticks() as u32 + timeout; - while (::system_clock::ticks() as u32) < timeout - && !sdmmc.sta.read().cmdsent() {} + while (::system_clock::ticks() as u32) < timeout && !sdmmc.sta.read().cmdsent() {} if (::system_clock::ticks() as u32) >= timeout { return Err(Error::Timeout); @@ -130,11 +129,14 @@ pub fn stop_transfer(sdmmc: &mut Sdmmc) -> Result<(), Error> { } /// Send a command to the card. -pub fn send_cmd(sdmmc: &mut Sdmmc, - argument: u32, cmdidx: u8, - cpsmen: bool, - waitint: bool, - waitresp: u8) { +pub fn send_cmd( + sdmmc: &mut Sdmmc, + argument: u32, + cmdidx: u8, + cpsmen: bool, + waitint: bool, + waitresp: u8, +) { sdmmc.arg.update(|arg| arg.set_cmdarg(argument)); sdmmc.cmd.update(|cmd| { cmd.set_cpsmen(cpsmen); @@ -150,7 +152,7 @@ fn get_cmd_resp1(sdmmc: &mut Sdmmc, cmd_idx: u8, timeout: u32) -> Result<(), Err if sdmmc.respcmd.read().respcmd() != cmd_idx { return Err(Error::SdmmcError { - t: SdmmcErrorType::CmdCrcFailed + t: SdmmcErrorType::CmdCrcFailed, }); } @@ -185,7 +187,7 @@ fn get_cmd_resp6(sdmmc: &mut Sdmmc, cmd_idx: u8, timeout: u32) -> Result Result Result<(), Error> { let timeout = ::system_clock::ticks() as u32 + timeout; - while (::system_clock::ticks() as u32) < timeout - && !sdmmc.sta.read().cmdrend() - && !sdmmc.sta.read().ccrcfail() - && !sdmmc.sta.read().ctimeout() {} + while (::system_clock::ticks() as u32) < timeout && !sdmmc.sta.read().cmdrend() + && !sdmmc.sta.read().ccrcfail() && !sdmmc.sta.read().ctimeout() + {} if (::system_clock::ticks() as u32) >= timeout { return Err(Error::Timeout); @@ -220,7 +225,7 @@ fn wait_resp(sdmmc: &mut Sdmmc, timeout: u32) -> Result<(), Error> { if sdmmc.sta.read().ctimeout() { sdmmc.icr.update(|icr| icr.set_ctimeoutc(true)); return Err(Error::SdmmcError { - t: SdmmcErrorType::CmdRespTimeout + t: SdmmcErrorType::CmdRespTimeout, }); } @@ -233,7 +238,7 @@ fn wait_resp_crc(sdmmc: &mut Sdmmc, timeout: u32) -> Result<(), Error> { if sdmmc.sta.read().ccrcfail() { sdmmc.icr.update(|icr| icr.set_ccrcfailc(true)); return Err(Error::SdmmcError { - t: SdmmcErrorType::CmdCrcFailed + t: SdmmcErrorType::CmdCrcFailed, }); } @@ -263,11 +268,15 @@ fn check_for_errors(card_status: u32) -> Result<(), Error> { } else if card_status & ERASE_RESET.bits() != 0 { Err(Error::CardError { t: ERASE_RESET }) } else if card_status & CARD_ECC_DISABLED.bits() != 0 { - Err(Error::CardError { t: CARD_ECC_DISABLED }) + Err(Error::CardError { + t: CARD_ECC_DISABLED, + }) } else if card_status & WP_ERASE_SKIP.bits() != 0 { Err(Error::CardError { t: WP_ERASE_SKIP }) } else if card_status & CID_CSD_OVERWRITE.bits() != 0 { - Err(Error::CardError { t: CID_CSD_OVERWRITE }) + Err(Error::CardError { + t: CID_CSD_OVERWRITE, + }) } else if card_status & CC_ERROR.bits() != 0 { Err(Error::CardError { t: CC_ERROR }) } else if card_status & CARD_ECC_FAILED.bits() != 0 { @@ -277,7 +286,9 @@ fn check_for_errors(card_status: u32) -> Result<(), Error> { } else if card_status & COM_CRC_ERROR.bits() != 0 { Err(Error::CardError { t: COM_CRC_ERROR }) } else if card_status & LOCK_UNLOCK_FAILED.bits() != 0 { - Err(Error::CardError { t: LOCK_UNLOCK_FAILED }) + Err(Error::CardError { + t: LOCK_UNLOCK_FAILED, + }) } else if card_status & WP_VIOLATION.bits() != 0 { Err(Error::CardError { t: WP_VIOLATION }) } else if card_status & ERASE_PARAM.bits() != 0 { @@ -287,9 +298,13 @@ fn check_for_errors(card_status: u32) -> Result<(), Error> { } else if card_status & BLOCK_LEN_ERROR.bits() != 0 { Err(Error::CardError { t: BLOCK_LEN_ERROR }) } else if card_status & ADDRESS_MISALIGNED.bits() != 0 { - Err(Error::CardError { t: ADDRESS_MISALIGNED }) + Err(Error::CardError { + t: ADDRESS_MISALIGNED, + }) } else if card_status & ADDRESS_OUT_OF_RANGE.bits() != 0 { - Err(Error::CardError { t: ADDRESS_OUT_OF_RANGE }) + Err(Error::CardError { + t: ADDRESS_OUT_OF_RANGE, + }) } else { Err(Error::CardError { t: ERROR }) } diff --git a/src/sdram.rs b/src/sdram.rs index 0740ee7f..00c06854 100644 --- a/src/sdram.rs +++ b/src/sdram.rs @@ -1,7 +1,7 @@ -use board::rcc::Rcc; use board::fmc::Fmc; -use system_clock; +use board::rcc::Rcc; use embedded::interfaces::gpio::Gpio; +use system_clock; pub fn init(rcc: &mut Rcc, fmc: &mut Fmc, gpio: &mut Gpio) { config_pins(gpio); @@ -79,9 +79,9 @@ pub fn init(rcc: &mut Rcc, fmc: &mut Fmc, gpio: &mut Gpio) { } fn config_pins(gpio: &mut Gpio) { - use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; - use embedded::interfaces::gpio::Port::*; use embedded::interfaces::gpio::Pin::*; + use embedded::interfaces::gpio::Port::*; + use embedded::interfaces::gpio::{AlternateFunction, OutputSpeed, OutputType, Resistor}; let sdclk = (PortG, Pin8); let sdcke0 = (PortC, Pin3); @@ -124,44 +124,8 @@ fn config_pins(gpio: &mut Gpio) { let sdnwe = (PortH, Pin5); let pins = [ - sdclk, - sdcke0, - sdcke1, - sdne0, - sdne1, - a0, - a1, - a2, - a3, - a4, - a5, - a6, - a7, - a8, - a9, - a10, - a11, - a12, - d0, - d1, - d2, - d3, - d4, - d5, - d6, - d7, - d8, - d9, - d10, - d11, - d12, - d13, - d14, - d15, - ba0, - ba1, - nras, - ncas, + sdclk, sdcke0, sdcke1, sdne0, sdne1, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, + d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, ba0, ba1, nras, ncas, sdnwe, ]; gpio.to_alternate_function_all( diff --git a/src/system_clock.rs b/src/system_clock.rs index 5530e6ae..71c870de 100644 --- a/src/system_clock.rs +++ b/src/system_clock.rs @@ -1,6 +1,6 @@ -use board::rcc::Rcc; -use board::pwr::Pwr; use board::flash::Flash; +use board::pwr::Pwr; +use board::rcc::Rcc; use cortex_m::peripheral; use core::sync::atomic::{AtomicUsize, Ordering}; @@ -108,7 +108,6 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) { // FIXME: Frequency should not exceed 90 MHz rcc.cfgr.update(|r| r.set_ppre2(DIVIDE_2)); - let systick = unsafe { peripheral::syst_mut() }; let pll_cfgr = rcc.pllcfgr.read(); diff --git a/src/touch.rs b/src/touch.rs index c7603d13..37071130 100644 --- a/src/touch.rs +++ b/src/touch.rs @@ -1,5 +1,5 @@ -use i2c::{self, I2C}; use arrayvec::ArrayVec; +use i2c::{self, I2C}; const FT5336_ADDRESS: i2c::Address = i2c::Address::bits_7(0b0111000); const FT5336_FAMILY_ID_REGISTER: u8 = 0xA8; From ee92fb45924b43631db011906ea64f9ee83da573 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 27 Apr 2018 13:23:49 +0200 Subject: [PATCH 3/4] Add dependency on new HAL crate --- Cargo.lock | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 1 + 3 files changed, 113 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ff1db7ed..38edf297 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,8 @@ +[[package]] +name = "aligned" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "alloc-cortex-m" version = "0.3.3" @@ -16,6 +21,11 @@ dependencies = [ "odds 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bare-metal" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bit_field" version = "0.4.0" @@ -54,6 +64,36 @@ dependencies = [ "volatile-register 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cortex-m" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aligned 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aligned 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "untagged-option 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m-rt" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "embedded" version = "0.3.0" @@ -65,6 +105,14 @@ dependencies = [ "volatile 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "embedded-hal" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "embedded_stm32f7" version = "0.1.0" @@ -86,6 +134,11 @@ name = "managed" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "nb" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "nodrop" version = "0.1.12" @@ -106,6 +159,11 @@ name = "r0" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "r0" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rusttype" version = "0.2.1" @@ -138,6 +196,27 @@ dependencies = [ "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "stm32f7" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "stm32f746-hal" +version = "0.1.0" +source = "git+https://github.com/embed-rs/stm32f746-hal.git?branch=wip#7778f01c869bd481e592780c35a566dacce35501" +dependencies = [ + "cortex-m 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "stm32f7 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "stm32f7_discovery" version = "0.1.0" @@ -153,9 +232,20 @@ dependencies = [ "rusttype 0.2.1 (git+https://github.com/phil-opp/rusttype.git?branch=no_std)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", "spin 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "stm32f746-hal 0.1.0 (git+https://github.com/embed-rs/stm32f746-hal.git?branch=wip)", "volatile 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "untagged-option" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "vcell" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "volatile" version = "0.2.4" @@ -166,9 +256,19 @@ name = "volatile-register" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "volatile-register" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] +"checksum aligned 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0211cd15e6a84c97c3815bd8808e499b490ca386cf9beaf1985f49d5e3ef0f38" "checksum alloc-cortex-m 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369232e925bf5c087dce1a6ee01157509671ebfc64047d56a8b1bc5dec4f5304" "checksum arrayvec 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)" = "06f59fe10306bb78facd90d28c2038ad23ffaaefa85bac43c8a434cde383334f" +"checksum bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eda0f54b2d49f18f3867a5e6d458299bb886db6e64c34d319d6b1aa0839ac31c" "checksum bit_field 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c7f2626c064227bf8d383b35223f8ac9b7d33a7999f7bd9a5b5e491583061f6" "checksum bit_field 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2f2608c2dbf1057804d86937a32731a17458a60b10e83ad91c1c35c36e522f5d" "checksum bit_field 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff91a64014e1bc53bf643920f2c9ab5f0980d92a0948295f3ee550e9266849ad" @@ -176,17 +276,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" "checksum cortex-m 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "de9b334d0778b1ace2dfb63672594d0c0db093a3924617ad4e2f1669d32832dc" +"checksum cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d553ca1f23403c81e6d3d28a64ef6e8eadd7f395195aacda65cbc0dc987738e" +"checksum cortex-m 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2864dd1e83344abe7a6192befbeb8cd88bf763cfc560e28680d5b06a8ce9b7f7" +"checksum cortex-m-rt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6d8cc476060aa9c17d3b2ed883652b1ab691e19410847322ef095532b4dbea" "checksum embedded 0.3.0 (git+https://github.com/embed-rs/embedded-rs.git)" = "" +"checksum embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "684b1fa3196f78342296d04edc2a6e5d053729d1b64a819dcb072810d706e267" "checksum embedded_stm32f7 0.1.0 (git+https://github.com/embed-rs/embedded_stm32f7.git)" = "" "checksum linked_list_allocator 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1ee3eeeadfa301cf51b59684c034ad47a9796d03a8b70650d46b6b400a4a3258" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" +"checksum nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "69f380b5fe9fab8c0d7a6a99cda23e2cc0463bedb2cbc3aada0813b98496ecdc" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum odds 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "4eae0151b9dacf24fcc170d9995e511669a082856a91f958a2fe380bfab3fb22" "checksum once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "931fb7a4cf34610cf6cbe58d52a8ca5ef4c726d4e2e178abd0dc13a6551c6d73" "checksum r0 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1627d705506f5bf4c16126c4f85cd8c59d45c151f2aef890b45bdd4a91ca152f" +"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" "checksum rusttype 0.2.1 (git+https://github.com/phil-opp/rusttype.git?branch=no_std)" = "" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum spin 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dc28a8d2f2efa706fc9d3d074e265c1d529db41c1603679861662cb88e05e70a" "checksum stb_truetype 0.2.1 (git+https://github.com/phil-opp/stb_truetype-rs.git)" = "" +"checksum stm32f7 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "737c789bdb8aee6fb571ab319b2c31b4272739ac472124078d14b69c2b58075e" +"checksum stm32f746-hal 0.1.0 (git+https://github.com/embed-rs/stm32f746-hal.git?branch=wip)" = "" +"checksum untagged-option 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89553f60895e868761e18120e72077da22920614562d2f4fe98fa707fbb12fe6" +"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d" "checksum volatile 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "54d4343a2df2d65144a874f95950754ee7b7e8594f6027aae8c7d0f4858a3fe8" "checksum volatile-register 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a470889aa8f2d3ad893bd43cd90c824e63e8ac0ee5fe64c5d81a932d184fd549" +"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/Cargo.toml b/Cargo.toml index 0152fac2..4362f396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ volatile = "0.2.1" rusttype = {git = "https://github.com/phil-opp/rusttype.git", branch = "no_std"} alloc-cortex-m = "0.3.3" bitflags = "0.7.0" +stm32f746-hal = {git = "https://github.com/embed-rs/stm32f746-hal.git", branch = "wip"} [dependencies.arrayvec] default-features = false diff --git a/src/main.rs b/src/main.rs index 04e6e392..5d095df1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ #[macro_use] extern crate stm32f7_discovery as stm32f7; +extern crate stm32f746_hal as hal; // initialization routines for .data and .bss From 470e0a560a63fe00d177bf47c8f1f1f3088d494d Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 27 Apr 2018 14:24:14 +0200 Subject: [PATCH 4/4] Pass HAL peripherals struct to main --- Cargo.lock | 2 +- src/main.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38edf297..b9f20914 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,7 +210,7 @@ dependencies = [ [[package]] name = "stm32f746-hal" version = "0.1.0" -source = "git+https://github.com/embed-rs/stm32f746-hal.git?branch=wip#7778f01c869bd481e592780c35a566dacce35501" +source = "git+https://github.com/embed-rs/stm32f746-hal.git?branch=wip#ffdb8d9a729086619e5c507e22a647398bc0af6f" dependencies = [ "cortex-m 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/main.rs b/src/main.rs index 5d095df1..a6142900 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ use smoltcp::socket::{UdpPacketMetadata, UdpSocket, UdpSocketBuffer}; use smoltcp::time::Instant; use smoltcp::wire::{EthernetAddress, IpAddress, IpEndpoint, Ipv4Address}; use stm32f7::{audio, board, embedded, ethernet, i2c, lcd, sd, sdram, system_clock, touch}; +use hal::stm32f7::stm32f7x6::Peripherals; pub const ETH_ADDR: EthernetAddress = EthernetAddress([0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef]); pub const IP_ADDR: Ipv4Address = Ipv4Address([141, 52, 46, 198]); @@ -50,12 +51,12 @@ pub unsafe extern "C" fn reset() -> ! { scb.cpacr.modify(|v| v | 0b1111 << 20); asm!("DSB; ISB;"::::"volatile"); // pipeline flush - main(board::hw()); + main(board::hw(), hal::take_peripherals().unwrap()); } // WORKAROUND: rust compiler will inline & reorder fp instructions into #[inline(never)] // reset() before the FPU is initialized -fn main(hw: board::Hardware) -> ! { +fn main(hw: board::Hardware, peripherals: Peripherals) -> ! { use alloc::Vec; use embedded::interfaces::gpio::{self, Gpio};