davids5 commented on code in PR #11020:
URL: https://github.com/apache/nuttx/pull/11020#discussion_r1371212483
##########
arch/arm/src/imxrt/imxrt_serial.c:
##########
@@ -1373,6 +1373,7 @@ static inline void imxrt_serialout(struct imxrt_uart_s
*priv,
static int imxrt_dma_nextrx(struct imxrt_uart_s *priv)
{
int dmaresidual = imxrt_dmach_getcount(priv->rxdma);
+ DEBUGASSERT(dmaresidual <= RXDMA_BUFFER_SIZE);
Review Comment:
@danielappiagyei-bc
The rxfifo is a ring buffer. Written to by the DMA and read from by code.
N.B `imxrt_dma_nextrx` is only used on the RX side to check if data has been
added by the DMA.
Based on this setup
```
/* Configure for circular DMA reception into the RX FIFO */
config.saddr = priv->uartbase + IMXRT_LPUART_DATA_OFFSET;
config.daddr = (uint32_t) priv->rxfifo;
config.soff = 0;
config.doff = 1;
config.iter = RXDMA_BUFFER_SIZE;
config.flags = EDMA_CONFIG_LINKTYPE_LINKNONE |
EDMA_CONFIG_LOOPDEST |
EDMA_CONFIG_INTHALF |
EDMA_CONFIG_INTMAJOR;
config.ssize = EDMA_8BIT;
config.dsize = EDMA_8BIT;
config.nbytes = 1;
#ifdef CONFIG_KINETIS_EDMA_ELINK
config.linkch = 0;
#endif
```
The DMA reads a byte from IMXRT_LPUART_DATA_OFFSET and writes a byte it to
priv->rxfifo adding 1 to to the destination address register and decrementing
the count register. (That starts at RXDMA_BUFFER_SIZE. ) EDMA_CONFIG_LOOPDEST
causes the destination address register to be reloaded with priv->rxfifo at
count = 0 and the count is reloaded.
Therefore it can not write outside the buffer.
I could image a case were the count is sampled before the reload but I have
not seen it.
Even if it did, the net effect is `imxrt_dma_nextrx` returns 32. But the
only way the return from `imxrt_dma_nextrx` is used is to compare it with the
`priv->rxdmanext` to determine if data is in the ring.
`priv->rxdmanext` is constrained from 0 - RXDMA_BUFFER_SIZE-1; by
```
priv->rxdmanext++;
if (priv->rxdmanext == RXDMA_BUFFER_SIZE)
{
priv->rxdmanext = 0;
}
```
read access is via
```
c = priv->rxfifo[priv->rxdmanext]
```
Not the DMA' index returned from imxrt_dma_nextrx().
Glitch of 32 would just say there is data, the next read, will see the
truth. So the assert !=0 should stay out.
But the nagging question is how do you see 0..
What are your config settings for DMA and LPUART?
Here is what I have
```
CONFIG_IMXRT_EDMA=y
CONFIG_IMXRT_EDMA_EDBG=y
CONFIG_IMXRT_EDMA_ELINK=y
CONFIG_IMXRT_EDMA_NTCD=64\
# ttyS2
CONFIG_LPUART4_RXDMA=y
CONFIG_LPUART4_TXDMA=y
ONFIG_IMXRT_LPUART4=y
CONFIG_LPUART4_BAUD=57600
CONFIG_LPUART4_IFLOWCONTROL=y
CONFIG_LPUART4_OFLOWCONTROL=y
CONFIG_LPUART4_RXBUFSIZE=600
CONFIG_LPUART4_RXDMA=y
CONFIG_LPUART4_TXBUFSIZE=3000
CONFIG_LPUART4_TXDMA=y
```
I am running on this
https://github.com/PX4/PX4-Autopilot/tree/pr-imxrt1170-imxrt1062 branch with
`make nxp_fmurt1170-v1` using `serial_test -s -c -p /dev/ttyS2 -b 3000000` on
the DUT and `./linux-serial-test -s -p
/dev/serial/by-id/usb-FTDI_TTL-234X-3V3_FT2QRM97-if00-port0 -c -b 3000000` on
my linux box.
imxrt_dma_nextrx returns unsigned int. So the DEBUGASSERT ignores the
dmaresidual > 0 term.
Replacing it with
<img width="932" alt="image"
src="https://github.com/apache/nuttx/assets/1945821/46caece0-97f1-4383-a681-1dffb1cf1d7e">
Will trap the condition. I have a break on the assert firing. But it has
never. 20 minute in.....
<img width="701" alt="image"
src="https://github.com/apache/nuttx/assets/1945821/732f5497-708e-4c53-b56e-0912e4b098fa">
--
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]