@@ -509,7 +509,7 @@ static int send_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
509509 nrfe_mspi_opcode_t opcode = (packet -> dir == MSPI_RX ) ? NRFE_MSPI_TXRX : NRFE_MSPI_TX ;
510510
511511#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
512- /* Check for alignment problems. */
512+ /* In case of buffer alignment problems: create correctly aligned temporary buffer . */
513513 uint32_t len = ((uint32_t )packet -> data_buf ) % sizeof (uint32_t ) != 0
514514 ? sizeof (nrfe_mspi_xfer_packet_msg_t ) + packet -> num_bytes
515515 : sizeof (nrfe_mspi_xfer_packet_msg_t );
@@ -525,10 +525,14 @@ static int send_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
525525 xfer_packet -> num_bytes = packet -> num_bytes ;
526526
527527#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
528- /* Check for alignlemt problems. */
528+ /* In case of buffer alignment problems: fill temporary buffer with TX data and
529+ * set it as packet data.
530+ */
529531 if (((uint32_t )packet -> data_buf ) % sizeof (uint32_t ) != 0 ) {
530- memcpy ((void * )(buffer + sizeof (nrfe_mspi_xfer_packet_msg_t )),
531- (void * )packet -> data_buf , packet -> num_bytes );
532+ if (packet -> dir == MSPI_TX ) {
533+ memcpy ((void * )(buffer + sizeof (nrfe_mspi_xfer_packet_msg_t )),
534+ (void * )packet -> data_buf , packet -> num_bytes );
535+ }
532536 xfer_packet -> data = buffer + sizeof (nrfe_mspi_xfer_packet_msg_t );
533537 } else {
534538 xfer_packet -> data = packet -> data_buf ;
@@ -540,20 +544,39 @@ static int send_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
540544 rc = send_data (xfer_packet -> opcode , xfer_packet , len );
541545
542546 /* Wait for the transfer to complete and receive data. */
543- if ((packet -> dir == MSPI_RX ) && (ipc_receive_buffer != NULL ) && (ipc_received > 0 )) {
544- /*
545- * It is not possible to check whether received data is valid, so packet->num_bytes
546- * should always be equal to ipc_received. If it is not, then something went wrong.
547+ if (packet -> dir == MSPI_RX ) {
548+
549+ /* In case of CONFIG_MSPI_NRFE_IPC_NO_COPY ipc_received if equal to 0 because
550+ * packet buffer address was passed to vpr and data was written directly there.
551+ * So there is no way of checking how much data was written.
552+ */
553+ #ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
554+ /* In case of buffer alignment problems: copy received data from temporary buffer
555+ * back to users buffer.
547556 */
548- if (packet -> num_bytes != ipc_received ) {
549- rc = - EIO ;
550- } else {
551- memcpy ((void * )packet -> data_buf , (void * )ipc_receive_buffer , ipc_received );
557+ if (((uint32_t )packet -> data_buf ) % sizeof (uint32_t ) != 0 ) {
558+ memcpy ((void * )packet -> data_buf , (void * )xfer_packet -> data ,
559+ packet -> num_bytes );
552560 }
561+ #else
562+ if ((ipc_receive_buffer != NULL ) && (ipc_received > 0 )) {
563+ /*
564+ * It is not possible to check whether received data is valid, so
565+ * packet->num_bytes should always be equal to ipc_received. If it is not,
566+ * then something went wrong.
567+ */
568+ if (packet -> num_bytes != ipc_received ) {
569+ rc = - EIO ;
570+ } else {
571+ memcpy ((void * )packet -> data_buf , (void * )ipc_receive_buffer ,
572+ ipc_received );
573+ }
553574
554- /* Clear the receive buffer pointer and size */
555- ipc_receive_buffer = NULL ;
556- ipc_received = 0 ;
575+ /* Clear the receive buffer pointer and size */
576+ ipc_receive_buffer = NULL ;
577+ ipc_received = 0 ;
578+ }
579+ #endif
557580 }
558581
559582 return rc ;
0 commit comments