Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serial/uart_16550: Wait before setting Line Control Register (Synopsys DesignWare 8250) #10019

Merged
merged 1 commit into from Aug 3, 2023

Conversation

lupyuen
Copy link
Member

@lupyuen lupyuen commented Aug 3, 2023

Summary

Some UART Controllers (Synopsys DesignWare 8250) will trigger spurious interrupts when the Line Control Register (LCR) is set while the UART is busy. This patch provides the option (16550_WAIT_LCR) to wait for UART until it's not busy, before setting the LCR. (16550_WAIT_LCR is disabled by default)

This patch fixes the spurious UART interrupts for the upcoming port of NuttX to StarFive JH7110 SoC (with Synopsys DesignWare 8250 UART). The patch is explained here

Modified Files

drivers/serial/uart_16550.c: If 16550_WAIT_LCR is enabled, wait until UART is not busy before setting LCR

include/nuttx/serial/uart_16550.h: Define the UART Status Register (USR) for checking if UART is busy

drivers/serial/Kconfig-16550: Added option 16550_WAIT_LCR to 16550 UART Config, disabled by default

Impact

After applying this patch and enabling 16550_WAIT_LCR, StarFive JH7110 will boot correctly to NSH. (Instead of getting stuck servicing too many spurious UART interrupts)

No impact on existing code, since 16550_WAIT_LCR is disabled by default.

Testing

We tested this patch with the upcoming port of NuttX for JH7110. For Regression Testing, we tested with QEMU RISC-V (rv-virt:knsh64).

JH7110 Test

When 16550_WAIT_LCR is Disabled (default), JH7110 will fire spurious UART interrupts and fail to start NSH Shell (because it's too busy servicing interrupts):

Starting kernel ...
BCnx_start: Entry
uart_register: Registering /dev/console
uart_register: Registering /dev/ttyS0

When 16550_WAIT_LCR is Enabled, JH7110 will start NSH Shell correctly:

Starting kernel ...
BCnx_start: Entry
uart_register: Registering /dev/console
uart_register: Registering /dev/ttyS0
work_start_lowpri: Starting low-priority kernel worker thread(s)
nx_start_application: Starting init task: /system/bin/init
...
NuttShell (NSH) NuttX-12.0.3
nsh>

Regression Test

We tested with QEMU RISC-V (rv-virt:knsh64):

tools/configure.sh rv-virt:knsh64
make
qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -bios none -kernel nuttx -initrd initrd -nographic

NuttX boots correctly with the default setting of 16550_WAIT_LCR (disabled):

…s DesignWare 8250)

Some UART Controllers (Synopsys DesignWare 8250) will trigger spurious interrupts when the Line Control Register (LCR) is set while the UART is busy. This patch provides the option (16550_WAIT_LCR) to wait for UART until it's not busy, before setting the LCR. (16550_WAIT_LCR is disabled by default)

This patch fixes the spurious UART interrupts for the upcoming port of NuttX to StarFive JH7110 SoC (with Synopsys DesignWare 8250 UART). [The patch is explained here](https://lupyuen.github.io/articles/plic#appendix-fix-the-spurious-uart-interrupts)

drivers/serial/uart_16550.c: If 16550_WAIT_LCR is enabled, wait until UART is not busy before setting LCR

include/nuttx/serial/uart_16550.h: Define the UART Status Register (USR) for checking if UART is busy

drivers/serial/Kconfig-16550: Added option 16550_WAIT_LCR to 16550 UART Config, disabled by default
@jerpelea jerpelea merged commit b2c1930 into apache:master Aug 3, 2023
26 checks passed
@jerpelea jerpelea added this to To-Add in Release Notes - 12.3.0 Sep 26, 2023
@jerpelea jerpelea moved this from To-Add to drivers in Release Notes - 12.3.0 Sep 27, 2023
@jerpelea jerpelea moved this from drivers to done in Release Notes - 12.3.0 Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants