hw/char/stm32l4x5_usart.c: Support 16-bit writes
PATCH v2 1/1 hw/char/stm32l4x5_usart.c: Support 16-bit writes
Official STM32CubeL4 drivers use and require support for 16-bit writes to UART registers for proper function despite datasheet claims.
---
v2:
- Remove all changes other than supporting 16-bit writes UART regs
hw/char/stm32l4x5_usart.c | 4 ++-- tests/qtest/stm32l4x5_usart-test.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-)
hw/char/stm32l4x5_usart.c +2 -2
@@ -521,12 +521,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 +21 -1
@@ -332,6 +332,26 @@ static void test_ack(void)qtest_quit (qts); } +static void test_16bit_access (void ) +{ +QTestState *qts =qtest_init ("-M b-l475e-iot01a" ); + +/* GTPR is declared uint16_t in the official STM driver. */ +qtest_writew (qts,USART1_BASE_ADDR +A_GTPR ,0xABCD ); +uint16_t gtpr16 =qtest_readw (qts,USART1_BASE_ADDR +A_GTPR ); + g_assert_cmpuint(gtpr16, ==, 0xABCD); + +/* TDR is uint16_t and r/w, register is 9-bits */ +qtest_writew (qts,USART1_BASE_ADDR +A_TDR ,0x01CD ); +uint16_t tdr16 =qtest_readw (qts,USART1_BASE_ADDR +A_TDR ); + g_assert_cmpuint(tdr16, ==, 0x01CD); + +/* RDR is uint16_t and read only, register is 9-bits */ +qtest_writew (qts,USART1_BASE_ADDR +A_RDR ,0x01FA ); + +qtest_quit (qts); +} +static void check_clock (QTestState *qts,const char *path,uint32_t rcc_reg,uint32_t reg_offset) {
@@ -370,6 +390,6 @@ int main(int argc, char **argv)qtest_add_func ("stm32l4x5/usart/send_str" , test_send_str);qtest_add_func ("stm32l4x5/usart/ack" , test_ack);qtest_add_func ("stm32l4x5/usart/clock_enable" , test_clock_enable); +qtest_add_func ("stm32l4x5/usart/16bit_access" , test_16bit_access);return g_test_run (); } -
Signature · 1 line
2.43.0
Hi Jacob,
Quoted 2 lines · Jacob Whitaker Abrams
Official STM32CubeL4 drivers use and require support for 16-bit writes to UART registers for proper function despite datasheet claims.
[*]
Quoted 15 lines
Signed-off-by Jacob Whitaker Abrams <[email protected]>---
v2:
- Remove all changes other than supporting 16-bit writes UART regshw/char/stm32l4x5_usart.c | 4 ++-- tests/qtest/stm32l4x5_usart-test.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-)hw/char/stm32l4x5_usart.c +0
-0
hw/char/stm32l4x5_usart.c static const MemoryRegionOps stm32l4x5_usart_base_ops = { · line 524
Quoted 5 lines
hw/char/stm32l4x5_usart.c +1
-1@@ -521,12 +521,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,
Can we replicate the description comment here?
hw/char/stm32l4x5_usart.c static const MemoryRegionOps stm32l4x5_usart_base_ops = { · line 529
Quoted 6 lines
hw/char/stm32l4x5_usart.c +1
-1.unaligned = false }, .impl = { .max_access_size = 4, - .min_access_size = 4, + .min_access_size = 2,
This files defines addresses using the REG32() macro, and the read/write handlers switch over these 32-bit addresses.
Why change the implementation minimum access size to 16-bit?
Quoted 3 lines
hw/char/stm32l4x5_usart.c +0
-0.unaligned = false }, };