]> granicus.if.org Git - esp-idf/commitdiff
fix(spi_dma): fix the receive error with RX DMA start with non-aligned address.
authormichael <xiaoxufeng@espressif.com>
Tue, 15 Aug 2017 04:46:21 +0000 (12:46 +0800)
committermichael <xiaoxufeng@espressif.com>
Fri, 18 Aug 2017 02:14:49 +0000 (10:14 +0800)
components/driver/include/driver/spi_master.h
components/driver/spi_master.c

index 04f4c069944d26f6987a4dd0be8cab55b8acb167..099f3b7573cd6cb6254647294e7a0a16d254f346 100644 (file)
@@ -86,7 +86,7 @@ struct spi_transaction_t {
         void *rx_buffer;            ///< Pointer to receive buffer, or NULL for no MISO phase. Written by 4 bytes-unit if DMA is used.
         uint8_t rx_data[4];         ///< If SPI_USE_RXDATA is set, data is received directly to this variable
     };
-};
+} ;        //the rx data should start from a 32-bit aligned address to get around dma issue.
 
 
 typedef struct spi_device_t* spi_device_handle_t;  ///< Handle for a device on a SPI bus
index e6175ebae9579d8418720b2111eaf3ab9c336264..0e42be78f7d6af69c1871009557c11a8f45a81b1 100644 (file)
@@ -603,7 +603,7 @@ esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *
         //if not use RXDATA neither rx_buffer, buffer_to_rcv assigned to NULL
         trans_buf.buffer_to_rcv = trans_desc->rx_buffer;
     }
-    if ( trans_buf.buffer_to_rcv && handle->host->dma_chan && !esp_ptr_dma_capable( trans_buf.buffer_to_rcv )) {
+    if ( trans_buf.buffer_to_rcv && handle->host->dma_chan && (!esp_ptr_dma_capable( trans_buf.buffer_to_rcv ) || ((int)trans_buf.buffer_to_rcv%4!=0)) ) {
         //if rxbuf in the desc not DMA-capable, malloc a new one
         trans_buf.buffer_to_rcv = heap_caps_malloc((trans_desc->rxlength+7)/8, MALLOC_CAP_DMA);
         if ( trans_buf.buffer_to_rcv==NULL ) return ESP_ERR_NO_MEM;