rustfmt, squash warnings, add bmp support
This commit is contained in:
parent
dab73c3fec
commit
7e314410a0
|
@ -1,5 +1,5 @@
|
|||
[target.thumbv7em-none-eabihf]
|
||||
runner = "gdb -q -x openocd.gdb"
|
||||
runner = "gdb -batch -q -x bmp.gdb"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
]
|
||||
|
|
|
@ -683,7 +683,6 @@ checksum = "72165c4af59f5f19c7fb774b88b95660591b612380305b5f4503157341a9f7ee"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"log",
|
||||
"managed",
|
||||
]
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ nb = "1"
|
|||
cortex-m-log = { version = "0.7.0", features = ["log-integration", "semihosting"] }
|
||||
stm32f4xx-hal = { version = "0.13.2", features = ["rt", "stm32f407", "usb_fs", "rtic-monotonic"] }
|
||||
stm32-eth = { git = "https://github.com/stm32-rs/stm32-eth", features = ["stm32f407", "smoltcp-phy", "smoltcp"] }
|
||||
smoltcp = { version = "0.8.1", default-features = false, features = ["proto-ipv4", "socket-tcp", "log", "medium-ethernet"] }
|
||||
smoltcp = { version = "0.8.1", default-features = false, features = ["proto-ipv4", "socket-tcp", "medium-ethernet"] }
|
||||
ieee802_3_miim = "0.7.2"
|
||||
num-traits = { version = "0.2.15", default-features = false, features = ["libm"] }
|
||||
usb-device = "0.2.9"
|
||||
|
@ -35,6 +35,7 @@ cortex-m-rtic = "1.0.0"
|
|||
systick-monotonic = "1.0.0"
|
||||
|
||||
[features]
|
||||
default = ["RTT"]
|
||||
semihosting = ["cortex-m-log/semihosting"]
|
||||
RTT = []
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
target extended-remote /dev/ttyBmpGdb
|
||||
monitor swdp_scan
|
||||
attach 1
|
||||
load
|
||||
compare-sections
|
||||
kill
|
|
@ -66,7 +66,7 @@
|
|||
buildInputs = with pkgs; [
|
||||
rustPlatform.rust.rustc
|
||||
rustPlatform.rust.cargo
|
||||
openocd dfu-util glibc
|
||||
openocd dfu-util glibc picocom gdb
|
||||
] ++ (with python3Packages; [
|
||||
numpy matplotlib pyqtgraph
|
||||
]);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use super::{gpio, usb, delay};
|
||||
use super::{delay, gpio, usb};
|
||||
use crate::laser_diode::current_sources::*;
|
||||
use smoltcp::iface::{SocketHandle, Interface};
|
||||
use stm32_eth::stm32::ETHERNET_DMA;
|
||||
use systick_monotonic::Systick;
|
||||
use crate::network::network;
|
||||
use crate::network::network::EthernetPeripherals;
|
||||
use fugit::ExtU32;
|
||||
use log::info;
|
||||
use stm32f4xx_hal::{
|
||||
|
@ -11,15 +10,22 @@ use stm32f4xx_hal::{
|
|||
time::MegaHertz,
|
||||
watchdog::IndependentWatchdog,
|
||||
};
|
||||
use crate::network::network;
|
||||
use crate::network::network::EthernetPeripherals;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[cfg(not(feature = "semihosting"))]
|
||||
const WATCHDOG_PERIOD: u32 = 1000;
|
||||
#[cfg(feature = "semihosting")]
|
||||
const WATCHDOG_PERIOD: u32 = 30000;
|
||||
|
||||
pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals, server_storage: &'static mut network::ServerStorage) -> (IndependentWatchdog, Systick<1000_u32>, network::ServerHandle) {
|
||||
pub fn bootup(
|
||||
mut core_perif: CorePeripherals,
|
||||
perif: Peripherals,
|
||||
server_storage: &'static mut network::ServerStorage,
|
||||
) -> (
|
||||
IndependentWatchdog,
|
||||
Systick<1000_u32>,
|
||||
network::ServerHandle,
|
||||
) {
|
||||
core_perif.SCB.enable_icache();
|
||||
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
|
||||
|
||||
|
@ -43,7 +49,6 @@ pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals, server_storag
|
|||
perif.GPIOB,
|
||||
perif.GPIOC,
|
||||
perif.GPIOD,
|
||||
perif.GPIOG,
|
||||
perif.SPI2,
|
||||
perif.OTG_FS_GLOBAL,
|
||||
perif.OTG_FS_DEVICE,
|
||||
|
|
|
@ -2,9 +2,9 @@ use crate::laser_diode::current_sources::*;
|
|||
use fugit::RateExtU32;
|
||||
use stm32_eth::EthPins;
|
||||
use stm32f4xx_hal::{
|
||||
gpio::{GpioExt, AF11, Speed, Alternate},
|
||||
gpio::{Alternate, GpioExt, Speed},
|
||||
otg_fs::USB,
|
||||
pac::{GPIOA, GPIOB, GPIOC, GPIOD, GPIOG, OTG_FS_DEVICE, OTG_FS_GLOBAL, OTG_FS_PWRCLK, SPI2},
|
||||
pac::{GPIOA, GPIOB, GPIOC, GPIOD, OTG_FS_DEVICE, OTG_FS_GLOBAL, OTG_FS_PWRCLK, SPI2},
|
||||
rcc::Clocks,
|
||||
spi,
|
||||
spi::{NoMiso, Spi},
|
||||
|
@ -18,7 +18,6 @@ pub fn setup(
|
|||
gpiob: GPIOB,
|
||||
gpioc: GPIOC,
|
||||
gpiod: GPIOD,
|
||||
gpiog: GPIOG,
|
||||
spi2: SPI2,
|
||||
otg_fs_global: OTG_FS_GLOBAL,
|
||||
otg_fs_device: OTG_FS_DEVICE,
|
||||
|
@ -28,15 +27,13 @@ pub fn setup(
|
|||
USB,
|
||||
CurrentSourcePhyConstruct<CurrentSourcePhyCh0>,
|
||||
stm32f4xx_hal::gpio::PA2<Alternate<11>>,
|
||||
stm32f4xx_hal::gpio::PC1<Alternate<11>>
|
||||
// photo_diode_phy,
|
||||
// thermostat_phy
|
||||
stm32f4xx_hal::gpio::PC1<Alternate<11>>, // photo_diode_phy,
|
||||
// thermostat_phy
|
||||
) {
|
||||
let gpioa = gpioa.split();
|
||||
let gpiob = gpiob.split();
|
||||
let gpioc = gpioc.split();
|
||||
let gpiod = gpiod.split();
|
||||
let gpiog = gpiog.split();
|
||||
|
||||
let usb = USB {
|
||||
usb_global: otg_fs_global,
|
||||
|
@ -62,7 +59,6 @@ pub fn setup(
|
|||
mdio.set_speed(Speed::VeryHigh);
|
||||
mdc.set_speed(Speed::VeryHigh);
|
||||
|
||||
|
||||
let current_source_phy = CurrentSourcePhyConstruct {
|
||||
max5719_spi: Spi::new(
|
||||
spi2,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pub mod boot;
|
||||
pub mod delay;
|
||||
pub mod gpio;
|
||||
pub mod log_setup;
|
||||
pub mod rtt_logger;
|
||||
pub mod delay;
|
||||
pub mod usb;
|
||||
|
|
|
@ -3,7 +3,7 @@ use stm32f4xx_hal::{
|
|||
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Output, PushPull, PD9},
|
||||
hal::{blocking::spi::Write, digital::v2::OutputPin},
|
||||
pac::SPI2,
|
||||
spi::{NoMiso, Spi, TransferModeNormal}
|
||||
spi::{NoMiso, Spi, TransferModeNormal},
|
||||
};
|
||||
|
||||
pub trait CurrentSourcePhy {
|
||||
|
@ -43,7 +43,7 @@ impl CurrentSourcePhy for CurrentSourcePhyCh0 {
|
|||
use crate::device::delay;
|
||||
|
||||
impl<C: CurrentSourcePhy> CurrentSource<C> {
|
||||
pub fn setup(&mut self, mut delay : delay::AsmDelay) {
|
||||
pub fn setup(&mut self, mut delay: delay::AsmDelay) {
|
||||
let _ = self.phy.max5719_load.set_high();
|
||||
let _ = self.phy.max5719_cs.set_high();
|
||||
let _ = self.phy.current_source_ldo_en.set_high();
|
||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -8,10 +8,7 @@ mod network;
|
|||
|
||||
// If RTT is used, print panic info through RTT
|
||||
#[cfg(feature = "RTT")]
|
||||
use {
|
||||
core::panic::PanicInfo,
|
||||
rtt_target::rprintln,
|
||||
};
|
||||
use {core::panic::PanicInfo, rtt_target::rprintln};
|
||||
#[cfg(feature = "RTT")]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
|
@ -26,33 +23,24 @@ use panic_halt as _;
|
|||
#[app(device = stm32f4xx_hal::pac, peripherals = true, dispatchers = [TIM8_CC, TIM8_BRK_TIM12])]
|
||||
mod app {
|
||||
|
||||
use log::info;
|
||||
use stm32_eth::stm32::ETHERNET_DMA;
|
||||
use systick_monotonic::Systick;
|
||||
use fugit::ExtU32;
|
||||
use stm32f4xx_hal::watchdog::IndependentWatchdog;
|
||||
use crate::device::{boot::bootup, log_setup};
|
||||
use smoltcp::iface::{SocketHandle, Interface};
|
||||
use crate::network::network;
|
||||
|
||||
fn now_fn() -> smoltcp::time::Instant {
|
||||
let time = monotonics::now().duration_since_epoch().to_millis();
|
||||
smoltcp::time::Instant::from_millis(time as i64)
|
||||
}
|
||||
use fugit::ExtU32;
|
||||
use log::info;
|
||||
use stm32f4xx_hal::watchdog::IndependentWatchdog;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type SystickTimer = Systick<1000>;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
||||
}
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
wd: IndependentWatchdog,
|
||||
// server_storage: network::network::ServerStorage::new(),
|
||||
server_handle: network::ServerHandle
|
||||
server_handle: network::ServerHandle,
|
||||
}
|
||||
|
||||
#[init( local = [server_storage: network::ServerStorage = network::ServerStorage::new()] )]
|
||||
|
@ -67,11 +55,15 @@ mod app {
|
|||
|
||||
wd_feed::spawn().unwrap();
|
||||
// server_poll::spawn().unwrap();
|
||||
(Shared {}, Local {wd, server_handle}, init::Monotonics(systick))
|
||||
(
|
||||
Shared {},
|
||||
Local { wd, server_handle },
|
||||
init::Monotonics(systick),
|
||||
)
|
||||
}
|
||||
|
||||
#[task(priority = 5, local = [wd])]
|
||||
fn wd_feed (cx: wd_feed::Context) {
|
||||
fn wd_feed(cx: wd_feed::Context) {
|
||||
let start = monotonics::now();
|
||||
let wd = cx.local.wd;
|
||||
// info!("feed wd");
|
||||
|
@ -80,7 +72,7 @@ mod app {
|
|||
}
|
||||
|
||||
#[task(binds = ETH, priority = 2, local = [server_handle, data: [u8; 512] = [0u8; 512]])]
|
||||
fn server_poll (cx: server_poll::Context) {
|
||||
fn server_poll(cx: server_poll::Context) {
|
||||
let data = cx.local.data;
|
||||
let server_handle = cx.local.server_handle;
|
||||
server_handle.poll(data);
|
||||
|
@ -93,6 +85,4 @@ mod app {
|
|||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,34 @@
|
|||
use fugit::Instant;
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, SocketHandle, Interface, SocketStorage};
|
||||
use smoltcp::socket::{TcpSocket, TcpSocketBuffer, self, Socket};
|
||||
use smoltcp::storage::RingBuffer;
|
||||
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
|
||||
use stm32f4xx_hal::gpio::{gpioa::*, gpiob::*, gpioc::*, gpiog::*, Input};
|
||||
use stm32_eth::{EthPins, TxDescriptor, RxDescriptor, EthernetMAC};
|
||||
use stm32_eth::stm32::{ETHERNET_DMA, ETHERNET_MAC, ETHERNET_MMC};
|
||||
use stm32_eth::RingEntry;
|
||||
use stm32_eth::TxRingEntry;
|
||||
use stm32_eth::RxRingEntry;
|
||||
use stm32f4xx_hal::rcc::Clocks;
|
||||
use smoltcp::iface::Neighbor;
|
||||
use stm32_eth::*;
|
||||
use log::{info, warn, debug};
|
||||
use smoltcp::iface::Route;
|
||||
use smoltcp::wire::Ipv4Cidr;
|
||||
use stm32f4xx_hal::gpio::Alternate;
|
||||
// Modified by Wong Tat Hang (aw@m-labs.hk), with original source from
|
||||
// https://github.com/stm32-rs/stm32-eth/blob/master/examples/rtic-echo.rs
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use log::{info, warn};
|
||||
use smoltcp::{
|
||||
iface::{self},
|
||||
socket::{TcpState},
|
||||
iface::{
|
||||
Interface, InterfaceBuilder, Neighbor, NeighborCache, Route, SocketHandle, SocketStorage,
|
||||
},
|
||||
socket::{TcpSocket, TcpSocketBuffer, TcpState},
|
||||
wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr},
|
||||
};
|
||||
use stm32_eth::stm32::{ETHERNET_DMA, ETHERNET_MAC, ETHERNET_MMC};
|
||||
use stm32_eth::*;
|
||||
use stm32f4xx_hal::{
|
||||
gpio::{gpioa::*, gpiob::*, gpioc::*, Alternate, Input},
|
||||
rcc::Clocks,
|
||||
};
|
||||
|
||||
|
||||
use crate::app::monotonics::{self, now};
|
||||
|
||||
use crate::app::monotonics;
|
||||
|
||||
pub type EthernetPins =
|
||||
EthPins<PA1<Input>, PA7<Input>, PB11<Input>, PB12<Input>, PB13<Input>, PC4<Input>, PC5<Input>>;
|
||||
|
@ -31,8 +36,16 @@ pub type EthernetPins =
|
|||
pub type EthInterface = Interface<'static, &'static mut EthernetDMA<'static, 'static>>;
|
||||
|
||||
const IPV4_ADDR: (u8, u8, u8, u8) = (192, 168, 1, 132);
|
||||
const ADDRESS: (IpAddress, u16) = (IpAddress::Ipv4(Ipv4Address::new(IPV4_ADDR.0, IPV4_ADDR.1,IPV4_ADDR.2,IPV4_ADDR.3)), 1337);
|
||||
const MAC: [u8; 6] = [0x02,0x5f,0x25,0x37,0x93,0x0e];
|
||||
const ADDRESS: (IpAddress, u16) = (
|
||||
IpAddress::Ipv4(Ipv4Address::new(
|
||||
IPV4_ADDR.0,
|
||||
IPV4_ADDR.1,
|
||||
IPV4_ADDR.2,
|
||||
IPV4_ADDR.3,
|
||||
)),
|
||||
1337,
|
||||
);
|
||||
const MAC: [u8; 6] = [0x02, 0x5f, 0x25, 0x37, 0x93, 0x0e];
|
||||
pub struct EthernetPeripherals {
|
||||
pub dma: ETHERNET_DMA,
|
||||
pub mac: ETHERNET_MAC,
|
||||
|
@ -42,7 +55,7 @@ pub struct EthernetPeripherals {
|
|||
pub struct ServerHandle {
|
||||
// storage: &'static mut ServerStorage,
|
||||
socket_handle: SocketHandle,
|
||||
iface: EthInterface
|
||||
iface: EthInterface,
|
||||
}
|
||||
|
||||
pub struct ServerStorage {
|
||||
|
@ -55,8 +68,17 @@ pub struct ServerStorage {
|
|||
impl ServerStorage {
|
||||
pub const fn new() -> Self {
|
||||
ServerStorage {
|
||||
rx_ring: [RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new(),RxRingEntry::new()],
|
||||
tx_ring: [TxRingEntry::new(),TxRingEntry::new()],
|
||||
rx_ring: [
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
RxRingEntry::new(),
|
||||
],
|
||||
tx_ring: [TxRingEntry::new(), TxRingEntry::new()],
|
||||
storage: NetworkStorage::new(),
|
||||
dma: core::mem::MaybeUninit::uninit(),
|
||||
}
|
||||
|
@ -73,8 +95,10 @@ pub struct NetworkStorage {
|
|||
}
|
||||
|
||||
impl NetworkStorage {
|
||||
const IP_INIT: IpCidr =
|
||||
IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address::new(IPV4_ADDR.0, IPV4_ADDR.1,IPV4_ADDR.2,IPV4_ADDR.3), 24));
|
||||
const IP_INIT: IpCidr = IpCidr::Ipv4(Ipv4Cidr::new(
|
||||
Ipv4Address::new(IPV4_ADDR.0, IPV4_ADDR.1, IPV4_ADDR.2, IPV4_ADDR.3),
|
||||
24,
|
||||
));
|
||||
|
||||
pub const fn new() -> Self {
|
||||
NetworkStorage {
|
||||
|
@ -109,16 +133,14 @@ fn now_fn() -> smoltcp::time::Instant {
|
|||
}
|
||||
|
||||
impl ServerHandle {
|
||||
|
||||
pub fn new(
|
||||
eth_pins: EthernetPins,
|
||||
ethernet: EthernetPeripherals,
|
||||
clocks: Clocks,
|
||||
storage: &'static mut ServerStorage,
|
||||
mdio: stm32f4xx_hal::gpio::PA2<Alternate<11>>,
|
||||
mdc: stm32f4xx_hal::gpio::PC1<Alternate<11>>
|
||||
mdc: stm32f4xx_hal::gpio::PC1<Alternate<11>>,
|
||||
) -> ServerHandle {
|
||||
|
||||
let (dma, mac) = stm32_eth::new_with_mii(
|
||||
ethernet.mac,
|
||||
ethernet.mmc,
|
||||
|
@ -128,7 +150,7 @@ impl ServerHandle {
|
|||
clocks,
|
||||
eth_pins,
|
||||
mdio,
|
||||
mdc
|
||||
mdc,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -137,12 +159,13 @@ impl ServerHandle {
|
|||
.add_default_ipv4_route(Ipv4Address::new(192, 168, 1, 1))
|
||||
.ok();
|
||||
|
||||
|
||||
let dma = storage.dma.write(dma);
|
||||
dma.enable_interrupt();
|
||||
|
||||
let rx_buffer = TcpSocketBuffer::new(&mut storage.storage.tcp_socket_storage.rx_storage[..]);
|
||||
let tx_buffer = TcpSocketBuffer::new(&mut storage.storage.tcp_socket_storage.tx_storage[..]);
|
||||
let rx_buffer =
|
||||
TcpSocketBuffer::new(&mut storage.storage.tcp_socket_storage.rx_storage[..]);
|
||||
let tx_buffer =
|
||||
TcpSocketBuffer::new(&mut storage.storage.tcp_socket_storage.tx_storage[..]);
|
||||
let socket = TcpSocket::new(rx_buffer, tx_buffer);
|
||||
|
||||
let mut iface = InterfaceBuilder::new(dma, &mut storage.storage.sockets[..])
|
||||
|
@ -153,11 +176,11 @@ impl ServerHandle {
|
|||
.finalize();
|
||||
let mut server = ServerHandle {
|
||||
socket_handle: iface.add_socket(socket),
|
||||
iface: iface
|
||||
iface: iface,
|
||||
};
|
||||
let socket = server.iface.get_socket::<TcpSocket>(server.socket_handle);
|
||||
socket.listen(ADDRESS).ok();
|
||||
server.iface.poll(now_fn());
|
||||
server.iface.poll(now_fn()).ok();
|
||||
if let Ok(mut phy) = EthernetPhy::from_miim(mac, 0) {
|
||||
info!(
|
||||
"Resetting PHY as an extra step. Type: {}",
|
||||
|
@ -173,11 +196,6 @@ impl ServerHandle {
|
|||
}
|
||||
|
||||
pub fn poll(&mut self, buffer: &mut [u8]) {
|
||||
|
||||
// info!("poll eth");
|
||||
let interrupt_reason = self.iface.device_mut().interrupt_handler();
|
||||
// debug!("Reason: {:?}", interrupt_reason);
|
||||
|
||||
self.iface.poll(now_fn()).ok();
|
||||
|
||||
let socket = self.iface.get_socket::<TcpSocket>(self.socket_handle);
|
||||
|
@ -195,11 +213,9 @@ impl ServerHandle {
|
|||
}
|
||||
|
||||
self.iface.poll(now_fn()).ok();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
use ieee802_3_miim::{
|
||||
phy::{
|
||||
lan87xxa::{LAN8720A, LAN8742A},
|
||||
|
|
Loading…
Reference in New Issue