2
2
#![ no_main]
3
3
4
4
extern crate panic_itm;
5
- use cortex_m:: iprintln;
5
+ use cortex_m:: { iprintln, iprint } ;
6
6
7
7
use cortex_m_rt:: entry;
8
8
use embedded_hal:: digital:: v2:: OutputPin ;
@@ -39,7 +39,7 @@ fn main() -> ! {
39
39
let mut itm = cp. ITM ;
40
40
let stim0 = & mut itm. stim [ 0 ] ;
41
41
42
- iprintln ! ( stim0,
42
+ iprintln ! ( stim0,
43
43
"Eth TX Pinging on STM32-F407 via NIC100/ENC424J600" ) ;
44
44
45
45
// NIC100 / ENC424J600 Set-up
@@ -57,33 +57,33 @@ fn main() -> ! {
57
57
spisel. set_low ( ) . unwrap ( ) ;
58
58
// Create SPI1 for HAL
59
59
let spi_eth_port = Spi :: spi1 (
60
- spi1, ( spi1_sck, spi1_miso, spi1_mosi) ,
60
+ spi1, ( spi1_sck, spi1_miso, spi1_mosi) ,
61
61
enc424j600:: spi:: interfaces:: SPI_MODE ,
62
62
Hertz ( enc424j600:: spi:: interfaces:: SPI_CLOCK_FREQ ) ,
63
63
clocks) ;
64
64
let mut spi_eth = enc424j600:: SpiEth :: new ( spi_eth_port, spi1_nss) ;
65
65
// Init
66
66
match spi_eth. init_dev ( & mut delay) {
67
67
Ok ( _) => {
68
- iprintln ! ( stim0, "Ethernet initialised. " )
68
+ iprintln ! ( stim0, "Ethernet initialized " )
69
69
}
70
70
Err ( _) => {
71
- panic ! ( "Ethernet initialisation Failed !" )
71
+ panic ! ( "Ethernet initialization failed !" )
72
72
}
73
73
}
74
74
75
75
// Read MAC
76
76
let mut eth_mac_addr: [ u8 ; 6 ] = [ 0 ; 6 ] ;
77
77
spi_eth. read_from_mac ( & mut eth_mac_addr) ;
78
- iprintln ! ( stim0 ,
79
- "MAC Address = {:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}" ,
80
- eth_mac_addr [ 0 ] , eth_mac_addr [ 1 ] ,
81
- eth_mac_addr [ 2 ] , eth_mac_addr [ 3 ] ,
82
- eth_mac_addr [ 4 ] , eth_mac_addr [ 5 ] ) ;
83
- // Set to promiscuous mode
84
- spi_eth . set_promiscuous ( ) ;
85
- iprintln ! ( stim0 ,
86
- "Promiscuous Mode ON" ) ;
78
+ for i in 0 .. 6 {
79
+ let byte = eth_mac_addr [ i ] ;
80
+ match i {
81
+ 0 => iprint ! ( stim0 , "MAC Address = {:02x}-" , byte ) ,
82
+ 1 ..= 4 => iprint ! ( stim0 , "{:02x}-" , byte ) ,
83
+ 5 => iprint ! ( stim0 , "{:02x} \n " , byte ) ,
84
+ _ => ( )
85
+ } ;
86
+ }
87
87
88
88
// Init Rx/Tx buffers
89
89
spi_eth. init_rxbuf ( ) ;
@@ -102,26 +102,23 @@ fn main() -> ! {
102
102
loop {
103
103
let mut eth_tx_packet = enc424j600:: tx:: TxPacket :: new ( ) ;
104
104
eth_tx_packet. update_frame ( & eth_tx_dat, 64 ) ;
105
- iprintln ! ( stim0,
106
- "Sending packet (len={:}): \
107
- dest={:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x} \
108
- src={:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x} \
109
- data={:02x}{:02x}{:02x}{:02x} {:02x}{:02x}{:02x}{:02x} ..." ,
110
- eth_tx_packet . get_frame_length ( ) ,
111
- eth_tx_packet . get_frame_byte ( 0 ) , eth_tx_packet . get_frame_byte ( 1 ) , eth_tx_packet . get_frame_byte ( 2 ) ,
112
- eth_tx_packet . get_frame_byte ( 3 ) , eth_tx_packet . get_frame_byte ( 4 ) , eth_tx_packet . get_frame_byte ( 5 ) ,
113
- eth_tx_packet . get_frame_byte ( 6 ) , eth_tx_packet . get_frame_byte ( 7 ) , eth_tx_packet . get_frame_byte ( 8 ) ,
114
- eth_tx_packet . get_frame_byte ( 9 ) , eth_tx_packet . get_frame_byte ( 10 ) , eth_tx_packet . get_frame_byte ( 11 ) ,
115
- eth_tx_packet . get_frame_byte ( 12 ) , eth_tx_packet . get_frame_byte ( 13 ) ,
116
- eth_tx_packet . get_frame_byte ( 14 ) , eth_tx_packet . get_frame_byte ( 15 ) ,
117
- eth_tx_packet . get_frame_byte ( 16 ) , eth_tx_packet . get_frame_byte ( 17 ) ,
118
- eth_tx_packet . get_frame_byte ( 18 ) , eth_tx_packet . get_frame_byte ( 19 )
119
- ) ;
105
+ iprint ! ( stim0,
106
+ "Sending packet (len={:}): " , eth_tx_packet . get_frame_length ( ) ) ;
107
+ for i in 0 .. 20 {
108
+ let byte = eth_tx_packet . get_frame_byte ( i ) ;
109
+ match i {
110
+ 0 => iprint ! ( stim0 , "dest={:02x}-" , byte ) ,
111
+ 6 => iprint ! ( stim0 , "src={:02x}-" , byte ) ,
112
+ 12 => iprint ! ( stim0 , "data={:02x}" , byte ) ,
113
+ 1 ..= 4 | 7 ..= 10 => iprint ! ( stim0 , "{:02x}-" , byte ) ,
114
+ 13 ..= 14 | 16 ..= 18 => iprint ! ( stim0 , "{:02x}" , byte ) ,
115
+ 5 | 11 | 15 => iprint ! ( stim0 , "{:02x} " , byte ) ,
116
+ 19 => iprint ! ( stim0 , "{:02x} ... \n " , byte ) ,
117
+ _ => ( )
118
+ } ;
119
+ }
120
120
spi_eth. send_raw_packet ( & eth_tx_packet) ;
121
- iprintln ! ( stim0,
122
- "Packet sent" ) ;
121
+ iprintln ! ( stim0, "Packet sent" ) ;
123
122
delay. delay_ms ( 100_u32 ) ;
124
123
}
125
-
126
- unreachable ! ( )
127
124
}
0 commit comments