mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(driver_spi): fixed slave example error on esp32p4
This commit is contained in:
@@ -198,7 +198,9 @@ void sender(void *arg)
|
||||
data_ready = get_tx_data(send_buf[descriptor_id], send_buf_size, &ready_data_size);
|
||||
if (data_ready) {
|
||||
slave_trans[descriptor_id].data = send_buf[descriptor_id];
|
||||
slave_trans[descriptor_id].len = ready_data_size;
|
||||
slave_trans[descriptor_id].len = send_buf_size;
|
||||
//To use dma, data buffer address and trans_len should byte align to hardware requirement, or using following flag for auto deal by driver.
|
||||
slave_trans[descriptor_id].flags |= SPI_SLAVE_HD_TRANS_DMA_BUFFER_ALIGN_AUTO;
|
||||
//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
|
||||
ESP_ERROR_CHECK(spi_slave_hd_queue_trans(SLAVE_HOST, SPI_SLAVE_CHAN_TX, &slave_trans[descriptor_id], portMAX_DELAY));
|
||||
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)
|
||||
uint8_t *recv_buf[QUEUE_SIZE];
|
||||
spi_slave_hd_data_t slave_trans[QUEUE_SIZE];
|
||||
for (int i = 0; i < QUEUE_SIZE; i++) {
|
||||
recv_buf[i] = heap_caps_calloc(1, recv_buf_size, MALLOC_CAP_DMA);
|
||||
recv_buf[i] = spi_bus_dma_memory_alloc(SLAVE_HOST, recv_buf_size, MALLOC_CAP_8BIT);
|
||||
if (!recv_buf[i]) {
|
||||
ESP_LOGE(TAG, "No enough memory!");
|
||||
abort();
|
||||
@@ -249,6 +251,7 @@ void receiver(void *arg)
|
||||
for (int i = 0; i < QUEUE_SIZE; i++) {
|
||||
slave_trans[descriptor_id].data = recv_buf[descriptor_id];
|
||||
slave_trans[descriptor_id].len = recv_buf_size;
|
||||
slave_trans[descriptor_id].flags |= SPI_SLAVE_HD_TRANS_DMA_BUFFER_ALIGN_AUTO;
|
||||
ESP_ERROR_CHECK(spi_slave_hd_queue_trans(SLAVE_HOST, SPI_SLAVE_CHAN_RX, &slave_trans[descriptor_id], portMAX_DELAY));
|
||||
descriptor_id = (descriptor_id + 1) % QUEUE_SIZE; //descriptor_id will be: 0, 1, 2, ..., QUEUE_SIZE, 0, 1, ....
|
||||
}
|
||||
@@ -266,7 +269,6 @@ void receiver(void *arg)
|
||||
*/
|
||||
ESP_ERROR_CHECK(spi_slave_hd_get_trans_res(SLAVE_HOST, SPI_SLAVE_CHAN_RX, &ret_trans, portMAX_DELAY));
|
||||
//Process the received data in your own code. Here we just print it out.
|
||||
printf("%d bytes are received: \n%s\n", ret_trans->trans_len, ret_trans->data);
|
||||
memset(ret_trans->data, 0x0, recv_buf_size);
|
||||
|
||||
/**
|
||||
@@ -288,10 +290,10 @@ void app_main(void)
|
||||
uint8_t init_value[SOC_SPI_MAXIMUM_BUFFER_SIZE] = {0x0};
|
||||
spi_slave_hd_write_buffer(SLAVE_HOST, 0, init_value, SOC_SPI_MAXIMUM_BUFFER_SIZE);
|
||||
|
||||
static uint32_t send_buf_size = 5000;
|
||||
static uint32_t send_buf_size = 4800;
|
||||
spi_slave_hd_write_buffer(SLAVE_HOST, SLAVE_MAX_TX_BUF_LEN_REG, (uint8_t *)&send_buf_size, sizeof(send_buf_size));
|
||||
|
||||
static uint32_t recv_buf_size = 120;
|
||||
static uint32_t recv_buf_size = 128;
|
||||
spi_slave_hd_write_buffer(SLAVE_HOST, SLAVE_MAX_RX_BUF_LEN_REG, (uint8_t *)&recv_buf_size, sizeof(recv_buf_size));
|
||||
|
||||
uint32_t slave_ready_flag = SLAVE_READY_FLAG;
|
||||
|
||||
Reference in New Issue
Block a user