@@ -19,7 +19,7 @@ pub struct RegisterBlock {
19
19
pub acpr : RW < u32 > ,
20
20
reserved1 : [ u32 ; 55 ] ,
21
21
/// Selected Pin Control
22
- pub sppr : RW < u32 > ,
22
+ pub sppr : RW < Sppr > ,
23
23
reserved2 : [ u32 ; 132 ] ,
24
24
/// Formatter and Flush Control
25
25
pub ffcr : RW < Ffcr > ,
@@ -52,7 +52,16 @@ bitfield! {
52
52
nrzvalid, _: 11 ;
53
53
}
54
54
55
+ bitfield ! {
56
+ /// Selected pin protocol register.
57
+ #[ repr( C ) ]
58
+ #[ derive( Clone , Copy ) ]
59
+ pub struct Sppr ( u32 ) ;
60
+ u8 , txmode, set_txmode: 1 , 0 ;
61
+ }
62
+
55
63
/// The available protocols for the trace output.
64
+ #[ repr( u8 ) ]
56
65
pub enum TraceProtocol {
57
66
/// Parallel trace port mode
58
67
Parallel = 0b00 ,
@@ -61,6 +70,21 @@ pub enum TraceProtocol {
61
70
/// Asynchronous SWO, using NRZ encoding
62
71
AsyncSWONRZ = 0b10 ,
63
72
}
73
+ impl core:: convert:: TryFrom < u8 > for TraceProtocol {
74
+ type Error = ( ) ;
75
+
76
+ /// Tries to convert from a `TXMODE` field value. Fails if the set mode is
77
+ /// unknown (and thus unpredictable).
78
+ #[ inline]
79
+ fn try_from ( value : u8 ) -> Result < Self , Self :: Error > {
80
+ match value {
81
+ 0b00 => Ok ( Self :: Parallel ) ,
82
+ 0b01 => Ok ( Self :: AsyncSWOManchester ) ,
83
+ 0b10 => Ok ( Self :: AsyncSWONRZ ) ,
84
+ _ => Err ( ( ) ) , // unknown and unpredictable mode
85
+ }
86
+ }
87
+ }
64
88
65
89
/// The SWO options supported by the TPIU.
66
90
#[ allow( dead_code) ]
@@ -86,10 +110,25 @@ impl TPIU {
86
110
}
87
111
}
88
112
113
+ /// The used protocol for the trace output. Return `None` if an
114
+ /// unknown (and thus unpredicable mode) is configured by means
115
+ /// other than
116
+ /// [`trace_output_protocol`](Self::set_trace_output_protocol).
117
+ #[ inline]
118
+ pub fn trace_output_protocol ( & self ) -> Option < TraceProtocol > {
119
+ use core:: convert:: TryInto ;
120
+ self . sppr . read ( ) . txmode ( ) . try_into ( ) . ok ( )
121
+ }
122
+
89
123
/// Sets the used protocol for the trace output.
90
124
#[ inline]
91
125
pub fn set_trace_output_protocol ( & mut self , proto : TraceProtocol ) {
92
- unsafe { self . sppr . write ( proto as u32 ) }
126
+ unsafe {
127
+ self . sppr . modify ( |mut r| {
128
+ r. set_txmode ( proto as u8 ) ;
129
+ r
130
+ } ) ;
131
+ }
93
132
}
94
133
95
134
/// Whether to enable the formatter. If disabled, only ITM and DWT
0 commit comments