maxikrie opened a new pull request, #21024:
URL: https://github.com/apache/nuttx/pull/21024

   ## Summary
   
   On STM32H7, data written to a serial port just before its last `close()` was 
lost: up to 16 bytes (the TX FIFO), so a short `write()` + `close()` sent 
nothing at all. Fixes #7138 ("echo does not even emit anything if I write less 
than 16 characters").
   
   - `txempty` pointed to `up_txready()`, which tests TXE. With the TX FIFO 
enabled that means "FIFO not full". `uart_tcdrain()` on the last close found 
the software buffer empty and `txempty` true right away, and `up_shutdown()` 
turned the USART clock off while the FIFO still held the data. A new 
`up_txempty()` tests TC (transmission complete) instead.
   - `up_shutdown()` turned the APB clock off before clearing UE/TE/RE, so the 
CR1 write was lost and the USART stayed enabled. It now disables the USART 
first.
   
   The first commit only fixes the nxstyle errors in the file (switch 
indentation, blank lines after declarations), so that checkpatch passes; the 
object code is identical.
   
   Other STM32 drivers also use `txready` for `txempty` (e.g. stm32n6, 
stm32wl5, common m0_v3/v4); the ones with a TX FIFO probably lose data the same 
way. Not changed here (not tested).
   
   ## Impact
   
   STM32H7 serial ports that are opened and closed (not the console, which 
stays open). Closing now waits for the last bit to leave (at most a FIFO's 
worth, ~1.4 ms at 115200).
   
   ## Testing
   
   NUCLEO-H753ZI, master b9d1d6a834, `nucleo-h753zi:nsh` + USART2 on PD5/PD6 
(pins and DMA map added locally to board.h for the test, not part of this PR) 
to an FTDI TTL-232R-3V3 cable, 115200 8N1. NSH writes N bytes and closes the 
port (`dd if=/dev/zero of=/dev/ttyS1 bs=N count=1`, or `echo`), the host counts 
what arrives, 5 runs each:
   
   | bytes written | master | this PR | master, TX DMA | this PR, TX DMA |
   |---|---|---|---|---|
   | 1 | 1 | 1 | 1 | 1 |
   | 8 | 2-3 | 8 | 2-3 | 8 |
   | 15 | 3 | 15 | 2-3 | 15 |
   | 16 | 3 | 16 | 2-3 | 16 |
   | 17 | 3 | 17 | 3 | 17 |
   | 31, 100, 252, 300, 1000 | all | all | all | all |
   
   `tools/checkpatch.sh -f arch/arm/src/stm32h7/stm32_serial.c` passes after 
each commit.
   
   ## Logs
   
   <details><summary>master: echo of 8..18 characters (+ newline) to 
/dev/ttyS1, what the host receives</summary>
   
   ```
    8 sent 'ABCDEFGH'             got b''
    9 sent 'ABCDEFGHI'            got b''
   10 sent 'ABCDEFGHIJ'           got b''
   11 sent 'ABCDEFGHIJK'          got b''
   12 sent 'ABCDEFGHIJKL'         got b''
   13 sent 'ABCDEFGHIJKLM'        got b''
   14 sent 'ABCDEFGHIJKLMN'       got b''
   15 sent 'ABCDEFGHIJKLMNO'      got b'ABCDEFGHIJKLMNO\n'
   16 sent 'ABCDEFGHIJKLMNOP'     got b'ABCDEFGHIJKLMNOP\n'
   ```
   </details>
   
   <details><summary>master, after such a close: USART6 registers 
(ST-Link)</summary>
   
   ```
   RCC_APB2ENR   = 0x00000000   (USART6EN off)
   USART6 CR1    = 0x2000000d   (UE, TE, RE still set: the CR1 write after the 
clock-off was lost)
   USART6 ISR    = 0x08600080   (TXFE = 0, TC = 0: the TX FIFO still holds data)
   ```
   </details>
   
   <details><summary>this PR: dd byte counts</summary>
   
   ```
   1: [1, 1, 1, 1, 1]
   8: [8, 8, 8, 8, 8]
   15: [15, 15, 15, 15, 15]
   16: [16, 16, 16, 16, 16]
   17: [17, 17, 17, 17, 17]
   31: [31, 31, 31, 31, 31]
   100: [100, 100, 100, 100, 100]
   252: [252, 252, 252, 252, 252]
   300: [300, 300, 300, 300, 300]
   1000: [1000, 1000, 1000, 1000, 1000]
   ```
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to