title: SPI with DMA transfer between two STM32 chips results in reordered data in struct
body: <p>Using HAL with two chips: <code>STM32F373RBT6</code> and <code>STM32F042K6T6</code>. <code>SPI</code> with <code>DMA</code> is set up on both.</p>
  
  <p>I use the following struct in the code for each processor:</p>
  
  <pre class="lang-c prettyprint-override"><code>typedef __packed struct {
      u16 command;
      u16 status;
      s32 motorPos;
  
  } motorParams;
  </code></pre>
  
  <p>In debug (ST-LINK), I can see the first packet come in correctly, and then the bytes change order in the struct. All the data is there, it's just in the wrong order.</p>
  
  <p>Example:</p>
  
  <p><img src="https://i.stack.imgur.com/5ZTLh.png" alt="first packet received">, </p>
  
  <p>the command is one for motor enable, and then on the next packet: </p>
  
  <p><img src="https://i.stack.imgur.com/FXk0X.png" alt="second packet received">, </p>
  
  <p>the enable shows up in the position field. And finally, </p>
  
  <p><img src="https://i.stack.imgur.com/8m0Ga.png" alt="final packet received">, </p>
  
  <p>the position is now divided up between the command and status fields.</p>
  
  <p>I have checked the output on the SPI bus on the oscope, looking at the chip select and data signals. All the data is there and in the correct order going into the M0 chip.</p>
  
  <p>Receiving in the <code>M0</code>, the SPI has a pointer directly to a variable to receive the struct.</p>
  
  <p>Is there any intermediate checks I can do to see why the data is changing location within the struct?
  Thank you.</p>