From 60c82150599207e5bbf369e970df1db0f8a12a5d Mon Sep 17 00:00:00 2001 From: occheung Date: Mon, 7 Sep 2020 14:05:13 +0800 Subject: [PATCH] hal: upgrade to 0.7.1 --- Cargo.toml | 7 +++-- examples/ethernet.rs | 65 +++++++++++++++++++++-------------------- examples/mqtt_client.rs | 4 +-- examples/tcp_client.rs | 12 ++++---- src/nal_tcp_client.rs | 2 +- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffdb00f..8588ca1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,13 @@ panic-halt = "0.2.0" cortex-m = "0.6.2" cortex-m-rt = "0.6.12" embedded-hal = "0.2.4" -stm32h7xx-hal = {version = "0.6.0", features = [ "stm32h743v", "rt", "unproven" ] } -stm32h7-ethernet = { version = "0.2.0", features = [ "phy_lan8742a", "stm32h743v" ] } -smoltcp = { version = "0.6.0", default-features = false, features = [ "ethernet", "proto-ipv4", "proto-ipv6", "socket-raw" ] } +stm32h7xx-hal = {version = "0.7.1", features = [ "stm32h743v", "rt", "unproven", "ethernet", "phy_lan8742a" ] } +# stm32h7-ethernet = { version = "0.2.0", features = [ "phy_lan8742a", "stm32h743v" ] } +smoltcp = { version = "0.6.0", default-features = false, features = [ "ethernet", "proto-ipv4", "proto-ipv6", "socket-tcp" ] } nb = "1.0.0" # scpi = { path = "../scpi-fork/scpi", version = "0.3.4" } scpi = { git = "https://github.com/occheung/scpi-rs", branch = "issue-4" } +mashup = "0.1.12" lexical-core = { version="0.7.1", features=["radix"], default-features=false } libm = "0.2.0" diff --git a/examples/ethernet.rs b/examples/ethernet.rs index ee7d82b..1f227a3 100644 --- a/examples/ethernet.rs +++ b/examples/ethernet.rs @@ -21,8 +21,9 @@ use cortex_m_semihosting::hprintln; extern crate smoltcp; // Ethernet crate for STM32H7 has been merged into HAL in the latest commit -extern crate stm32h7_ethernet as ethernet; +// extern crate stm32h7_ethernet as ethernet; +use stm32h7xx_hal::ethernet; use stm32h7xx_hal::gpio::Speed; use stm32h7xx_hal::hal::digital::v2::{ OutputPin, @@ -34,16 +35,6 @@ use Speed::*; use libm::round; -/* -#[cfg(feature = "itm")] -use cortex_m_log::log::{trick_init, Logger}; - -#[cfg(feature = "itm")] -use cortex_m_log::{ - destination::Itm, printer::itm::InterruptSync as InterruptSyncItm, -}; -*/ - use core::{ str, fmt::Write @@ -76,7 +67,15 @@ use firmware::{ cpld::{ CPLD, }, - scpi::{ HelloWorldCommand, Channel1SwitchCommand}, + scpi::{ + HelloWorldCommand, + Channel0SwitchCommand, + Channel1SwitchCommand, + Channel2SwitchCommand, + Channel3SwitchCommand, + ClockSourceCommand, + ClockDivisionCommand, + }, Urukul, scpi_root, recursive_scpi_tree }; @@ -246,7 +245,7 @@ fn main() -> ! { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (_eth_dma, mut eth_mac) = unsafe { - ethernet::ethernet_init( + ethernet::new_unchecked( dp.ETHERNET_MAC, dp.ETHERNET_MTL, dp.ETHERNET_DMA, @@ -296,8 +295,27 @@ fn main() -> ! { // SCPI configs let tree = scpi_root!( - ["EXAMple"] => {"HELLO" => {"WORLD" => HelloWorldCommand}}; - "CHANNEL1" => {"SWitch" => Channel1SwitchCommand} + ["EXAMple"] => { + "HELLO" => { + "WORLD" => HelloWorldCommand + } + }, + "CHANNEL0" => { + "SWitch" => Channel0SwitchCommand + }, + "CHANNEL1" => { + "SWitch" => Channel1SwitchCommand + }, + "CHANNEL2" => { + "SWitch" => Channel2SwitchCommand + }, + "CHANNEL3" => { + "SWitch" => Channel3SwitchCommand + }, + "CLOCK" => { + "SOURCE" => ClockSourceCommand, + "DIVision" => ClockDivisionCommand + } ); // Device was declared in prior @@ -351,23 +369,6 @@ fn main() -> ! { }, }; - // Float rounding test socket (:6969) - { - let mut socket = sockets.get::(tcp1_handle); - if !socket.is_open() { - socket.listen(6969).unwrap(); - socket.set_timeout(Some(Duration::from_millis(5000))); - } - - if socket.can_recv() { - let data = socket.recv(|buffer| { - (buffer.len(), buffer) - }).unwrap(); - hprintln!("{:?}", data).unwrap(); - let result = lexical_core::parse_partial::(data).unwrap(); - writeln!(socket, "{}", round(result.0 * 2.0)); - } - } // SCPI interaction socket (:7000) { let mut socket = sockets.get::(silent_handle); diff --git a/examples/mqtt_client.rs b/examples/mqtt_client.rs index 8180ef6..b382e90 100644 --- a/examples/mqtt_client.rs +++ b/examples/mqtt_client.rs @@ -2,7 +2,7 @@ #![no_main] use smoltcp as net; -use stm32h7_ethernet as ethernet; +use stm32h7xx_hal::ethernet; use stm32h7xx_hal::{gpio::Speed, prelude::*, spi, pac}; use embedded_hal::{blocking::spi::Transfer}; @@ -103,7 +103,7 @@ fn main() -> ! { // Configure ethernet let mac_addr = net::wire::EthernetAddress([0xAC, 0x6F, 0x7A, 0xDE, 0xD6, 0xC8]); let (eth_dma, _eth_mac) = unsafe { - ethernet::ethernet_init( + ethernet::new_unchecked( dp.ETHERNET_MAC, dp.ETHERNET_MTL, dp.ETHERNET_DMA, diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index 381ee80..e8fd418 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -16,9 +16,7 @@ use cortex_m_semihosting::hprintln; extern crate smoltcp; -// Ethernet crate for STM32H7 has been merged into HAL in the latest commit -extern crate stm32h7_ethernet as ethernet; - +use stm32h7xx_hal::ethernet; use stm32h7xx_hal::gpio::Speed; use stm32h7xx_hal::hal::digital::v2::{ OutputPin, @@ -207,7 +205,7 @@ fn main() -> ! { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (_eth_dma, mut eth_mac) = unsafe { - ethernet::ethernet_init( + ethernet::new_unchecked( dp.ETHERNET_MAC, dp.ETHERNET_MTL, dp.ETHERNET_DMA, @@ -321,13 +319,13 @@ fn main() -> ! { { let mut socket = socket_set.get::(client_handle); - if !socket.is_open() || !socket.can_send() { + if !socket.is_open() { socket.abort(); socket.close(); - // hprintln!("reset state: {}", socket.state()).unwrap(); + hprintln!("reset state: {}", socket.state()).unwrap(); socket.connect((IpAddress::v4(192, 168, 1, 200), 1883), (IpAddress::Unspecified, 45000)).unwrap(); - // hprintln!("post connect state: {}", socket.state()).unwrap(); + hprintln!("post connect state: {}", socket.state()).unwrap(); } // hprintln!("client state: {}", socket.state()).unwrap(); diff --git a/src/nal_tcp_client.rs b/src/nal_tcp_client.rs index 6e9bf84..9c77341 100644 --- a/src/nal_tcp_client.rs +++ b/src/nal_tcp_client.rs @@ -3,7 +3,7 @@ use nb; use heapless::{consts, Vec}; -use stm32h7_ethernet as ethernet; +use stm32h7xx_hal::ethernet; use smoltcp as net; use cortex_m_semihosting::hprintln;