Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Embedded Ethernet driver in Rust

License

NotificationsYou must be signed in to change notification settings

stm32-rs/stm32-eth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supported microcontrollers

  • STM32F107
  • STM32F4xx
  • STM32F7xx

Pull requests are welcome :)

Usage

Add one of the following to the[dependencies] section in yourCargo.toml (with the correct MCU specified):

stm32-eth = {version ="0.6.0",features = ["stm32f429"] }# For stm32f4xx-like MCUsstm32-eth = {version ="0.6.0",features = ["stm32f767"] }# For stm32f7xx-like MCUsstm32-eth = {version ="0.6.0",features = ["stm32f107"] }# For stm32f107

stm32_eth re-exports the underlying HAL asstm32_eth::hal.

Insrc/main.rs add:

use stm32_eth::{    hal::gpio::GpioExt,    hal::rcc::RccExt,    stm32::Peripherals,    dma::{RxRingEntry,TxRingEntry},EthPins,};use fugit::RateExtU32;fnmain(){let p =Peripherals::take().unwrap();let rcc = p.RCC.constrain();// HCLK must be at least 25MHz to use the ethernet peripherallet clocks = rcc.cfgr.sysclk(32.MHz()).hclk(32.MHz()).freeze();let gpioa = p.GPIOA.split();let gpiob = p.GPIOB.split();let gpioc = p.GPIOC.split();let gpiog = p.GPIOG.split();let eth_pins =EthPins{ref_clk: gpioa.pa1,crs: gpioa.pa7,tx_en: gpiog.pg11,tx_d0: gpiog.pg13,tx_d1: gpiob.pb13,rx_d0: gpioc.pc4,rx_d1: gpioc.pc5,};letmut rx_ring:[RxRingEntry;16] =Default::default();letmut tx_ring:[TxRingEntry;8] =Default::default();let parts = stm32_eth::PartsIn{mac: p.ETHERNET_MAC,mmc: p.ETHERNET_MMC,dma: p.ETHERNET_DMA,ptp: p.ETHERNET_PTP,};let stm32_eth::Parts{dma:mut eth_dma,mac: _,ptp: _} = stm32_eth::new(        parts,&mut rx_ring[..],&mut tx_ring[..],        clocks,        eth_pins,).unwrap();    eth_dma.enable_interrupt();loop{ifletOk(pkt) = eth_dma.recv_next(None){// handle received pkt}let size =42;        eth_dma.send(size,None, |buf|{// write up to `size` bytes into buf before it is being sent}).expect("send");}}use stm32_eth::stm32::interrupt;#[interrupt]fnETH(){    stm32_eth::eth_interrupt_handler();}

smoltcp support

Use feature-flagsmoltcp-phy.

To make proper use ofsmoltcp, you will also have to activate additionalsmoltcp features. You can do this by adding a dependency on the same version ofsmoltcp asstm32-eth to your ownCargo.toml with the features you require activated.

Examples

The examples should run and compile on any MCU that has an 802.3 compatible PHY capable of generating the required 50 MHz clock signal connected to the default RMII pins.

The examples usedefmt anddefmt_rtt for logging, andpanic_probe overdefmt_rtt for printing panic backtraces.

Alternative pin configuration, HSE & PPS

If the board you're developing for has a High Speed External oscillator connected to the correct pins, the HSE configuration can be activated by setting theSTM32_ETH_EXAMPLE_HSE environment variable to one ofoscillator orbypass when compiling.

If the board you're developing for uses the nucleo pinout (PG11 and PG13 instead of PB11 and PB12), the pin configuration can be changed by setting theSTM32_ETH_EXAMPLE_PINS environment variable tonucleo when compiling.

If you wish to use the alternative PPS output pin (PG8 instead of PB5) for thertic-timestamp example, the pin configuration can be changed by setting theSTM32_ETH_EXAMPLE_PPS_PIN environment variable toalternate when compiling.

Building examples

To build an example, run the following command:

cargo build --release --example<example> \    --features<MCU feature>,<additional required features> \    --target<MCU compilation target>

For example, if we wish to build theip example for anstm32f429, we should run the following command:

cargo build --release --example ip \        --features stm32f429,smoltcp-phy \        --target thumbv7em-none-eabihf

If we wish to build thearp example for a Nucleo-F767ZI with a HSE oscillator:

STM32_ETH_EXAMPLE_HSE=bypass STM32_ETH_EXAMPLE_PINS=nucleo \cargo build --release --example arp \    --features stm32f767

Running examples

Installprobe-run withcargo install probe-run --version '~0.3'

Find the correct value forPROBE_RUN_CHIP for your MCU from the list provided byprobe-run --list-chips.

Ensure thatprobe-run can attach to your MCU

Then, run the following command:

DEFMT_LOG=info PROBE_RUN_CHIP=<probe-run chip> \cargo run --release --example<example> \    --features<MCU feature>,<additional required features> \    --target<MCU compilation target>

For example, if we wish to run thertic-echo example on anSTM32F107RCT6, we should run the following command:

DEFMT_LOG=info PROBE_RUN_CHIP=STM32F107RC \cargo run --release --example rtic-echo \    --features stm32f107,smoltcp-phy \    --target thumbv7m-none-eabi

Or, if we want to run thearp example on a Nucleo-F767ZI with a HSE oscillator:

DEFMT_LOG=info PROBE_RUN_CHIP=STM32F767ZGTx \STM32_ETH_EXAMPLE_PINS=nucleo STM32_ETH_EXAMPLE_HSE=oscillator \cargo run --release --example arp \    --features stm32f767 \    --target thumbv7em-none-eabihf

License

All source code (including code snippets) is licensed under the Apache License, Version 2.0 (LICENSE) orhttps://www.apache.org/licenses/LICENSE-2.0

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

About

Embedded Ethernet driver in Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors24

Languages


[8]ページ先頭

©2009-2025 Movatter.jp