walnux/drivers/serial/Kconfig-usart
Kerogit a3f8b55143 drivers/serial/serial: prevent race conditions on 8-bit architectures
Some code paths in drivers/serial/serial.c load head and tail values
of receive and transmit circular buffers with interrupts enabled,
making it possible that the interrupt handler changes the value.
As noted in the code, this is safe as long as the load itself is atomic.

That is not true for 8bit architectures which fetch the 16-bit values
using two load instructions. If interrupt handler runs between those
two instructions and changes the value, the read returns corrupted data.

This patch introduces CONFIG_ARCH_LDST_16BIT_NOT_ATOMIC configuration
option which is automatically selected for AVR architecture. Based
on this option, head and tail values are reduced to 8-bit length
so the read remains atomic.

Patch was tested by building on rv-virt:nsh - disassembly of functions
from serial.c showed no difference which is correct as Risc-V does
not need to protect reads of these values. There should be no impact
for architectures that do not set the new configuration option.

It was also tested by by custom echo application running on AVR128DA28.

Signed-off-by: Kerogit <kr.git@kerogit.eu>
2025-06-19 10:01:24 -03:00

853 lines
18 KiB
Text

#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config USART0_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART1_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART2_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART3_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART4_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART5_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART6_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART7_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART8_SERIALDRIVER
bool
default n
select MCU_SERIAL
config USART9_SERIALDRIVER
bool
default n
select MCU_SERIAL
menu "USART0 Configuration"
depends on USART0_SERIALDRIVER
config USART0_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART0_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART0_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART0_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART0_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART0_2STOP
int "use 2 stop bits"
default 0
---help---
1=Two stop bits
config USART0_IFLOWCONTROL
bool "USART0 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART0 RTS flow control
config USART0_OFLOWCONTROL
bool "USART0 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART0 CTS flow control
config USART0_RXDMA
bool "USART0 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART0
config USART0_TXDMA
bool "USART0 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART0
endmenu
menu "USART1 Configuration"
depends on USART1_SERIALDRIVER
config USART1_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART1_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART1_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART1_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART1_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART1_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART1_IFLOWCONTROL
bool "USART1 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART1 RTS flow control
config USART1_OFLOWCONTROL
bool "USART1 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART1 CTS flow control
config USART1_RXDMA
bool "USART1 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART1
config USART1_TXDMA
bool "USART1 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART1
endmenu
menu "USART2 Configuration"
depends on USART2_SERIALDRIVER
config USART2_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART2_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART2_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART2_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART2_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART2_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART2_IFLOWCONTROL
bool "USART2 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART2 RTS flow control
config USART2_OFLOWCONTROL
bool "USART2 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART2 CTS flow control
config USART2_RXDMA
bool "USART2 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART2
config USART2_TXDMA
bool "USART2 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART2
endmenu
menu "USART3 Configuration"
depends on USART3_SERIALDRIVER
config USART3_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART3_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART3_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART3_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART3_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART3_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART3_IFLOWCONTROL
bool "USART3 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART3 RTS flow control
config USART3_OFLOWCONTROL
bool "USART3 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART3 CTS flow control
config USART3_RXDMA
bool "USART3 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART3
config USART3_TXDMA
bool "USART3 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART3
endmenu
menu "USART4 Configuration"
depends on USART4_SERIALDRIVER
config USART4_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART4_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART4_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART4_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART4_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART4_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART4_IFLOWCONTROL
bool "USART4 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART4 RTS flow control
config USART4_OFLOWCONTROL
bool "USART4 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART4 CTS flow control
config USART4_RXDMA
bool "USART4 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART4
config USART4_TXDMA
bool "USART4 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART4
endmenu
menu "USART5 Configuration"
depends on USART5_SERIALDRIVER
config USART5_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART5_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART5_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART5_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART5_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART5_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART5_IFLOWCONTROL
bool "USART5 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART5 RTS flow control
config USART5_OFLOWCONTROL
bool "USART5 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART5 CTS flow control
config USART5_RXDMA
bool "USART5 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART5
config USART5_TXDMA
bool "USART5 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART5
endmenu
menu "USART6 Configuration"
depends on USART6_SERIALDRIVER
config USART6_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART6_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART6_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART6_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART6_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART6_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART6_IFLOWCONTROL
bool "USART6 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART6 RTS flow control
config USART6_OFLOWCONTROL
bool "USART6 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART6 CTS flow control
config USART6_RXDMA
bool "USART6 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART6
config USART6_TXDMA
bool "USART6 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART6
endmenu
menu "USART7 Configuration"
depends on USART7_SERIALDRIVER
config USART7_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART7_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART7_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART7_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART7_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART7_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART7_IFLOWCONTROL
bool "USART7 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART7 RTS flow control
config USART7_OFLOWCONTROL
bool "USART7 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART7 CTS flow control
config USART7_RXDMA
bool "USART7 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART7
config USART7_TXDMA
bool "USART7 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART7
endmenu
menu "USART8 Configuration"
depends on USART8_SERIALDRIVER
config USART8_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART8_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART8_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART8_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART8_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART8_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART8_IFLOWCONTROL
bool "USART8 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART8 RTS flow control
config USART8_OFLOWCONTROL
bool "USART8 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART8 CTS flow control
config USART8_RXDMA
bool "USART8 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART8
config USART8_TXDMA
bool "USART8 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART8
endmenu
menu "USART9 Configuration"
depends on USART9_SERIALDRIVER
config USART9_RXBUFSIZE
int "Receive buffer size"
default 252
---help---
Characters are buffered as they are received. This specifies
the size of the receive buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART9_TXBUFSIZE
int "Transmit buffer size"
default 252
---help---
Characters are buffered before being sent. This specifies
the size of the transmit buffer.
Note that on architectures that are unable to load 16-bit
values atomically without eg. disabling interrupts, the size
of the buffer is stored in uint8_t variable.
config USART9_BAUD
int "BAUD rate"
default 115200
---help---
The configured BAUD of the USART.
config USART9_BITS
int "Character size"
default 8
---help---
The number of bits. Must be either 7 or 8.
config USART9_PARITY
int "Parity setting"
default 0
range 0 2
---help---
0=no parity, 1=odd parity, 2=even parity
config USART9_2STOP
int "Uses 2 stop bits"
default 0
---help---
1=Two stop bits
config USART9_IFLOWCONTROL
bool "USART9 RTS flow control"
default n
select SERIAL_IFLOWCONTROL
---help---
Enable USART9 RTS flow control
config USART9_OFLOWCONTROL
bool "USART9 CTS flow control"
default n
select SERIAL_OFLOWCONTROL
---help---
Enable USART9 CTS flow control
config USART9_RXDMA
bool "USART9 Rx DMA support"
default n
select SERIAL_RXDMA
---help---
Enable Rx DMA transfers on USART9
config USART9_TXDMA
bool "USART9 Tx DMA support"
default n
select SERIAL_TXDMA
---help---
Enable Tx DMA transfers on USART9
endmenu