hw/char/stm32l4x5_usart.c: Fix ACK and min access size
PATCH v2 1/1 hw/char/stm32l4x5_usart.c: Fix ACK and min access size
These changes allow the official STM32L4xx HAL UART driver to function properly with the b-l475e-iot01a machine.
Modifying USART_CR1 TE bit should alter USART_ISR TEACK bit, and likewise for RE and REACK bit.
USART registers may be accessed via 16-bit instructions.
Reseting USART_CR1 UE bit should restore ISR to default value.
Fixes 87b77e6e01ca ("hw/char/stm32l4x5_usart: Enable serial read and write")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2540
Signed-off-by Jacob Abrams <[email protected]>
---
Changes since version 1:
- Add qtest_quit to end of new test
hw/char/stm32l4x5_usart.c | 29 ++++++++++++++++++--- tests/qtest/stm32l4x5_usart-test.c | 41 +++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 4 deletions(-)
hw/char/stm32l4x5_usart.c +26 -3
@@ -154,6 +154,28 @@ REG32(RDR, 0x24) REG32(TDR, 0x28) FIELD(TDR, TDR, 0, 9) +#define ISR_RESET_VALUE (0x020000C0) + +static void stm32l4x5_update_isr (Stm32l4x5UsartBaseState *s) +{ +if (!(s->cr1 &R_CR1_UE_MASK )) { + s->isr =ISR_RESET_VALUE ; +return ; + } + +if (s->cr1 &R_CR1_TE_MASK ) { + s->isr |=R_ISR_TEACK_MASK ; + }else { + s->isr &= ~R_ISR_TEACK_MASK ; + } + +if (s->cr1 &R_CR1_RE_MASK ) { + s->isr |=R_ISR_REACK_MASK ; + }else { + s->isr &= ~R_ISR_REACK_MASK ; + } +} +static void stm32l4x5_update_irq (Stm32l4x5UsartBaseState *s) { if (((s->isr & R_ISR_WUF_MASK) && (s->cr3 & R_CR3_WUFIE_MASK)) ||
@@ -367,7 +389,7 @@ static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type) s->brr =0x00000000 ; s->gtpr =0x00000000 ; s->rtor =0x00000000 ; - s->isr =0x020000C0 ; + s->isr =ISR_RESET_VALUE ; s->rdr =0x00000000 ; s->tdr =0x00000000 ;
@@ -456,6 +478,7 @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr,case A_CR1 : s->cr1 = value;stm32l4x5_update_params (s); +stm32l4x5_update_isr (s);stm32l4x5_update_irq (s);return ;case A_CR2 :
@@ -508,12 +531,12 @@ static const MemoryRegionOps stm32l4x5_usart_base_ops = { .endianness = DEVICE_NATIVE_ENDIAN, .valid = { .max_access_size = 4, - .min_access_size = 4, + .min_access_size = 2, .unaligned = false }, .impl = { .max_access_size = 4, - .min_access_size = 4, + .min_access_size = 2, .unaligned = false }, };
tests/qtest/stm32l4x5_usart-test.c +40 -1
71 lines not on this page · raw message
Signature · 1 line
2.43.0