From 5351a8312829be92b9b07bccb683c77036c80c71 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Thu, 31 Oct 2024 10:10:56 +0100 Subject: [PATCH 1/4] feat(newlib): change line endings on standard input and output Currently, the newline conversions for the NEWLIB_STDOUT_LINE_ENDING and NEWLIB_STDIN_LINE_ENDING options are only applied by VFS drivers. Without VFS, newline conversion does not occur. Introduce the default conversion of LF to CRLF on stdout and CF to LF on stdin for the default read and write syscalls in newlib. Signed-off-by: Frantisek Hrbata --- components/newlib/syscalls.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/newlib/syscalls.c b/components/newlib/syscalls.c index 20d890b287..c60280912f 100644 --- a/components/newlib/syscalls.c +++ b/components/newlib/syscalls.c @@ -33,6 +33,9 @@ ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t siz const char* cdata = (const char*) data; if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { for (size_t i = 0; i < size; ++i) { + if (cdata[i] == '\n') { + esp_rom_output_tx_one_char('\r'); + } esp_rom_output_tx_one_char(cdata[i]); } return size; @@ -53,6 +56,9 @@ ssize_t _read_r_console(struct _reent *r, int fd, void * data, size_t size) if (status != 0) { break; } + if (cdata[received] == '\r') { + cdata[received] = '\n'; + } } if (received == 0) { errno = EWOULDBLOCK; From 2c3c0653d2ccaeac31741c798fecb9e9ad490fa7 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Thu, 24 Oct 2024 09:55:52 +0200 Subject: [PATCH 2/4] change(newlib): support line endings modification only with VFS The configuration of newline endings for stdout and stdin is supported only by the VFS drivers. The write and read syscalls in newlib automatically convert LF to CRLF for stdout and CR to LF for stdin, ignoring the configured newline settings. Therefore, make the options for newline endings visible only when VFS is enabled. Signed-off-by: Frantisek Hrbata --- components/newlib/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/newlib/Kconfig b/components/newlib/Kconfig index 98e63e8c03..92573ca73d 100644 --- a/components/newlib/Kconfig +++ b/components/newlib/Kconfig @@ -3,6 +3,7 @@ menu "Newlib" choice NEWLIB_STDOUT_LINE_ENDING prompt "Line ending for UART output" default NEWLIB_STDOUT_LINE_ENDING_CRLF + depends on VFS_SUPPORT_IO help This option allows configuring the desired line endings sent to UART when a newline ('\n', LF) appears on stdout. @@ -27,6 +28,7 @@ menu "Newlib" choice NEWLIB_STDIN_LINE_ENDING prompt "Line ending for UART input" default NEWLIB_STDIN_LINE_ENDING_CR + depends on VFS_SUPPORT_IO help This option allows configuring which input sequence on UART produces a newline ('\n', LF) on stdin. From cf3802a0ac3e7bec98e03ba4e1dc01f3482c7c95 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 28 Oct 2024 13:45:21 +0100 Subject: [PATCH 3/4] fix(test_apps): do not check line endings in dut.expect The default newlib read/write syscalls automatically convert newline endings from LF to CRLF on stdout. Therefore, the test should not specifically check for LF in the expected output, as the standard conversion for stdout is CRLF. While it is possible to change the expected line ending in the test from LF to CRLF, it seems more dependable to just avoid verifying line endings entirely. Signed-off-by: Frantisek Hrbata --- tools/test_apps/system/mmu_page_size/pytest_mmu_page_size.py | 4 ++-- .../system/unicore_bootloader/pytest_unicore_bootloader.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/test_apps/system/mmu_page_size/pytest_mmu_page_size.py b/tools/test_apps/system/mmu_page_size/pytest_mmu_page_size.py index cd9eb47db2..d4cb1104af 100644 --- a/tools/test_apps/system/mmu_page_size/pytest_mmu_page_size.py +++ b/tools/test_apps/system/mmu_page_size/pytest_mmu_page_size.py @@ -27,7 +27,7 @@ def test_app_mmu_page_size_32k_and_bootloader_mmu_page_size_64k(dut: Dut, app_do dut.serial.bootloader_flash(path_to_mmu_page_size_64k_build) dut.expect('MMU page size mismatch') dut.expect('App is running') - dut.expect('Partition test done\n') + dut.expect('Partition test done') @pytest.mark.esp32c6 @@ -49,4 +49,4 @@ def test_app_mmu_page_size_64k_and_bootloader_mmu_page_size_32k(dut: Dut, app_do dut.serial.bootloader_flash(path_to_mmu_page_size_32k_build) dut.expect('MMU page size mismatch') dut.expect('App is running') - dut.expect('Partition test done\n') + dut.expect('Partition test done') diff --git a/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py b/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py index da16ff07db..3e6ba5b11a 100644 --- a/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py +++ b/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py @@ -34,7 +34,7 @@ def test_multicore_app_and_unicore_bootloader(dut: Dut, app_downloader, config) if 'psram' in config: dut.expect(re.compile(r'Adding pool of \d+K of PSRAM memory to heap allocator')) dut.expect('App is running') - dut.expect('NVS test done\n') + dut.expect('NVS test done') @pytest.mark.esp32 @@ -62,4 +62,4 @@ def test_unicore_app_and_multicore_bootloader(dut: Dut, app_downloader, config) if 'psram' in config: dut.expect(re.compile(r'Adding pool of \d+K of PSRAM memory to heap allocator')) dut.expect('App is running') - dut.expect('NVS test done\n') + dut.expect('NVS test done') From e16f711a9986d00da74fdf215353fd3817ab3863 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 5 Nov 2024 08:26:59 +0100 Subject: [PATCH 4/4] change(newlib): use a general console name in the new line conversion options Currently, the new line ending conversion options for stdin and stdout are specifically described for UART, which is inaccurate since the console could be connected to USB serial/CDC or have secondary output. Use a generic console term instead of UART. Signed-off-by: Frantisek Hrbata --- components/newlib/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/newlib/Kconfig b/components/newlib/Kconfig index 92573ca73d..78eaa47376 100644 --- a/components/newlib/Kconfig +++ b/components/newlib/Kconfig @@ -1,11 +1,11 @@ menu "Newlib" choice NEWLIB_STDOUT_LINE_ENDING - prompt "Line ending for UART output" + prompt "Line ending for console output" default NEWLIB_STDOUT_LINE_ENDING_CRLF depends on VFS_SUPPORT_IO help - This option allows configuring the desired line endings sent to UART + This option allows configuring the desired line endings sent to console when a newline ('\n', LF) appears on stdout. Three options are possible: @@ -26,11 +26,11 @@ menu "Newlib" endchoice choice NEWLIB_STDIN_LINE_ENDING - prompt "Line ending for UART input" + prompt "Line ending for console input" default NEWLIB_STDIN_LINE_ENDING_CR depends on VFS_SUPPORT_IO help - This option allows configuring which input sequence on UART produces + This option allows configuring which input sequence on console produces a newline ('\n', LF) on stdin. Three options are possible: