summary refs log tree commit diff stats
path: root/hw/char/stm32f2xx_usart.c
diff options
context:
space:
mode:
authorOlivier Hériveaux <olivier.heriveaux@ledger.fr>2021-11-28 13:07:23 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-12-15 10:11:34 +0000
commitab08c3467605365b44fab1b66bb6254db86814f6 (patch)
tree0d81c93a3c6afa0451c94c7815f520dbbde9279d /hw/char/stm32f2xx_usart.c
parentb662fac6aa800669d3a802f1ddaa1910a42b77ab (diff)
downloadfocaccia-qemu-ab08c3467605365b44fab1b66bb6254db86814f6.tar.gz
focaccia-qemu-ab08c3467605365b44fab1b66bb6254db86814f6.zip
Fix STM32F2XX USART data register readout
Fix issue where the data register may be overwritten by next character
reception before being read and returned.

Signed-off-by: Olivier Hériveaux <olivier.heriveaux@ledger.fr>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20211128120723.4053-1-olivier.heriveaux@ledger.fr
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/char/stm32f2xx_usart.c')
-rw-r--r--hw/char/stm32f2xx_usart.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c
index 8df0832424..fde67f4f03 100644
--- a/hw/char/stm32f2xx_usart.c
+++ b/hw/char/stm32f2xx_usart.c
@@ -103,10 +103,11 @@ static uint64_t stm32f2xx_usart_read(void *opaque, hwaddr addr,
         return retvalue;
     case USART_DR:
         DB_PRINT("Value: 0x%" PRIx32 ", %c\n", s->usart_dr, (char) s->usart_dr);
+        retvalue = s->usart_dr & 0x3FF;
         s->usart_sr &= ~USART_SR_RXNE;
         qemu_chr_fe_accept_input(&s->chr);
         qemu_set_irq(s->irq, 0);
-        return s->usart_dr & 0x3FF;
+        return retvalue;
     case USART_BRR:
         return s->usart_brr;
     case USART_CR1: