@@ -123,11 +123,19 @@ impl<T> Uarte<T> where T: Instance {
123
123
return Err ( Error :: TxBufferTooLong ) ;
124
124
}
125
125
126
+ if !crate :: slice_in_ram ( tx_buffer) {
127
+ return Err ( Error :: BufferNotInRAM ) ;
128
+ }
129
+
126
130
// Conservative compiler fence to prevent optimizations that do not
127
131
// take in to account actions by DMA. The fence has been placed here,
128
132
// before any DMA action has started
129
133
compiler_fence ( SeqCst ) ;
130
134
135
+ // Reset the events.
136
+ self . 0 . events_endtx . write ( |w| w) ;
137
+ self . 0 . events_txstopped . write ( |w| w) ;
138
+
131
139
// Set up the DMA write
132
140
self . 0 . txd . ptr . write ( |w|
133
141
// We're giving the register a pointer to the stack. Since we're
@@ -153,17 +161,22 @@ impl<T> Uarte<T> where T: Instance {
153
161
unsafe { w. bits ( 1 ) } ) ;
154
162
155
163
// Wait for transmission to end
156
- while self . 0 . events_endtx . read ( ) . bits ( ) == 0 { }
157
-
158
- // Reset the event, otherwise it will always read `1` from now on.
159
- self . 0 . events_endtx . write ( |w| w) ;
164
+ let mut endtx;
165
+ let mut txstopped;
166
+ loop {
167
+ endtx = self . 0 . events_endtx . read ( ) . bits ( ) != 0 ;
168
+ txstopped = self . 0 . events_txstopped . read ( ) . bits ( ) != 0 ;
169
+ if endtx || txstopped {
170
+ break ;
171
+ }
172
+ }
160
173
161
174
// Conservative compiler fence to prevent optimizations that do not
162
175
// take in to account actions by DMA. The fence has been placed here,
163
176
// after all possible DMA actions have completed
164
177
compiler_fence ( SeqCst ) ;
165
178
166
- if self . 0 . txd . amount . read ( ) . bits ( ) != tx_buffer . len ( ) as u32 {
179
+ if txstopped {
167
180
return Err ( Error :: Transmit ) ;
168
181
}
169
182
@@ -364,6 +377,7 @@ pub enum Error {
364
377
Transmit ,
365
378
Receive ,
366
379
Timeout ( usize ) ,
380
+ BufferNotInRAM ,
367
381
}
368
382
369
383
0 commit comments