10 byte offset when fetching a structure from a queue with xQueueReceiveFromISR()

Hello I have a project where I am collecting packets of data using an STM32F745 and then sending them via an SPI port to a master device (the mcu is an spi slave). When I receive the packets of data I place them into a buffer held within a structure, and place the structure in a queue. My SPI ISR retrieves the structures from the queue and copies them into a dma buffer ready for sending to the master device. The problem I have is that when I retrive the structure from the queue, the data appears to be offset by 8 bytes. I have looked at this page https://www.freertos.org/a00118.html for an example of how to queue a structure, but am still having problems. My structure is: ~~~

define INTERNALBUFFSIZE 248

typedef struct tSPIPacket {  uint8t flags;  uint8t checksum;  uint8t framecount;  uint8t frametime;  uint64_t timestamp;  uint8t size;    //size of structure, not amount of data  uint8t packetid;   //an id for the entire packet (large data split across transfers have same id)  uint8t xferid;   //id for transfer in packet (0=first transfer for packet, 1=second etc)  uint8t xfersize;  //number of data bytes in this transfer  uint32t totaldatasize;   //total amount of data in the packet  uint32t datatype;   //fourcc,  uint8t data[INTERNALBUFFSIZE]; } SPIPacket; extern SPIPacket SpiBuffer; extern SPIPacket *SpiBuffer2; ~~~ Then the code for creating the queue, and placing data onto the queue is: ~~~ spiqueue = xQueueCreate( 100, sizeof( SPIPacket  *) ); memcpy(SpiBuffer.data[0], , INTERNALBUFFSIZE);       // Fill out the packet header       SpiBuffer.flags = 0;       SpiBuffer.checksum = 0;       SpiBuffer.framecount = 1;       SpiBuffer.frametime = 1;       SpiBuffer.timestamp = 1;       SpiBuffer.size = sizeof(SPIPacket);       SpiBuffer.packetid = 0;       SpiBuffer.xferid = 0;       SpiBuffer.xfersize = INTERNALBUFFSIZE;       SpiBuffer.totaldatasize = INTERNALBUFFSIZE + sizeof(SPIPacket);       SpiBuffer.datatype =  FOURCC; &SpiBuffer, ( TickTypet ) 0 );       SPIPacket *spitmp=&SpiBuffer;       xQueueSend( spiqueue, ( void * ) spitmp, ( TickTypet ) 0 ); And the code for retriving the structures and placing them into the dma buffer is: // Arm the SPI and DMA to Tx bytes from aSPITxBuffer             if ( xQueueReceiveFromISR( spiqueue, ( void * ) &(SpiBuffer2), & xTaskWokenByReceive) )             {                 memset ( aSPITxBuffer, 0, 256 ); // ensure tx buffer is clear                 memcpy(&aSPITxBuffer[1], &SpiBuffer2, 256);                 HALSPITransmitReceiveDMA(&hspi5, (uint8t*)&aSPITxBuffer[0], (uint8t *)&aSPIRxBuffer[0], 256);                 return; // Return from he as we don’t want to be re armed for receive only             }             if ( xTaskWokenByReceive != pdFALSE )             {                 /* We should switch context so the ISR returns to a different task.                    NOTE:  How this is done depends on the port you are using.  Check                    the documentation and examples for your port. */                 HAL_SPI_Receive_DMA(&hspi5, (uint8_t *)aSPIRxBuffer, 7);                 taskYIELD ();             } ~~~ I am using the intermediate buffer aSPITxBuffer to make this issue easier to debug. Can someone please suggest why I’m getting the 8 byte offset when I retrieve Spi_Buffer2 from the queue please? Thanks in advance Andrew

10 byte offset when fetching a structure from a queue with xQueueReceiveFromISR()

Your memcpy call places the data at &aSPITxBUFFER[1], and then you send &aSPITxBuffer[0]. I don’t see a definition of the buffer, but that seems to be a possible source of an offset.

10 byte offset when fetching a structure from a queue with xQueueReceiveFromISR()

Hi Richard Thank you for your reply. The definition of the buffer is: ~~~ uint8_t aSPITxBuffer[282] = {0}; ~~~ The reson for the 1 byte offset with memcopy is because when the spi transfer is started, the first by of the buffer is droped by the master as it is clocked out with the write cycle. If I create a dummby buffer like the one below: ~~~ uint8_t aSPITestTxBuffer[21] = {0x00,0xDE,0xAD,0xBE,0xEF,0x60,0x0D,0xF0,0x0D,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x00}; ~~~ I can perform the same memcopy witht he 1 byte offset and the spi transfer works correctly. I.E: ~~~ memcpy(&aSPITxBuffer[1], &aSPITestTxBuffer, 21); HALSPITransmitReceiveDMA(&hspi5, (uint8t*)&aSPITxBuffer[0], (uint8_t *)&aSPIRxBuffer[0], 256); // 272 is the max no bytes the cavium can hadnle in 1 go ~~~ The problem is when I’m trying to retrive the data from the queue. Previosuly I have placed the output of the queue straight into the dma buffer, and I saw the same issue at the master. Andrew