33If you wrote your program like this:
44
55``` rust
6- #![no_main]
7- #![no_std]
8-
9- #[allow(unused_imports)]
10- use aux11 :: {entry, iprint, iprintln};
11-
12- #[entry]
13- fn main () -> ! {
14- let (usart1 , mono_timer , itm ) = aux11 :: init ();
15-
16- // Send a string
17- for byte in b " The quick brown fox jumps over the lazy dog." . iter () {
18- usart1
19- . tdr
20- . write (| w | unsafe { w . tdr (). bits (u16 :: from (* byte )) });
21- }
22-
23- loop {}
24- }
6+ {{#include examples / buffer - overrun . rs}}
257```
268
279You probably received something like this on your computer when you executed the program compiled in
@@ -60,33 +42,7 @@ We can actually time how long it takes to execute the `for` loop. `aux11::init()
6042` std::time ` .
6143
6244``` rust
63- #![deny(unsafe_code)]
64- #![no_main]
65- #![no_std]
66-
67- #[allow(unused_imports)]
68- use aux11 :: {entry, iprint, iprintln};
69-
70- #[entry]
71- fn main () -> ! {
72- let (usart1 , mono_timer , mut itm ) = aux11 :: init ();
73-
74- let instant = mono_timer . now ();
75- // Send a string
76- for byte in b " The quick brown fox jumps over the lazy dog." . iter () {
77- usart1 . tdr. write (| w | w . tdr (). bits (u16 :: from (* byte )));
78- }
79- let elapsed = instant . elapsed (); // in ticks
80-
81- iprintln! (
82- & mut itm . stim[0 ],
83- " `for` loop took {} ticks ({} us)" ,
84- elapsed ,
85- elapsed as f32 / mono_timer . frequency (). 0 as f32 * 1e 6
86- );
87-
88- loop {}
89- }
45+ {{#include examples / buffer - overrun - timed . rs}}
9046```
9147
9248In debug mode, I get:
@@ -109,37 +65,7 @@ to write to the `TDR` register without incurring in data loss.
10965Let's use that to slowdown the processor.
11066
11167``` rust
112- #![no_main]
113- #![no_std]
114-
115- #[allow(unused_imports)]
116- use aux11 :: {entry, iprint, iprintln};
117-
118- #[entry]
119- fn main () -> ! {
120- let (usart1 , mono_timer , mut itm ) = aux11 :: init ();
121-
122- let instant = mono_timer . now ();
123- // Send a string
124- for byte in b " The quick brown fox jumps over the lazy dog." . iter () {
125- // wait until it's safe to write to TDR
126- while usart1 . isr. read (). txe (). bit_is_clear () {} // <- NEW!
127-
128- usart1
129- . tdr
130- . write (| w | unsafe { w . tdr (). bits (u16 :: from (* byte )) });
131- }
132- let elapsed = instant . elapsed (); // in ticks
133-
134- iprintln! (
135- & mut itm . stim[0 ],
136- " `for` loop took {} ticks ({} us)" ,
137- elapsed ,
138- elapsed as f32 / mono_timer . frequency (). 0 as f32 * 1e 6
139- );
140-
141- loop {}
142- }
68+ {{#include examples / buffer - overrun - txe . rs}}
14369```
14470
14571This time, running the program in debug or release mode should result in a complete string on the
0 commit comments