Merge branch 'fix/spi_buslock_multi_dev_acq_release_issue_v6.0' into 'release/v6.0'

fix(esp_hw_support): fixed spi buslock multi dev acq/release logic issue (v6.0)

See merge request espressif/esp-idf!49168
This commit is contained in:
morris
2026-07-07 14:53:55 +08:00
15 changed files with 277 additions and 201 deletions
@@ -297,3 +297,64 @@ TEST_CASE("spi_lcd_send_colors_to_fixed_region", "[lcd]")
TEST_ESP_OK(spi_bus_free(TEST_SPI_HOST_ID));
free(color_data);
}
#define TEST_SPI_LCD_CONCURRENT_COLOR_LEN (120 * 120)
typedef struct {
spi_device_handle_t spi_dev;
TaskHandle_t done_task;
volatile bool stop;
uint32_t trans_count;
} spi_lcd_concurrent_polling_ctx_t;
static void spi_lcd_concurrent_polling_task(void *arg)
{
spi_lcd_concurrent_polling_ctx_t *ctx = arg;
spi_transaction_t trans = {
.length = 4 * 8,
.flags = SPI_TRANS_USE_TXDATA,
};
while (!ctx->stop) {
vTaskDelay(pdMS_TO_TICKS(50));
TEST_ESP_OK(spi_device_polling_transmit(ctx->spi_dev, &trans));
ctx->trans_count++;
}
xTaskNotifyGive(ctx->done_task);
vTaskDelete(NULL);
}
TEST_CASE("spi_lcd_safe_with_another_device_polling_on_same_bus", "[lcd]")
{
void *color_data = malloc(TEST_SPI_LCD_CONCURRENT_COLOR_LEN);
TEST_ASSERT_NOT_NULL(color_data);
esp_lcd_panel_io_handle_t io_handle = NULL;
test_spi_lcd_common_initialize(&io_handle, NULL, NULL, 8, 8, false);
spi_lcd_concurrent_polling_ctx_t polling_ctx = { .done_task = xTaskGetCurrentTaskHandle() };
spi_device_interface_config_t other_dev_config = {
.clock_speed_hz = TEST_LCD_PIXEL_CLOCK_HZ,
.spics_io_num = -1,
.queue_size = 1,
};
TEST_ESP_OK(spi_bus_add_device(TEST_SPI_HOST_ID, &other_dev_config, &polling_ctx.spi_dev));
// polling task with higher priority than the interrupt task
xTaskCreate(spi_lcd_concurrent_polling_task, "spi_polling", 4096, &polling_ctx, 10, NULL);
for (int i = 0; i < 30; i++) {
printf("panel_io_tx_color %d\r\n", i);
TEST_ESP_OK(esp_lcd_panel_io_tx_color(io_handle, -1, color_data, TEST_SPI_LCD_CONCURRENT_COLOR_LEN));
}
polling_ctx.stop = true;
vTaskDelay(pdMS_TO_TICKS(100)); // wait for polling task to stop
TEST_ASSERT_GREATER_THAN(0, (int)ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5000)));
TEST_ASSERT_GREATER_THAN_UINT32(0, polling_ctx.trans_count);
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
TEST_ESP_OK(spi_bus_remove_device(polling_ctx.spi_dev));
TEST_ESP_OK(spi_bus_free(TEST_SPI_HOST_ID));
TEST_ESP_OK(gpio_reset_pin(TEST_LCD_BK_LIGHT_GPIO));
free(color_data);
}