esp32s3 使用串口gdma,无法发送。idf4.4.4

liuecho
Posts: 3
Joined: Fri Aug 04, 2023 2:29 am

esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby liuecho » Fri Aug 04, 2023 2:42 am

使用的是esp32s3,idf4.4.4。串口2单独可以发送,串口2部分配置没问题。但是用gdma无法发送数据。调用uart_gdma_write没反应。不知道是gdma的配置问题,还是uhci的配置问题?请大佬解答。多谢。我现在可以在做哪些测试呢?如何更改配置。因为我有大量的数据来发送,需要使用dma来减轻cpu的负担。
测试代码

Code: Untitled.c Select all

dma_descriptor_t *tx_desc; ///< DMA descriptors
static gdma_channel_handle_t tx_channel;
uint8_t *tx_dma_buf; //dma buffer
uhci_seper_chr_t seper_char ={
.sub_chr_en =0,
};

static inline void muhci_ll_init(uhci_dev_t *hw)
{
// typeof(hw->conf0) conf0_reg;
hw->conf0.clk_en = 1;
hw->conf0.val = 0;
hw->conf0.clk_en = 1;
//hw->conf0.val = conf0_reg.val;
hw->conf0.tx_rst = 1;
hw->conf0.tx_rst = 0;
hw->conf0.rx_rst = 1;
hw->conf0.rx_rst = 0;
hw->conf1.val = 0;
}

esp_err_t uart_gdma_init(void)
{
esp_err_t ret;
int rx_ch_id = 0;
gdma_channel_alloc_config_t channel_config_tx = {
.direction = GDMA_CHANNEL_DIRECTION_TX,
};

ret = gdma_new_channel(&channel_config_tx, &tx_channel);
if (ret != ESP_OK) {
goto err;
}
gdma_strategy_config_t strategy_config = {
.auto_update_desc = true,
.owner_check = true
};
gdma_apply_strategy(tx_channel, &strategy_config);
gdma_connect(tx_channel, GDMA_MAKE_TRIGGER(GDMA_TRIG_PERIPH_UART, 0));// trig_periph.instance_id ==2
tx_dma_buf = heap_caps_calloc(1, 2048, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);
if (!tx_dma_buf) {
ret = ESP_ERR_NO_MEM;
goto err;
}

//malloc dma descriptor
tx_desc = heap_caps_calloc(1, (sizeof(dma_descriptor_t)), MALLOC_CAP_DMA);
if (!tx_desc) {
ret = ESP_ERR_NO_MEM;
goto err;
}
tx_desc->dw0.size = 2048;
tx_desc->dw0.length = 0;
tx_desc->dw0.suc_eof = 1;
tx_desc->dw0.owner = 1;
tx_desc->buffer = tx_dma_buf;
tx_desc->next = NULL;
gdma_get_channel_id(tx_channel, &rx_ch_id);
ESP_LOGE(TAG, "acquire DMA channel, rx_ch_id=%d", rx_ch_id);
gdma_ll_tx_reset_channel(&GDMA, rx_ch_id);

muhci_ll_init(UHCI_LL_GET_HW(0));
uhci_ll_attach_uart_port(UHCI_LL_GET_HW(0),2);

uhci_ll_set_seper_chr(UHCI_LL_GET_HW(0), &seper_char);
return ESP_OK;

err:
ESP_LOGE(TAG, "Failed to acquire DMA channel, Err=%d", ret);
tx_channel = NULL;
free(tx_dma_buf);
free(tx_desc);
return ret;
}

void uart_gdma_write(dma_descriptor_t *desc,uint32_t len1)
{
desc->dw0.length = len1;
gdma_start( tx_channel, (intptr_t )desc);
}
在main中调用,串口2无法输出。不用gdma,使用uart_write_bytes(2, test_data, strlen(test_data));是可以正常在串口2发送引脚输出的。是配置流程有问题吗,我只需要串口2 DMA发送。请求大神帮忙指教

Code: Untitled.c Select all

uart_gdma_init();
const char *source_str = "testtest\r\n";
strcpy((char *)tx_dma_buf, source_str);
uart_gdma_write(tx_desc,10);
输出日志:
uart_gdma: acquire DMA channel, rx_ch_id=0

Yake
Espressif staff
Espressif staff
Posts: 111
Joined: Mon Mar 06, 2017 12:23 pm

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby Yake » Tue Aug 08, 2023 9:07 am

我们IDF里面uart没有实现DMA方式吧?这是你们自己做的吗

liuecho
Posts: 3
Joined: Fri Aug 04, 2023 2:29 am

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby liuecho » Fri Aug 11, 2023 3:35 am

是的,根据idf写的

Yake
Espressif staff
Espressif staff
Posts: 111
Joined: Mon Mar 06, 2017 12:23 pm

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby Yake » Tue Aug 22, 2023 8:01 am

我们已经有同事之前做了这个方案,我上传上来供你参考,请将IDF版本切换至commit: 2e68e510a5163c106ea04182b6ffe3063630b6c1,然后打入patch进行测试
Attachments
uart_dma.zip
(16.46 KiB) Downloaded 926 times

liuecho
Posts: 3
Joined: Fri Aug 04, 2023 2:29 am

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby liuecho » Tue Aug 22, 2023 12:56 pm

收到,实在太感谢

XiongJL001
Posts: 30
Joined: Sat Jun 24, 2023 12:52 am

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby XiongJL001 » Fri Aug 25, 2023 4:40 am

我们已经有同事之前做了这个方案,我上传上来供你参考,请将IDF版本切换至commit: 2e68e510a5163c106ea04182b6ffe3063630b6c1,然后打入patch进行测试
我不会用git但是我也想用串口DMA怎么办,怎么获取这个例程

Yake
Espressif staff
Espressif staff
Posts: 111
Joined: Mon Mar 06, 2017 12:23 pm

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby Yake » Tue Aug 29, 2023 4:07 am

我们已经有同事之前做了这个方案,我上传上来供你参考,请将IDF版本切换至commit: 2e68e510a5163c106ea04182b6ffe3063630b6c1,然后打入patch进行测试
我不会用git但是我也想用串口DMA怎么办,怎么获取这个例程
可以下载 IDF v5.0的版本,然后手动修改patch的内容

wishlucky
Posts: 6
Joined: Tue Aug 15, 2023 5:36 am

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby wishlucky » Fri Apr 12, 2024 3:08 am

我们已经有同事之前做了这个方案,我上传上来供你参考,请将IDF版本切换至commit: 2e68e510a5163c106ea04182b6ffe3063630b6c1,然后打入patch进行测试
你好 我打入patch失败了 报错信息如下?

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((v5.1.2))
$ pwd
/e/1zhc/ESP32/esp-idf--5.1.2/esp-idf

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((v5.1.2))
$ git branch
* (no branch)

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((v5.1.2))
$ git checkout 2e68e510a51
warning: unable to rmdir 'components/bt/controller/lib_esp32c2/esp32c2-bt-lib': Directory not empty
warning: unable to rmdir 'components/bt/controller/lib_esp32c6/esp32c6-bt-lib': Directory not empty
warning: unable to rmdir 'components/bt/controller/lib_esp32h2/esp32h2-bt-lib': Directory not empty
warning: unable to rmdir 'components/esp_coex/lib': Directory not empty
warning: unable to rmdir 'components/heap/tlsf': Directory not empty
Updating files: 100% (12407/12407), done.
Previous HEAD position was 482a8fb2d7 change(version): Update version to 5.1.2
HEAD is now at 2e68e510a5 Merge branch 'ci/remove_make_codeowner' into 'master'
M components/bootloader/subproject/components/micro-ecc/micro-ecc
M components/bt/controller/lib_esp32
M components/bt/controller/lib_esp32c3_family
M components/bt/host/nimble/nimble
M components/esp_phy/lib
M components/esp_wifi/lib
M components/hal/esp32s3/include/hal/uhci_ll.h
M components/ieee802154/lib
M components/json/cJSON
M components/lwip/lwip
M components/mbedtls/mbedtls
M components/mqtt/esp-mqtt
M components/openthread/lib
M components/openthread/openthread
M components/protobuf-c/protobuf-c
M components/spiffs/spiffs

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((2e68e510a5...))
$ git apply --check uart_dma.patch
error: patch failed: components/hal/esp32s3/include/hal/uhci_ll.h:120
error: components/hal/esp32s3/include/hal/uhci_ll.h: patch does not apply

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((2e68e510a5...))
$ ^C

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((2e68e510a5...))
$ git apply uart_dma.patch
error: patch failed: components/hal/esp32s3/include/hal/uhci_ll.h:120
error: components/hal/esp32s3/include/hal/uhci_ll.h: patch does not apply

Administrator@MS-TVJKOJRVRPYI MINGW64 /e/1zhc/ESP32/esp-idf--5.1.2/esp-idf ((2e68e510a5...))
$
这是什么原因呀

EternityFOR
Posts: 1
Joined: Thu Jul 04, 2024 6:55 am

Re: esp32s3 使用串口gdma,无法发送。idf4.4.4

Postby EternityFOR » Thu Jul 04, 2024 6:58 am

Code: Untitled.txt Select all

你好,想问下看到ESP32 UART是支持DMA的,而且例程的readme中写着支持ESP32的,但是为什么cmakelist中条件语句禁止了修改target到ESP32呢,谢谢

Who is online

Users browsing this forum: YisouSpider and 1 guest