@@ -185,6 +185,12 @@ pub enum ConfigError {
185
185
RxOrTxNotEnabled ,
186
186
/// Data bits and parity combination not supported
187
187
DataParityNotSupported ,
188
+ /// DE assertion time too high
189
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
190
+ DeAssertionTimeTooHigh ,
191
+ /// DE deassertion time too high
192
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
193
+ DeDeassertionTimeTooHigh ,
188
194
}
189
195
190
196
#[ non_exhaustive]
@@ -251,6 +257,14 @@ pub struct Config {
251
257
/// Set the pin configuration for the DE pin.
252
258
pub de_config : OutputConfig ,
253
259
260
+ /// Set DE assertion time before the first start bit, 0-31 16ths of a bit period.
261
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
262
+ pub de_assertion_time : u8 ,
263
+
264
+ /// Set DE deassertion time after the last stop bit, 0-31 16ths of a bit period.
265
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
266
+ pub de_deassertion_time : u8 ,
267
+
254
268
// private: set by new_half_duplex, not by the user.
255
269
duplex : Duplex ,
256
270
}
@@ -296,6 +310,8 @@ impl Default for Config {
296
310
tx_config : OutputConfig :: PushPull ,
297
311
rts_config : OutputConfig :: PushPull ,
298
312
de_config : OutputConfig :: PushPull ,
313
+ de_assertion_time : 0 ,
314
+ de_deassertion_time : 0 ,
299
315
duplex : Duplex :: Full ,
300
316
}
301
317
}
@@ -1706,6 +1722,16 @@ fn configure(
1706
1722
return Err ( ConfigError :: RxOrTxNotEnabled ) ;
1707
1723
}
1708
1724
1725
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
1726
+ let dem = r. cr3 ( ) . read ( ) . dem ( ) ;
1727
+
1728
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
1729
+ if config. de_assertion_time > 31 {
1730
+ return Err ( ConfigError :: DeAssertionTimeTooHigh ) ;
1731
+ } else if config. de_deassertion_time > 31 {
1732
+ return Err ( ConfigError :: DeDeassertionTimeTooHigh ) ;
1733
+ }
1734
+
1709
1735
// UART must be disabled during configuration.
1710
1736
r. cr1 ( ) . modify ( |w| {
1711
1737
w. set_ue ( false ) ;
@@ -1754,6 +1780,20 @@ fn configure(
1754
1780
w. set_re ( enable_rx) ;
1755
1781
}
1756
1782
1783
+ #[ cfg( not( any( usart_v1, usart_v2) ) ) ]
1784
+ if dem {
1785
+ w. set_deat ( if over8 {
1786
+ config. de_assertion_time / 2
1787
+ } else {
1788
+ config. de_assertion_time
1789
+ } ) ;
1790
+ w. set_dedt ( if over8 {
1791
+ config. de_assertion_time / 2
1792
+ } else {
1793
+ config. de_assertion_time
1794
+ } ) ;
1795
+ }
1796
+
1757
1797
// configure word size and parity, since the parity bit is inserted into the MSB position,
1758
1798
// it increases the effective word size
1759
1799
match ( config. parity , config. data_bits ) {
0 commit comments