@@ -198,7 +198,9 @@ void sender(void *arg)
198198 data_ready = get_tx_data (send_buf [descriptor_id ], send_buf_size , & ready_data_size );
199199 if (data_ready ) {
200200 slave_trans [descriptor_id ].data = send_buf [descriptor_id ];
201- slave_trans [descriptor_id ].len = ready_data_size ;
201+ slave_trans [descriptor_id ].len = send_buf_size ;
202+ //To use dma, data buffer address and trans_len should byte align to hardware requirement, or using following flag for auto deal by driver.
203+ slave_trans [descriptor_id ].flags |= SPI_SLAVE_HD_TRANS_DMA_BUFFER_ALIGN_AUTO ;
202204 //Due to the `queue_sent_cnt` and `queue_recv_cnt` logic above, we are sure there is space to send data, this will return ESP_OK immediately
203205 ESP_ERROR_CHECK (spi_slave_hd_queue_trans (SLAVE_HOST , SPI_SLAVE_CHAN_TX , & slave_trans [descriptor_id ], portMAX_DELAY ));
204206 descriptor_id = (descriptor_id + 1 ) % QUEUE_SIZE ; //descriptor_id will be: 0, 1, 2, ..., QUEUE_SIZE, 0, 1, ....
@@ -234,7 +236,7 @@ void receiver(void *arg)
234236 uint8_t * recv_buf [QUEUE_SIZE ];
235237 spi_slave_hd_data_t slave_trans [QUEUE_SIZE ];
236238 for (int i = 0 ; i < QUEUE_SIZE ; i ++ ) {
237- recv_buf [i ] = heap_caps_calloc ( 1 , recv_buf_size , MALLOC_CAP_DMA );
239+ recv_buf [i ] = spi_bus_dma_memory_alloc ( SLAVE_HOST , recv_buf_size , MALLOC_CAP_8BIT );
238240 if (!recv_buf [i ]) {
239241 ESP_LOGE (TAG , "No enough memory!" );
240242 abort ();
@@ -249,6 +251,7 @@ void receiver(void *arg)
249251 for (int i = 0 ; i < QUEUE_SIZE ; i ++ ) {
250252 slave_trans [descriptor_id ].data = recv_buf [descriptor_id ];
251253 slave_trans [descriptor_id ].len = recv_buf_size ;
254+ slave_trans [descriptor_id ].flags |= SPI_SLAVE_HD_TRANS_DMA_BUFFER_ALIGN_AUTO ;
252255 ESP_ERROR_CHECK (spi_slave_hd_queue_trans (SLAVE_HOST , SPI_SLAVE_CHAN_RX , & slave_trans [descriptor_id ], portMAX_DELAY ));
253256 descriptor_id = (descriptor_id + 1 ) % QUEUE_SIZE ; //descriptor_id will be: 0, 1, 2, ..., QUEUE_SIZE, 0, 1, ....
254257 }
@@ -266,7 +269,6 @@ void receiver(void *arg)
266269 */
267270 ESP_ERROR_CHECK (spi_slave_hd_get_trans_res (SLAVE_HOST , SPI_SLAVE_CHAN_RX , & ret_trans , portMAX_DELAY ));
268271 //Process the received data in your own code. Here we just print it out.
269- printf ("%d bytes are received: \n%s\n" , ret_trans -> trans_len , ret_trans -> data );
270272 memset (ret_trans -> data , 0x0 , recv_buf_size );
271273
272274 /**
@@ -288,10 +290,10 @@ void app_main(void)
288290 uint8_t init_value [SOC_SPI_MAXIMUM_BUFFER_SIZE ] = {0x0 };
289291 spi_slave_hd_write_buffer (SLAVE_HOST , 0 , init_value , SOC_SPI_MAXIMUM_BUFFER_SIZE );
290292
291- static uint32_t send_buf_size = 5000 ;
293+ static uint32_t send_buf_size = 4800 ;
292294 spi_slave_hd_write_buffer (SLAVE_HOST , SLAVE_MAX_TX_BUF_LEN_REG , (uint8_t * )& send_buf_size , sizeof (send_buf_size ));
293295
294- static uint32_t recv_buf_size = 120 ;
296+ static uint32_t recv_buf_size = 128 ;
295297 spi_slave_hd_write_buffer (SLAVE_HOST , SLAVE_MAX_RX_BUF_LEN_REG , (uint8_t * )& recv_buf_size , sizeof (recv_buf_size ));
296298
297299 uint32_t slave_ready_flag = SLAVE_READY_FLAG ;
0 commit comments