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的负担。
测试代码
  1. dma_descriptor_t *tx_desc; ///< DMA descriptors
  2. static gdma_channel_handle_t tx_channel;
  3. uint8_t *tx_dma_buf; //dma buffer
  4. uhci_seper_chr_t seper_char ={
  5. .sub_chr_en =0,
  6. };
  7.  
  8. static inline void muhci_ll_init(uhci_dev_t *hw)
  9. {
  10. // typeof(hw->conf0) conf0_reg;
  11. hw->conf0.clk_en = 1;
  12. hw->conf0.val = 0;
  13. hw->conf0.clk_en = 1;
  14. //hw->conf0.val = conf0_reg.val;
  15. hw->conf0.tx_rst = 1;
  16. hw->conf0.tx_rst = 0;
  17. hw->conf0.rx_rst = 1;
  18. hw->conf0.rx_rst = 0;
  19. hw->conf1.val = 0;
  20. }
  21.  
  22. esp_err_t uart_gdma_init(void)
  23. {
  24. esp_err_t ret;
  25. int rx_ch_id = 0;
  26. gdma_channel_alloc_config_t channel_config_tx = {
  27. .direction = GDMA_CHANNEL_DIRECTION_TX,
  28. };
  29.  
  30. ret = gdma_new_channel(&channel_config_tx, &tx_channel);
  31. if (ret != ESP_OK) {
  32.     goto err;
  33. }
  34. gdma_strategy_config_t strategy_config = {
  35.     .auto_update_desc = true,
  36.     .owner_check = true
  37. };
  38. gdma_apply_strategy(tx_channel, &strategy_config);
  39. gdma_connect(tx_channel, GDMA_MAKE_TRIGGER(GDMA_TRIG_PERIPH_UART, 0));//  trig_periph.instance_id ==2
  40. tx_dma_buf = heap_caps_calloc(1, 2048, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);
  41. if (!tx_dma_buf) {
  42.     ret = ESP_ERR_NO_MEM;
  43.     goto err;
  44. }
  45.  
  46. //malloc dma descriptor
  47. tx_desc = heap_caps_calloc(1, (sizeof(dma_descriptor_t)), MALLOC_CAP_DMA);
  48. if (!tx_desc) {
  49. ret = ESP_ERR_NO_MEM;
  50. goto err;
  51. }
  52. tx_desc->dw0.size = 2048;
  53. tx_desc->dw0.length = 0;
  54. tx_desc->dw0.suc_eof = 1;
  55. tx_desc->dw0.owner = 1;
  56. tx_desc->buffer = tx_dma_buf;
  57. tx_desc->next = NULL;
  58. gdma_get_channel_id(tx_channel, &rx_ch_id);
  59. ESP_LOGE(TAG, "acquire DMA channel, rx_ch_id=%d", rx_ch_id);
  60. gdma_ll_tx_reset_channel(&GDMA, rx_ch_id);
  61.  
  62. muhci_ll_init(UHCI_LL_GET_HW(0));
  63. uhci_ll_attach_uart_port(UHCI_LL_GET_HW(0),2);
  64.  
  65. uhci_ll_set_seper_chr(UHCI_LL_GET_HW(0), &seper_char);
  66. return ESP_OK;    
  67.  
  68. err:
  69. ESP_LOGE(TAG, "Failed to acquire DMA channel, Err=%d", ret);
  70. tx_channel = NULL;
  71. free(tx_dma_buf);
  72. free(tx_desc);
  73. return ret;
  74. }
  75.  
  76. void uart_gdma_write(dma_descriptor_t *desc,uint32_t len1)
  77. {
  78. desc->dw0.length = len1;
  79. gdma_start( tx_channel, (intptr_t )desc);
  80. }
在main中调用,串口2无法输出。不用gdma,使用uart_write_bytes(2, test_data, strlen(test_data));是可以正常在串口2发送引脚输出的。是配置流程有问题吗,我只需要串口2 DMA发送。请求大神帮忙指教
  1. uart_gdma_init();
  2. const char *source_str = "testtest\r\n";
  3. strcpy((char *)tx_dma_buf, source_str);
  4. uart_gdma_write(tx_desc,10);
输出日志:
uart_gdma: acquire DMA channel, rx_ch_id=0

ESP_Yake
Posts: 109
Joined: Mon Mar 06, 2017 12:23 pm

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

Postby ESP_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写的

ESP_Yake
Posts: 109
Joined: Mon Mar 06, 2017 12:23 pm

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

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

我们已经有同事之前做了这个方案,我上传上来供你参考,请将IDF版本切换至commit: 2e68e510a5163c106ea04182b6ffe3063630b6c1,然后打入patch进行测试
Attachments
uart_dma.zip
(16.46 KiB) Downloaded 524 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: 29
Joined: Sat Jun 24, 2023 12:52 am

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

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

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

ESP_Yake
Posts: 109
Joined: Mon Mar 06, 2017 12:23 pm

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

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

XiongJL001 wrote:
Fri Aug 25, 2023 4:40 am
ESP_Yake wrote:
Tue Aug 22, 2023 8:01 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

ESP_Yake wrote:
Tue Aug 22, 2023 8:01 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

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

Who is online

Users browsing this forum: No registered users and 43 guests