@@ -293,31 +293,6 @@ impl<const RXC: usize, const TXC: usize> SpiPeripheral<RXC, TXC> {
293293 }
294294 }
295295
296- /// Load some data into the TX buffer.
297- ///
298- /// You get an error if you try to load too much.
299- pub fn set_transmit ( & mut self , data : & [ u8 ] ) -> Result < ( ) , usize > {
300- self . tx_ready = 0 ;
301- self . tx_idx = 0 ;
302- if data. len ( ) > TXC {
303- // Too much data. This check is important for safety in
304- // [`Self::tx_isr`].
305- return Err ( TXC ) ;
306- }
307- for ( inc, space) in data. iter ( ) . zip ( self . tx_buffer . iter_mut ( ) ) {
308- * space = * inc;
309- }
310- // We must never set this to be longer than `TXC` as we do an unchecked
311- // read from `self.tx_buffer` in [`Self::tx_isr`].
312- self . tx_ready = data. len ( ) ;
313- // Turn on the TX interrupt
314- self . dev . cr2 . write ( |w| {
315- w. txeie ( ) . not_masked ( ) ;
316- w
317- } ) ;
318- Ok ( ( ) )
319- }
320-
321296 /// Render some message into the TX buffer.
322297 ///
323298 /// You get an error if you try to load too much.
@@ -328,11 +303,14 @@ impl<const RXC: usize, const TXC: usize> SpiPeripheral<RXC, TXC> {
328303 self . tx_ready = 0 ;
329304 self . tx_idx = 0 ;
330305
331- match message. render_to_buffer ( & mut self . tx_buffer ) {
306+ // SPI FIFO seems to corrupt the first byte we load. So load a dummy one
307+ // we don't care about.
308+ self . tx_buffer [ 0 ] = 0xFF ;
309+ match message. render_to_buffer ( & mut self . tx_buffer [ 1 ..] ) {
332310 Ok ( n) => {
333311 // We must never set this to be longer than `TXC` as we do an
334312 // unchecked read from `self.tx_buffer` in [`Self::tx_isr`].
335- self . tx_ready = n . min ( TXC ) ;
313+ self . tx_ready = ( n + 1 ) . min ( TXC ) ;
336314 // Turn on the TX interrupt
337315 self . dev . cr2 . write ( |w| {
338316 w. txeie ( ) . not_masked ( ) ;
0 commit comments