Can't manage to get UART DMA working
Posted: Sun Oct 30, 2022 3:23 pm
So, I've started using my ESP32 board with the Arduino IDE. I read the programming manual to learn how to configure and use the hardware, then wrote a C header file with all register and bit mask definitions (which I'll omit for brevity). This is my code:
Unfortunately, nothing comes out. I can easily print bytes by writing directly to ESP32_UART0_FIFO_REG, but that approach works terribly. I realize that the Arduino ESP32 library initializes the hardware to some values before my code runs, and I believe I'm probably doing the initialization wrong myself. Any ideas what might be wrong in this code? I've read the manual several times now and I can't find an issue.
Code: Select all
char alignas(uint32_t) out_buffer[16] = "Hello world!";
struct esp32_dma_linked_list dma_linked_list {
.dw0 =
ESP32_DMA_LINKED_LIST_DW0_OWNER |
ESP32_DMA_LINKED_LIST_DW0_EOF |
ESP32_DMA_LINKED_LIST_DW0_LENGTH(12) |
ESP32_DMA_LINKED_LIST_DW0_SIZE(16)
,
.dw1 = out_buffer,
.dw2 = nullptr
};
void setup_uart() {
*ESP32_UART0_FIFO_REG = ESP32_UART_RXFIFO_RD_BYTE('\0');
*ESP32_UART0_CONF0_REG =
ESP32_UART_TICK_REF_ALWAYS_ON |
ESP32_UART_TXFIFO_RST |
ESP32_UART_TXD_BRK |
ESP32_UART_STOP_BIT_NUM(1) |
ESP32_UART_BIT_NUM(3) |
ESP32_UART_PARITY_EN |
ESP32_UART_PARITY
;
*ESP32_UART0_CONF1_REG =
ESP32_UART_TXFIFO_EMPTY_THRHD(96) |
ESP32_UART_RXFIFO_FULL_THRHD(96)
;
set_baud_rate(9600);
*ESP32_UHCI0_CONF0_REG =
ESP32_UHCI_UART0_CE
;
*ESP32_UHCI0_DMA_OUT_LINK_REG =
ESP32_UHCI_OUTLINK_START |
ESP32_UHCI_OUTLINK_ADDR(((uintptr_t) &dma_linked_list) & 0xFFFFF)
;
}
void setup() {
setup_uart();
}
void loop() {
}