Skip to content

Commit bb03892

Browse files
committed
feat(uhci): Add length receive threshold support
1 parent f566b50 commit bb03892

File tree

10 files changed

+18
-6
lines changed

10 files changed

+18
-6
lines changed

components/esp_driver_uart/include/driver/uhci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
size_t max_transmit_size; /*!< Maximum transfer size in one transaction, in bytes. This decides the number of DMA nodes will be used for each transaction */
2525
size_t max_receive_internal_mem; /*!< Maximum transfer size in one transaction, in bytes. Each DMA node can point to a maximum of 4096 bytes. This value determines the number of DMA nodes used for each transaction. When your transfer size is large enough, it is recommended to set this value greater than 4096 to facilitate efficient ping-pong operations, such as 10 * 1024. */
2626
size_t dma_burst_size; /*!< DMA burst size, in bytes */
27+
size_t max_packet_receive; /*!< Max receive size, auto stop receiving after reach this value, only valid when `length_eof` set true */
2728

2829
struct {
2930
uint16_t rx_brk_eof: 1; /*!< UHCI will end payload receive process when NULL frame is received by UART. */

components/esp_driver_uart/linker.lf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ entries:
2626
gdma_link: gdma_link_mount_buffers (noflash)
2727
gdma_link: gdma_link_get_head_addr (noflash)
2828
gdma: gdma_start (noflash)
29+
gdma: gdma_stop (noflash)
30+
gdma: gdma_reset (noflash)

components/esp_driver_uart/src/uhci.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ static bool uhci_gdma_rx_callback_done(gdma_channel_handle_t dma_chan, gdma_even
149149
need_yield |= uhci_ctrl->rx_dir.on_rx_trans_event(uhci_ctrl, &evt_data, uhci_ctrl->user_data);
150150
}
151151

152+
// Stop the transaction when EOF is detected. In case for length EOF, there is no further more callback to be invoked.
153+
gdma_stop(uhci_ctrl->rx_dir.dma_chan);
154+
gdma_reset(uhci_ctrl->rx_dir.dma_chan);
155+
152156
uhci_ctrl->rx_dir.rx_fsm = UHCI_RX_FSM_ENABLE;
153157
}
154158

@@ -330,6 +334,7 @@ esp_err_t uhci_receive(uhci_controller_handle_t uhci_ctrl, uint8_t *read_buffer,
330334
}
331335
};
332336
ESP_LOGD(TAG, "The DMA node %d has %d byte", i, uhci_ctrl->rx_dir.buffer_size_per_desc_node[i]);
337+
ESP_RETURN_ON_FALSE(uhci_ctrl->rx_dir.buffer_size_per_desc_node[i] != 0, ESP_ERR_INVALID_STATE, TAG, "Allocate dma node length is 0, please reconfigure the buffer_size");
333338
read_buffer += uhci_ctrl->rx_dir.buffer_size_per_desc_node[i];
334339
}
335340

@@ -451,6 +456,9 @@ esp_err_t uhci_new_controller(const uhci_controller_config_t *config, uhci_contr
451456

452457
uhci_controller_handle_t uhci_ctrl = (uhci_controller_handle_t)heap_caps_calloc(1, sizeof(uhci_controller_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
453458
ESP_RETURN_ON_FALSE(uhci_ctrl, ESP_ERR_NO_MEM, TAG, "no mem for uhci controller handle");
459+
if (config->rx_eof_flags.length_eof) {
460+
ESP_RETURN_ON_FALSE(config->max_packet_receive < UHCI_LL_MAX_RECEIVE_PACKET_THRESHOLD, ESP_ERR_INVALID_ARG, TAG, "max receive packet is over threshold");
461+
}
454462

455463
atomic_init(&uhci_ctrl->tx_dir.tx_fsm, UHCI_TX_FSM_ENABLE);
456464
atomic_init(&uhci_ctrl->rx_dir.rx_fsm, UHCI_TX_FSM_ENABLE);
@@ -509,6 +517,7 @@ esp_err_t uhci_new_controller(const uhci_controller_config_t *config, uhci_contr
509517
}
510518
if (config->rx_eof_flags.length_eof) {
511519
uhci_ll_rx_set_eof_mode(uhci_ctrl->hal.dev, UHCI_RX_LEN_EOF);
520+
uhci_ll_rx_set_packet_threshold(uhci_ctrl->hal.dev, config->max_packet_receive);
512521
}
513522
if (config->rx_eof_flags.rx_brk_eof) {
514523
uhci_ll_rx_set_eof_mode(uhci_ctrl->hal.dev, UHCI_RX_BREAK_CHR_EOF);

components/esp_driver_uart/test_apps/.build-test-rules.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ components/esp_driver_uart/test_apps/uart_vfs:
3232
components/esp_driver_uart/test_apps/uhci:
3333
disable:
3434
- if: SOC_UHCI_SUPPORTED != 1
35-
- if: CONFIG_NAME == "psram" and SOC_SPIRAM_SUPPORTED != 1
35+
- if: CONFIG_NAME == "psram" and SOC_AHB_GDMA_SUPPORT_PSRAM != 1
3636
depends_components:
3737
- esp_driver_uart

components/esp_driver_uart/test_apps/uhci/main/test_uhci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ TEST_CASE("UHCI write and receive with length eof", "[uhci]")
246246
}
247247

248248
#if CONFIG_SPIRAM
249-
#if CONFIG_IDF_TARGET_ESP32S3
249+
#if SOC_AHB_GDMA_SUPPORT_PSRAM
250250
static void uhci_receive_test_in_psram(void *arg)
251251
{
252252
uhci_controller_handle_t uhci_ctrl = ((uhci_controller_handle_t *)arg)[0];

components/hal/esp32c5/include/hal/uhci_ll.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ static inline void uhci_ll_reset_register(int group_id)
5555
static inline void uhci_ll_init(uhci_dev_t *hw)
5656
{
5757
typeof(hw->conf0) conf0_reg;
58-
hw->conf0.clk_en = 1;
5958
conf0_reg.val = 0;
6059
conf0_reg.clk_en = 1;
6160
hw->conf0.val = conf0_reg.val;

components/hal/esp32h2/include/hal/uhci_ll.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static inline void uhci_ll_reset_register(int group_id)
5252
static inline void uhci_ll_init(uhci_dev_t *hw)
5353
{
5454
typeof(hw->conf0) conf0_reg;
55-
hw->conf0.clk_en = 1;
5655
conf0_reg.val = 0;
5756
conf0_reg.clk_en = 1;
5857
hw->conf0.val = conf0_reg.val;

examples/peripherals/.build-test-rules.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ examples/peripherals/uart/uart_dma_ota:
516516
disable:
517517
- if: SOC_UHCI_SUPPORTED != 1
518518
disable_test:
519-
- if: IDF_TARGET in ["esp32p4"]
519+
- if: IDF_TARGET in ["esp32p4", "esp32c5"]
520520
temporary: true
521521
reason: Lack runners
522522

examples/peripherals/uart/uart_dma_ota/pytest_uart_dma_ota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def send_file_via_uart(port: str, baud_rate: int, file_path: str, packet_size: i
4242
],
4343
indirect=True,
4444
)
45-
@idf_parametrize('target', ['esp32c6', 'esp32c3', 'esp32s3'], indirect=['target'])
45+
@idf_parametrize('target', ['esp32c6', 'esp32c3', 'esp32s3', 'esp32h2'], indirect=['target'])
4646
def test_uart_dma_ota(dut: Dut) -> None:
4747
dut.expect_exact('uhci-example: OTA process started')
4848
# We OTA the same binary to another partition and switch to there.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_IDF_TARGET="esp32h2"
2+
CONFIG_UART_RX_IO=23

0 commit comments

Comments
 (0)