UART DMA code doesn't work

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

UART DMA code doesn't work

Postby humptydumpty » Fri Oct 06, 2017 12:06 pm

I try the following code for a UART transfer via DMA. UART is already configured and works in the normal way. However, my code does not produce any output. Any ideas what is missing?

Code: Select all

lldesc_t dmaDesc_myarray;

void IRAM_ATTR send_DRM_DMA (void) {

   dmaDesc_myarray.length = 24;
   dmaDesc_myarray.size = 24;
   dmaDesc_myarray.owner = 1;
   dmaDesc_myarray.sosf = 0;
   dmaDesc_myarray.buf = (uint8_t *)myarray[0];
   dmaDesc_myarray.offset = 0; //unused in hw
   dmaDesc_myarray.empty = 0;
   dmaDesc_myarray.eof = 1;

   UHCI0.conf0.val = (UHCI_OUT_DATA_BURST_EN | UHCI_OUTDSCR_BURST_EN | UHCI_INDSCR_BURST_EN | UHCI_UART1_CE |
           UHCI_IN_RST | UHCI_OUT_RST | UHCI_AHBM_RST | UHCI_AHBM_FIFO_RST | UHCI_CLK_EN);
   UART1.conf0.txfifo_rst = 1;
   UHCI0.dma_out_link.addr = (uint32_t)(&dmaDesc_myarray);
   UHCI0.dma_out_link.start = 1;
   UHCI0.int_clr.val = 0xFFFFFFFF;
}

ESP_igrr
Posts: 998
Joined: Tue Dec 01, 2015 8:37 am

Re: UART DMA code doesn't work

Postby ESP_igrr » Fri Oct 06, 2017 4:49 pm

Have you enabled clock and taken UHCI out of reset? See driver/periph_clk.h.

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

Re: UART DMA code doesn't work

Postby humptydumpty » Sat Oct 07, 2017 4:05 pm

Thanks for your suggestion. I think you mean "driver/periph_ctrl.h". In fact I had not enabled the peripheral...

I tried adding the following lines to my code:

Code: Select all

#include  "driver/periph_ctrl.h"
periph_module_enable(PERIPH_UHCI0_MODULE);


But it still doesn't send anything.

ESP_igrr
Posts: 998
Joined: Tue Dec 01, 2015 8:37 am

Re: UART DMA code doesn't work

Postby ESP_igrr » Sat Oct 07, 2017 4:47 pm

Code: Select all

UHCI_OUT_DATA_BURST_EN | UHCI_OUTDSCR_BURST_EN | UHCI_INDSCR_BURST_EN | UHCI_UART1_CE |
           UHCI_IN_RST | UHCI_OUT_RST | UHCI_AHBM_RST | UHCI_AHBM_FIFO_RST | UHCI_CLK_EN


It seems that you assert reset of several modules and never de-assert it. Reset bits are not self-clearing, you must clear them manually. Also, the description of CLK_EN says: Set this bit to enable clock-gating for read or write registers. So if the bit is set, registers are clock-gated, which is probably not what you want.

According to the TRM, the only bit you really need to set in CONF0 is the UHCI_UART1_CE bit. The rest should be zero.

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

Re: UART DMA code doesn't work

Postby humptydumpty » Sat Oct 07, 2017 5:13 pm

Yes. Thank you. I forgot that you have to turn the reset bits off.

I revised as follows but still doesn't work.

Code: Select all

   
#include  "driver/periph_ctrl.h"
lldesc_t dmaDesc_myarray;

void IRAM_ATTR send_DRM_DMA (void) {

   dmaDesc_myarray.length = 24;
   dmaDesc_myarray.size = 24;
   dmaDesc_myarray.owner = 1;
   dmaDesc_myarray.sosf = 0;
   dmaDesc_myarray.buf = (uint8_t *)myarray[0];
   dmaDesc_myarray.offset = 0; //unused in hw
   dmaDesc_myarray.empty = 0;
   dmaDesc_myarray.eof = 1;
   periph_module_enable(PERIPH_UHCI0_MODULE);
   UHCI0.conf0.val = (UHCI_OUT_DATA_BURST_EN | UHCI_OUTDSCR_BURST_EN | UHCI_INDSCR_BURST_EN | UHCI_UART1_CE );
   UART1.conf0.txfifo_rst = 1;
   UHCI0.int_clr.val = 0xFFFFFFFF;
   UHCI0.conf0.val |= UHCI_IN_RST | UHCI_OUT_RST | UHCI_AHBM_RST | UHCI_AHBM_FIFO_RST;
   UHCI0.dma_out_link.start = 0;
   UHCI0.dma_in_link.start = 0;
   UHCI0.conf0.val &= ~( UHCI_IN_RST | UHCI_OUT_RST | UHCI_AHBM_RST | UHCI_AHBM_FIFO_RST);
   UART1.conf0.txfifo_rst = 0;
   UHCI0.dma_out_link.addr = (uint32_t)(&dmaDesc_myarray);
   UHCI0.dma_out_link.start = 1;
   UHCI0.int_clr.val = 0xFFFFFFFF;
   

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

Re: UART DMA code doesn't work

Postby humptydumpty » Sat Oct 07, 2017 9:30 pm

Sorry I didn't see your comment about the bitfields that should be zero until just now.

It appears that there might be an error in uhci_struct.h. There are a number of bitfields in the struct that are not in the TRM.

For example UHCI_OUT_DATA_BURST_EN, UHCI_OUTDSCR_BURST_EN and UHCI_INDSCR_BURST_EN.

I will change accordingly and try again tomorrow.

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

Re: UART DMA code doesn't work

Postby humptydumpty » Mon Oct 09, 2017 1:16 pm

Still no dice.

I notice that DMA routines for I2S and SPI reset the bus before start. Not sure why the reset bits in the UHCI configuration register are marked reserved in the TRM, but enumerated in the esp-idf include files.

Anyway I tried it both ways. No signal.

You wrote somewhere else that you are working on UART DMA driver. Have you succeeded in getting any output yet?

ESP_igrr
Posts: 998
Joined: Tue Dec 01, 2015 8:37 am

Re: UART DMA code doesn't work

Postby ESP_igrr » Mon Oct 09, 2017 5:47 pm

A colleague is working on UHCI driver, but it's not finished yet. Looking at the source code, I can't immediately figure out what is missing in your code to initialize UHCI correctly.
I'll ask my colleague to have a look at your code.

Just to make things easier, could you please post the complete code somewhere?

humptydumpty
Posts: 17
Joined: Thu Sep 07, 2017 10:26 am

Re: UART DMA code doesn't work

Postby humptydumpty » Mon Oct 09, 2017 7:36 pm

Thanks for helping. Actually it is part of a much larger project which I would not, for reasons of confidentiality, want to post. We are talking about thousands of lines of code.

I will try to take the relevant parts and make an independent project out of it for test purposes.

ESP_igrr
Posts: 998
Joined: Tue Dec 01, 2015 8:37 am

Re: UART DMA code doesn't work

Postby ESP_igrr » Tue Oct 10, 2017 3:55 am

Sure, just the "initialize UART - initialize UHCI - send data" part would do. We can piece that together from your posts, but we may also end up with something different that way...

Who is online

Users browsing this forum: No registered users and 5 guests