@@ -48,7 +48,7 @@ mod app {
48
48
} ,
49
49
mac:: Speed ,
50
50
ptp:: { EthernetPTP , Timestamp } ,
51
- Parts ,
51
+ Parts , MTU ,
52
52
} ;
53
53
54
54
#[ local]
@@ -65,19 +65,27 @@ mod app {
65
65
#[ monotonic( binds = SysTick , default = true ) ]
66
66
type Monotonic = Systick < 1000 > ;
67
67
68
- #[ init( local = [
69
- rx_desc: [ RxDescriptor ; 2 ] = [ RxDescriptor :: new( ) ; 2 ] ,
70
- tx_desc: [ TxDescriptor ; 2 ] = [ TxDescriptor :: new( ) ; 2 ] ,
71
- rx_buffers: [ [ u8 ; 1522 ] ; 2 ] = [ [ 0u8 ; stm32_eth:: MTU ] ; 2 ] ,
72
- tx_buffers: [ [ u8 ; 1522 ] ; 2 ] = [ [ 0u8 ; stm32_eth:: MTU ] ; 2 ] ,
73
- ] ) ]
68
+ /// On H7s, the ethernet DMA does not have access to the normal ram
69
+ /// so we must explicitly put them in SRAM.
70
+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
71
+ static mut TX_DESCRIPTORS : [ TxDescriptor ; 4 ] = [ TxDescriptor :: new ( ) ; 4 ] ;
72
+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
73
+ static mut TX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
74
+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
75
+ static mut RX_DESCRIPTORS : [ RxDescriptor ; 4 ] = [ RxDescriptor :: new ( ) ; 4 ] ;
76
+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
77
+ static mut RX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
78
+
79
+ #[ init]
74
80
fn init ( cx : init:: Context ) -> ( Shared , Local , init:: Monotonics ) {
75
81
defmt:: info!( "Pre-init" ) ;
76
82
let core = cx. core ;
77
83
let p = cx. device ;
78
84
79
- let rx_ring = RxDescriptorRing :: new ( cx. local . rx_desc , cx. local . rx_buffers ) ;
80
- let tx_ring = TxDescriptorRing :: new ( cx. local . tx_desc , cx. local . tx_buffers ) ;
85
+ let rx_ring =
86
+ RxDescriptorRing :: new ( unsafe { & mut RX_DESCRIPTORS } , unsafe { & mut RX_BUFFERS } ) ;
87
+ let tx_ring =
88
+ TxDescriptorRing :: new ( unsafe { & mut TX_DESCRIPTORS } , unsafe { & mut TX_BUFFERS } ) ;
81
89
82
90
let ( clocks, gpio, ethernet) = crate :: common:: setup_peripherals ( p) ;
83
91
let mono = Systick :: new ( core. SYST , clocks. hclk ( ) . raw ( ) ) ;
@@ -88,13 +96,15 @@ mod app {
88
96
defmt:: info!( "Configuring ethernet" ) ;
89
97
90
98
let Parts { dma, mac, mut ptp } =
91
- stm32_eth:: new_with_mii ( ethernet, rx_ring, tx_ring, clocks, pins, mdio , mdc ) . unwrap ( ) ;
99
+ stm32_eth:: new ( ethernet, rx_ring, tx_ring, clocks, pins) . unwrap ( ) ;
92
100
101
+ #[ cfg( not( feature = "stm32h7xx-hal" ) ) ]
93
102
ptp. enable_pps ( pps) ;
94
103
95
104
defmt:: info!( "Enabling interrupts" ) ;
96
105
dma. enable_interrupt ( ) ;
97
106
107
+ #[ cfg( not( feature = "stm32h7xx-hal" ) ) ]
98
108
match EthernetPhy :: from_miim ( mac, 0 ) {
99
109
Ok ( mut phy) => {
100
110
defmt:: info!(
@@ -151,14 +161,15 @@ mod app {
151
161
// incorrect, but works well enough in low-activity systems (such as this example).
152
162
let now = ( cx. shared . ptp , cx. shared . scheduled_time ) . lock ( |ptp, sched_time| {
153
163
let now = ptp. get_time ( ) ;
154
- #[ cfg( not( feature = "stm32f107" ) ) ]
164
+ #[ cfg( not( any ( feature = "stm32f107" , feature = "stm32h7xx-hal" ) ) ) ]
155
165
{
156
166
let in_half_sec = now
157
167
+ Timestamp :: new (
158
168
false ,
159
169
0 ,
160
170
stm32_eth:: ptp:: Subseconds :: new_from_nanos ( 500_000_000 ) . unwrap ( ) ,
161
171
) ;
172
+
162
173
ptp. configure_target_time_interrupt ( in_half_sec) ;
163
174
}
164
175
* sched_time = Some ( now) ;
@@ -201,7 +212,7 @@ mod app {
201
212
. lock ( |dma, tx_id, ptp, _sched_time| {
202
213
dma. interrupt_handler ( ) ;
203
214
204
- #[ cfg( not( feature = "stm32f107" ) ) ]
215
+ #[ cfg( not( any ( feature = "stm32f107" , feature = "stm32h7xx-hal" ) ) ) ]
205
216
{
206
217
if ptp. interrupt_handler ( ) {
207
218
if let Some ( sched_time) = _sched_time. take ( ) {
0 commit comments