aboutsummaryrefslogtreecommitdiff
path: root/include/hw/char/stm32l4x5_usart.h
blob: dd3866682a31338896e06c5d3625a50e41ed1f8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * STM32L4X5 USART (Universal Synchronous Asynchronous Receiver Transmitter)
 *
 * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
 * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 *
 * The STM32L4X5 USART is heavily inspired by the stm32f2xx_usart
 * by Alistair Francis.
 * The reference used is the STMicroElectronics RM0351 Reference manual
 * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
 */

#ifndef HW_STM32L4X5_USART_H
#define HW_STM32L4X5_USART_H

#include "hw/sysbus.h"
#include "chardev/char-fe.h"
#include "qom/object.h"

#define TYPE_STM32L4X5_USART_BASE "stm32l4x5-usart-base"
#define TYPE_STM32L4X5_USART "stm32l4x5-usart"
#define TYPE_STM32L4X5_UART "stm32l4x5-uart"
#define TYPE_STM32L4X5_LPUART "stm32l4x5-lpuart"
OBJECT_DECLARE_TYPE(Stm32l4x5UsartBaseState, Stm32l4x5UsartBaseClass,
                    STM32L4X5_USART_BASE)

typedef enum {
    STM32L4x5_USART,
    STM32L4x5_UART,
    STM32L4x5_LPUART,
} Stm32l4x5UsartType;

struct Stm32l4x5UsartBaseState {
    SysBusDevice parent_obj;

    MemoryRegion mmio;

    uint32_t cr1;
    uint32_t cr2;
    uint32_t cr3;
    uint32_t brr;
    uint32_t gtpr;
    uint32_t rtor;
    /* rqr is write-only */
    uint32_t isr;
    /* icr is a clear register */
    uint32_t rdr;
    uint32_t tdr;

    Clock *clk;
    CharBackend chr;
    qemu_irq irq;
    guint watch_tag;
};

struct Stm32l4x5UsartBaseClass {
    SysBusDeviceClass parent_class;

    Stm32l4x5UsartType type;
};

#endif /* HW_STM32L4X5_USART_H */