nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

ESP32: uart.write() doesn't send long chunk via CONSOLE_USB_SERIAL_JTAG #3657

Open serg3295 opened 1 month ago

serg3295 commented 1 month ago

Expected behavior

Currently, to send a data fragment larger than 256 bytes via CONSOLE_USB_SERIAL_JTAG, a forced insertion of \n between 256-byte fragments is required.

I would like the behavior to match the behavior when sending a long sequence via UART_DEFAULT. That is, data should be sent continuously without adding \n

In the nodemcu-tool and nodemcu-tools utilities, uniterrupted sending is used to download a file from the ESP32. Forcing \n to each piece will break the exchange protocol.

Moreover, the size of the response to a request from the utility can exceed 256 bytes. And in this case, I can't even add \n

Actual behavior

When sending a chunk longer than 256 bytes, only the first 256 bytes are sent. The remaining bytes will be sent only if you add \n at the end of the chunk.

Test code

This code works

s = string.rep('a', 256)
uart.write(0, s)
uart.write(0,'\n')
uart.write(0, s)
print'\n'

This code does not work

s = string.rep('a', 256)
uart.write(0, s)
uart.write(0, s)
print'\n'

NodeMCU startup banner

Startup banner ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021 rst:0x3 (RTC_SW_SYS_RST),boot:0xd (SPI_FAST_FLASH_BOOT) Saved PC:0x40048b82 SPIWP:0xee mode:DIO, clock div:1 load:0x3fcd5820,len:0x1704 load:0x403cc710,len:0x938 load:0x403ce710,len:0x2ee8 entry 0x403cc710 I (24) boot: ESP-IDF v5.1.3 2nd stage bootloader I (24) boot: compile time Jul 29 2024 20:30:34 I (24) boot: chip revision: v0.4 I (27) boot.esp32c3: SPI Speed : 80MHz I (32) boot.esp32c3: SPI Mode : DIO I (36) boot.esp32c3: SPI Flash Size : 4MB I (41) boot: Enabling RNG early entropy source... I (46) boot: Partition Table: I (50) boot: ## Label Usage Type ST Offset Length I (57) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (65) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (72) boot: 2 factory factory app 00 00 00010000 00180000 I (80) boot: 3 lfs unknown c2 01 00190000 00010000 I (87) boot: 4 storage Unknown data 01 82 001a0000 00070000 I (95) boot: End of partition table I (99) esp_image: segment 0: paddr=00010020 vaddr=3c0e0020 size=2d748h (186184) map I (137) esp_image: segment 1: paddr=0003d770 vaddr=3fc92400 size=028a8h ( 10408) load I (139) esp_image: segment 2: paddr=00040020 vaddr=42000020 size=d19b8h (858552) map I (279) esp_image: segment 3: paddr=001119e0 vaddr=3fc94ca8 size=001ach ( 428) load I (280) esp_image: segment 4: paddr=00111b94 vaddr=40380000 size=1237ch ( 74620) load I (299) esp_image: segment 5: paddr=00123f18 vaddr=50000000 size=00018h ( 24) load I (305) boot: Loaded app from partition at offset 0x10000 I (306) boot: Disabling RNG early entropy source... I (308) cpu_start: Unicore app I (312) cpu_start: Pro cpu up. I (327) cpu_start: Pro cpu start user code I (327) cpu_start: cpu freq: 160000000 Hz I (327) cpu_start: Application information: I (330) cpu_start: Project name: nodemcu I (335) cpu_start: App version: tmr-libmain-binpatch150-888-gca I (342) cpu_start: Compile time: Jul 29 2024 20:32:43 I (348) cpu_start: ELF file SHA256: b3501ddbd7970a59... I (354) cpu_start: ESP-IDF: v5.1.3 I (359) cpu_start: Min chip rev: v0.3 I (364) cpu_start: Max chip rev: v1.99 I (369) cpu_start: Chip rev: v0.4 I (373) heap_init: Initializing. RAM available for dynamic allocation: I (381) heap_init: At 3FC997B0 len 00026850 (154 KiB): DRAM I (387) heap_init: At 3FCC0000 len 0001C710 (113 KiB): DRAM/RETENTION I (394) heap_init: At 3FCDC710 len 00002950 (10 KiB): DRAM/RETENTION/STACK I (402) heap_init: At 50000018 len 00001FD0 (7 KiB): RTCRAM I (409) spi_flash: detected chip: generic I (412) spi_flash: flash io: dio W (417) rmt(legacy): legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h` W (427) ADC: legacy driver is deprecated, please migrate to `esp_adc/adc_oneshot.h` I (436) sleep: Configure to isolate all GPIO pins in sleep state I (442) sleep: Enable automatic switching of GPIO sleep configuration I (449) app_start: Starting scheduler on CPU0 I (454) main_task: Started on CPU0 I (454) main_task: Calling app_main() E (464) mmap: esp_mmu_paddr_to_vaddr(752): paddr isn't mapped LFS image loaded I (474) pp: pp rom version: 9387209 I (474) net80211: net80211 rom version: 9387209 I (484) wifi:wifi driver task: 3fca87a4, prio:23, stack:6656, core=0 I (484) wifi:wifi firmware version: 0016c4d I (484) wifi:wifi certification version: v7.0 I (484) wifi:config NVS flash: enabled I (484) wifi:config nano formating: disabled I (484) wifi:Init data frame dynamic rx buffer num: 32 I (484) wifi:Init static rx mgmt buffer num: 5 I (484) wifi:Init management short buffer num: 32 I (484) wifi:Init dynamic tx buffer num: 32 I (484) wifi:Init static tx FG buffer num: 2 I (484) wifi:Init static rx buffer size: 1600 I (484) wifi:Init static rx buffer num: 10 I (484) wifi:Init dynamic rx buffer num: 32 I (484) wifi_init: rx ba win: 6 I (494) wifi_init: tcpip mbox: 32 I (494) wifi_init: udp mbox: 6 I (494) wifi_init: tcp mbox: 6 I (494) wifi_init: tcp tx win: 5760 I (494) wifi_init: tcp rx win: 5760 I (494) wifi_init: tcp mss: 1440 I (494) wifi_init: WiFi IRAM OP enabled I (494) wifi_init: WiFi RX IRAM OP enabled NodeMCU ESP32 build 2024-07-29 20:32 powered by Lua 5.3.5 [5.3-int32-singlefp] on IDF v5.1.3 cannot open init.lua: No such file or directory

Hardware

esp32c3 and esp32c6 via CONSOLE_USB_SERIAL_JTAG

serg3295 commented 1 month ago

I found a workaround to the issue.

  1. Upgrade to ifd v5.2.2. This is a mandatory step.
  2. Change platform.c a little
void platform_uart_send_multi( unsigned id, const char *data, size_t len )
{
  size_t i;
  // if (id == CONFIG_ESP_CONSOLE_UART_NUM) {
      for( i = 0; i < len; i ++ ) {
        putchar (data[ i ]);
    }
  // } else {
    // uart_write_bytes(id, data, len);
  // }
}

void platform_uart_send( unsigned id, uint8_t data )
{
  // if (id == CONFIG_ESP_CONSOLE_UART_NUM)
    putchar (data);
  // else
    // uart_write_bytes(id, (const char *)&data, 1);
}

void platform_uart_flush( unsigned id )
{
  // if (id == CONFIG_ESP_CONSOLE_UART_NUM)
    fflush (stdout);
  // else
    // uart_tx_flush(id);
}

I don't know why it works, but it does.