1 // Copyright 2024, Linaro Limited 2 // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 3 // SPDX-License-Identifier: GPL-2.0-or-later 4 // 5 // PL011 QEMU Device Model 6 // 7 // This library implements a device model for the PrimeCell® UART (PL011) 8 // device in QEMU. 9 // 10 #![doc = include_str!("../README.md")] 11 //! # Library crate 12 //! 13 //! See [`PL011State`](crate::device::PL011State) for the device model type and 14 //! the [`registers`] module for register types. 15 16 #![deny( 17 clippy::correctness, 18 clippy::suspicious, 19 clippy::complexity, 20 clippy::perf, 21 clippy::cargo, 22 clippy::nursery, 23 clippy::style 24 )] 25 #![allow(clippy::upper_case_acronyms)] 26 #![allow(clippy::result_unit_err)] 27 28 extern crate bilge; 29 extern crate bilge_impl; 30 extern crate qemu_api; 31 32 use qemu_api::c_str; 33 34 pub mod device; 35 pub mod device_class; 36 pub mod memory_ops; 37 38 pub const TYPE_PL011: &::std::ffi::CStr = c_str!("pl011"); 39 pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr = c_str!("pl011_luminary"); 40 41 /// Offset of each register from the base memory address of the device. 42 /// 43 /// # Source 44 /// ARM DDI 0183G, Table 3-1 p.3-3 45 #[doc(alias = "offset")] 46 #[allow(non_camel_case_types)] 47 #[repr(u64)] 48 #[derive(Debug)] 49 pub enum RegisterOffset { 50 /// Data Register 51 /// 52 /// A write to this register initiates the actual data transmission 53 #[doc(alias = "UARTDR")] 54 DR = 0x000, 55 /// Receive Status Register or Error Clear Register 56 #[doc(alias = "UARTRSR")] 57 #[doc(alias = "UARTECR")] 58 RSR = 0x004, 59 /// Flag Register 60 /// 61 /// A read of this register shows if transmission is complete 62 #[doc(alias = "UARTFR")] 63 FR = 0x018, 64 /// Fractional Baud Rate Register 65 /// 66 /// responsible for baud rate speed 67 #[doc(alias = "UARTFBRD")] 68 FBRD = 0x028, 69 /// `IrDA` Low-Power Counter Register 70 #[doc(alias = "UARTILPR")] 71 ILPR = 0x020, 72 /// Integer Baud Rate Register 73 /// 74 /// Responsible for baud rate speed 75 #[doc(alias = "UARTIBRD")] 76 IBRD = 0x024, 77 /// line control register (data frame format) 78 #[doc(alias = "UARTLCR_H")] 79 LCR_H = 0x02C, 80 /// Toggle UART, transmission or reception 81 #[doc(alias = "UARTCR")] 82 CR = 0x030, 83 /// Interrupt FIFO Level Select Register 84 #[doc(alias = "UARTIFLS")] 85 FLS = 0x034, 86 /// Interrupt Mask Set/Clear Register 87 #[doc(alias = "UARTIMSC")] 88 IMSC = 0x038, 89 /// Raw Interrupt Status Register 90 #[doc(alias = "UARTRIS")] 91 RIS = 0x03C, 92 /// Masked Interrupt Status Register 93 #[doc(alias = "UARTMIS")] 94 MIS = 0x040, 95 /// Interrupt Clear Register 96 #[doc(alias = "UARTICR")] 97 ICR = 0x044, 98 /// DMA control Register 99 #[doc(alias = "UARTDMACR")] 100 DMACR = 0x048, 101 ///// Reserved, offsets `0x04C` to `0x07C`. 102 //Reserved = 0x04C, 103 } 104 105 impl core::convert::TryFrom<u64> for RegisterOffset { 106 type Error = u64; 107 108 fn try_from(value: u64) -> Result<Self, Self::Error> { 109 macro_rules! case { 110 ($($discriminant:ident),*$(,)*) => { 111 /* check that matching on all macro arguments compiles, which means we are not 112 * missing any enum value; if the type definition ever changes this will stop 113 * compiling. 114 */ 115 const fn _assert_exhaustive(val: RegisterOffset) { 116 match val { 117 $(RegisterOffset::$discriminant => (),)* 118 } 119 } 120 121 match value { 122 $(x if x == Self::$discriminant as u64 => Ok(Self::$discriminant),)* 123 _ => Err(value), 124 } 125 } 126 } 127 case! { DR, RSR, FR, FBRD, ILPR, IBRD, LCR_H, CR, FLS, IMSC, RIS, MIS, ICR, DMACR } 128 } 129 } 130 131 pub mod registers { 132 //! Device registers exposed as typed structs which are backed by arbitrary 133 //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. 134 //! 135 //! All PL011 registers are essentially 32-bit wide, but are typed here as 136 //! bitmaps with only the necessary width. That is, if a struct bitmap 137 //! in this module is for example 16 bits long, it should be conceived 138 //! as a 32-bit register where the unmentioned higher bits are always 139 //! unused thus treated as zero when read or written. 140 use bilge::prelude::*; 141 142 /// Receive Status Register / Data Register common error bits 143 /// 144 /// The `UARTRSR` register is updated only when a read occurs 145 /// from the `UARTDR` register with the same status information 146 /// that can also be obtained by reading the `UARTDR` register 147 #[bitsize(8)] 148 #[derive(Clone, Copy, Default, DebugBits, FromBits)] 149 pub struct Errors { 150 pub framing_error: bool, 151 pub parity_error: bool, 152 pub break_error: bool, 153 pub overrun_error: bool, 154 _reserved_unpredictable: u4, 155 } 156 157 // TODO: FIFO Mode has different semantics 158 /// Data Register, `UARTDR` 159 /// 160 /// The `UARTDR` register is the data register. 161 /// 162 /// For words to be transmitted: 163 /// 164 /// - if the FIFOs are enabled, data written to this location is pushed onto 165 /// the transmit 166 /// FIFO 167 /// - if the FIFOs are not enabled, data is stored in the transmitter 168 /// holding register (the 169 /// bottom word of the transmit FIFO). 170 /// 171 /// The write operation initiates transmission from the UART. The data is 172 /// prefixed with a start bit, appended with the appropriate parity bit 173 /// (if parity is enabled), and a stop bit. The resultant word is then 174 /// transmitted. 175 /// 176 /// For received words: 177 /// 178 /// - if the FIFOs are enabled, the data byte and the 4-bit status (break, 179 /// frame, parity, 180 /// and overrun) is pushed onto the 12-bit wide receive FIFO 181 /// - if the FIFOs are not enabled, the data byte and status are stored in 182 /// the receiving 183 /// holding register (the bottom word of the receive FIFO). 184 /// 185 /// The received data byte is read by performing reads from the `UARTDR` 186 /// register along with the corresponding status information. The status 187 /// information can also be read by a read of the `UARTRSR/UARTECR` 188 /// register. 189 /// 190 /// # Note 191 /// 192 /// You must disable the UART before any of the control registers are 193 /// reprogrammed. When the UART is disabled in the middle of 194 /// transmission or reception, it completes the current character before 195 /// stopping. 196 /// 197 /// # Source 198 /// ARM DDI 0183G 3.3.1 Data Register, UARTDR 199 #[bitsize(32)] 200 #[derive(Clone, Copy, Default, DebugBits, FromBits)] 201 #[doc(alias = "UARTDR")] 202 pub struct Data { 203 pub data: u8, 204 pub errors: Errors, 205 _reserved: u16, 206 } 207 208 impl Data { 209 // bilge is not very const-friendly, unfortunately 210 pub const BREAK: Self = Self { value: 1 << 10 }; 211 } 212 213 // TODO: FIFO Mode has different semantics 214 /// Receive Status Register / Error Clear Register, `UARTRSR/UARTECR` 215 /// 216 /// The UARTRSR/UARTECR register is the receive status register/error clear 217 /// register. Receive status can also be read from the `UARTRSR` 218 /// register. If the status is read from this register, then the status 219 /// information for break, framing and parity corresponds to the 220 /// data character read from the [Data register](Data), `UARTDR` prior to 221 /// reading the UARTRSR register. The status information for overrun is 222 /// set immediately when an overrun condition occurs. 223 /// 224 /// 225 /// # Note 226 /// The received data character must be read first from the [Data 227 /// Register](Data), `UARTDR` before reading the error status associated 228 /// with that data character from the `UARTRSR` register. This read 229 /// sequence cannot be reversed, because the `UARTRSR` register is 230 /// updated only when a read occurs from the `UARTDR` register. However, 231 /// the status information can also be obtained by reading the `UARTDR` 232 /// register 233 /// 234 /// # Source 235 /// ARM DDI 0183G 3.3.2 Receive Status Register/Error Clear Register, 236 /// UARTRSR/UARTECR 237 #[bitsize(8)] 238 #[derive(Clone, Copy, DebugBits, FromBits)] 239 pub struct ReceiveStatusErrorClear { 240 pub errors: Errors, 241 } 242 243 impl ReceiveStatusErrorClear { 244 pub fn set_from_data(&mut self, data: Data) { 245 self.set_errors(data.errors()); 246 } 247 248 pub fn reset(&mut self) { 249 // All the bits are cleared to 0 on reset. 250 *self = Self::default(); 251 } 252 } 253 254 impl Default for ReceiveStatusErrorClear { 255 fn default() -> Self { 256 0.into() 257 } 258 } 259 260 #[bitsize(16)] 261 #[derive(Clone, Copy, DebugBits, FromBits)] 262 /// Flag Register, `UARTFR` 263 #[doc(alias = "UARTFR")] 264 pub struct Flags { 265 /// CTS Clear to send. This bit is the complement of the UART clear to 266 /// send, `nUARTCTS`, modem status input. That is, the bit is 1 267 /// when `nUARTCTS` is LOW. 268 pub clear_to_send: bool, 269 /// DSR Data set ready. This bit is the complement of the UART data set 270 /// ready, `nUARTDSR`, modem status input. That is, the bit is 1 when 271 /// `nUARTDSR` is LOW. 272 pub data_set_ready: bool, 273 /// DCD Data carrier detect. This bit is the complement of the UART data 274 /// carrier detect, `nUARTDCD`, modem status input. That is, the bit is 275 /// 1 when `nUARTDCD` is LOW. 276 pub data_carrier_detect: bool, 277 /// BUSY UART busy. If this bit is set to 1, the UART is busy 278 /// transmitting data. This bit remains set until the complete 279 /// byte, including all the stop bits, has been sent from the 280 /// shift register. This bit is set as soon as the transmit FIFO 281 /// becomes non-empty, regardless of whether the UART is enabled 282 /// or not. 283 pub busy: bool, 284 /// RXFE Receive FIFO empty. The meaning of this bit depends on the 285 /// state of the FEN bit in the UARTLCR_H register. If the FIFO 286 /// is disabled, this bit is set when the receive holding 287 /// register is empty. If the FIFO is enabled, the RXFE bit is 288 /// set when the receive FIFO is empty. 289 pub receive_fifo_empty: bool, 290 /// TXFF Transmit FIFO full. The meaning of this bit depends on the 291 /// state of the FEN bit in the UARTLCR_H register. If the FIFO 292 /// is disabled, this bit is set when the transmit holding 293 /// register is full. If the FIFO is enabled, the TXFF bit is 294 /// set when the transmit FIFO is full. 295 pub transmit_fifo_full: bool, 296 /// RXFF Receive FIFO full. The meaning of this bit depends on the state 297 /// of the FEN bit in the UARTLCR_H register. If the FIFO is 298 /// disabled, this bit is set when the receive holding register 299 /// is full. If the FIFO is enabled, the RXFF bit is set when 300 /// the receive FIFO is full. 301 pub receive_fifo_full: bool, 302 /// Transmit FIFO empty. The meaning of this bit depends on the state of 303 /// the FEN bit in the [Line Control register](LineControl), 304 /// `UARTLCR_H`. If the FIFO is disabled, this bit is set when the 305 /// transmit holding register is empty. If the FIFO is enabled, 306 /// the TXFE bit is set when the transmit FIFO is empty. This 307 /// bit does not indicate if there is data in the transmit shift 308 /// register. 309 pub transmit_fifo_empty: bool, 310 /// `RI`, is `true` when `nUARTRI` is `LOW`. 311 pub ring_indicator: bool, 312 _reserved_zero_no_modify: u7, 313 } 314 315 impl Flags { 316 pub fn reset(&mut self) { 317 *self = Self::default(); 318 } 319 } 320 321 impl Default for Flags { 322 fn default() -> Self { 323 let mut ret: Self = 0.into(); 324 // After reset TXFF, RXFF, and BUSY are 0, and TXFE and RXFE are 1 325 ret.set_receive_fifo_empty(true); 326 ret.set_transmit_fifo_empty(true); 327 ret 328 } 329 } 330 331 #[bitsize(16)] 332 #[derive(Clone, Copy, DebugBits, FromBits)] 333 /// Line Control Register, `UARTLCR_H` 334 #[doc(alias = "UARTLCR_H")] 335 pub struct LineControl { 336 /// BRK Send break. 337 /// 338 /// If this bit is set to `1`, a low-level is continually output on the 339 /// `UARTTXD` output, after completing transmission of the 340 /// current character. For the proper execution of the break command, 341 /// the software must set this bit for at least two complete 342 /// frames. For normal use, this bit must be cleared to `0`. 343 pub send_break: bool, 344 /// 1 PEN Parity enable: 345 /// 346 /// - 0 = parity is disabled and no parity bit added to the data frame 347 /// - 1 = parity checking and generation is enabled. 348 /// 349 /// See Table 3-11 on page 3-14 for the parity truth table. 350 pub parity_enabled: bool, 351 /// EPS Even parity select. Controls the type of parity the UART uses 352 /// during transmission and reception: 353 /// - 0 = odd parity. The UART generates or checks for an odd number of 354 /// 1s in the data and parity bits. 355 /// - 1 = even parity. The UART generates or checks for an even number 356 /// of 1s in the data and parity bits. 357 /// This bit has no effect when the `PEN` bit disables parity checking 358 /// and generation. See Table 3-11 on page 3-14 for the parity 359 /// truth table. 360 pub parity: Parity, 361 /// 3 STP2 Two stop bits select. If this bit is set to 1, two stop bits 362 /// are transmitted at the end of the frame. The receive 363 /// logic does not check for two stop bits being received. 364 pub two_stops_bits: bool, 365 /// FEN Enable FIFOs: 366 /// 0 = FIFOs are disabled (character mode) that is, the FIFOs become 367 /// 1-byte-deep holding registers 1 = transmit and receive FIFO 368 /// buffers are enabled (FIFO mode). 369 pub fifos_enabled: Mode, 370 /// WLEN Word length. These bits indicate the number of data bits 371 /// transmitted or received in a frame as follows: b11 = 8 bits 372 /// b10 = 7 bits 373 /// b01 = 6 bits 374 /// b00 = 5 bits. 375 pub word_length: WordLength, 376 /// 7 SPS Stick parity select. 377 /// 0 = stick parity is disabled 378 /// 1 = either: 379 /// • if the EPS bit is 0 then the parity bit is transmitted and checked 380 /// as a 1 • if the EPS bit is 1 then the parity bit is 381 /// transmitted and checked as a 0. This bit has no effect when 382 /// the PEN bit disables parity checking and generation. See Table 3-11 383 /// on page 3-14 for the parity truth table. 384 pub sticky_parity: bool, 385 /// 15:8 - Reserved, do not modify, read as zero. 386 _reserved_zero_no_modify: u8, 387 } 388 389 impl LineControl { 390 pub fn reset(&mut self) { 391 // All the bits are cleared to 0 when reset. 392 *self = 0.into(); 393 } 394 } 395 396 impl Default for LineControl { 397 fn default() -> Self { 398 0.into() 399 } 400 } 401 402 #[bitsize(1)] 403 #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] 404 /// `EPS` "Even parity select", field of [Line Control 405 /// register](LineControl). 406 pub enum Parity { 407 /// - 0 = odd parity. The UART generates or checks for an odd number of 408 /// 1s in the data and parity bits. 409 Odd = 0, 410 /// - 1 = even parity. The UART generates or checks for an even number 411 /// of 1s in the data and parity bits. 412 Even = 1, 413 } 414 415 #[bitsize(1)] 416 #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] 417 /// `FEN` "Enable FIFOs" or Device mode, field of [Line Control 418 /// register](LineControl). 419 pub enum Mode { 420 /// 0 = FIFOs are disabled (character mode) that is, the FIFOs become 421 /// 1-byte-deep holding registers 422 Character = 0, 423 /// 1 = transmit and receive FIFO buffers are enabled (FIFO mode). 424 FIFO = 1, 425 } 426 427 impl From<Mode> for bool { 428 fn from(val: Mode) -> Self { 429 matches!(val, Mode::FIFO) 430 } 431 } 432 433 #[bitsize(2)] 434 #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] 435 /// `WLEN` Word length, field of [Line Control register](LineControl). 436 /// 437 /// These bits indicate the number of data bits transmitted or received in a 438 /// frame as follows: 439 pub enum WordLength { 440 /// b11 = 8 bits 441 _8Bits = 0b11, 442 /// b10 = 7 bits 443 _7Bits = 0b10, 444 /// b01 = 6 bits 445 _6Bits = 0b01, 446 /// b00 = 5 bits. 447 _5Bits = 0b00, 448 } 449 450 /// Control Register, `UARTCR` 451 /// 452 /// The `UARTCR` register is the control register. All the bits are cleared 453 /// to `0` on reset except for bits `9` and `8` that are set to `1`. 454 /// 455 /// # Source 456 /// ARM DDI 0183G, 3.3.8 Control Register, `UARTCR`, Table 3-12 457 #[bitsize(16)] 458 #[doc(alias = "UARTCR")] 459 #[derive(Clone, Copy, DebugBits, FromBits)] 460 pub struct Control { 461 /// `UARTEN` UART enable: 0 = UART is disabled. If the UART is disabled 462 /// in the middle of transmission or reception, it completes the current 463 /// character before stopping. 1 = the UART is enabled. Data 464 /// transmission and reception occurs for either UART signals or SIR 465 /// signals depending on the setting of the SIREN bit. 466 pub enable_uart: bool, 467 /// `SIREN` `SIR` enable: 0 = IrDA SIR ENDEC is disabled. `nSIROUT` 468 /// remains LOW (no light pulse generated), and signal transitions on 469 /// SIRIN have no effect. 1 = IrDA SIR ENDEC is enabled. Data is 470 /// transmitted and received on nSIROUT and SIRIN. UARTTXD remains HIGH, 471 /// in the marking state. Signal transitions on UARTRXD or modem status 472 /// inputs have no effect. This bit has no effect if the UARTEN bit 473 /// disables the UART. 474 pub enable_sir: bool, 475 /// `SIRLP` SIR low-power IrDA mode. This bit selects the IrDA encoding 476 /// mode. If this bit is cleared to 0, low-level bits are transmitted as 477 /// an active high pulse with a width of 3/ 16th of the bit period. If 478 /// this bit is set to 1, low-level bits are transmitted with a pulse 479 /// width that is 3 times the period of the IrLPBaud16 input signal, 480 /// regardless of the selected bit rate. Setting this bit uses less 481 /// power, but might reduce transmission distances. 482 pub sir_lowpower_irda_mode: u1, 483 /// Reserved, do not modify, read as zero. 484 _reserved_zero_no_modify: u4, 485 /// `LBE` Loopback enable. If this bit is set to 1 and the SIREN bit is 486 /// set to 1 and the SIRTEST bit in the Test Control register, UARTTCR 487 /// on page 4-5 is set to 1, then the nSIROUT path is inverted, and fed 488 /// through to the SIRIN path. The SIRTEST bit in the test register must 489 /// be set to 1 to override the normal half-duplex SIR operation. This 490 /// must be the requirement for accessing the test registers during 491 /// normal operation, and SIRTEST must be cleared to 0 when loopback 492 /// testing is finished. This feature reduces the amount of external 493 /// coupling required during system test. If this bit is set to 1, and 494 /// the SIRTEST bit is set to 0, the UARTTXD path is fed through to the 495 /// UARTRXD path. In either SIR mode or UART mode, when this bit is set, 496 /// the modem outputs are also fed through to the modem inputs. This bit 497 /// is cleared to 0 on reset, to disable loopback. 498 pub enable_loopback: bool, 499 /// `TXE` Transmit enable. If this bit is set to 1, the transmit section 500 /// of the UART is enabled. Data transmission occurs for either UART 501 /// signals, or SIR signals depending on the setting of the SIREN bit. 502 /// When the UART is disabled in the middle of transmission, it 503 /// completes the current character before stopping. 504 pub enable_transmit: bool, 505 /// `RXE` Receive enable. If this bit is set to 1, the receive section 506 /// of the UART is enabled. Data reception occurs for either UART 507 /// signals or SIR signals depending on the setting of the SIREN bit. 508 /// When the UART is disabled in the middle of reception, it completes 509 /// the current character before stopping. 510 pub enable_receive: bool, 511 /// `DTR` Data transmit ready. This bit is the complement of the UART 512 /// data transmit ready, `nUARTDTR`, modem status output. That is, when 513 /// the bit is programmed to a 1 then `nUARTDTR` is LOW. 514 pub data_transmit_ready: bool, 515 /// `RTS` Request to send. This bit is the complement of the UART 516 /// request to send, `nUARTRTS`, modem status output. That is, when the 517 /// bit is programmed to a 1 then `nUARTRTS` is LOW. 518 pub request_to_send: bool, 519 /// `Out1` This bit is the complement of the UART Out1 (`nUARTOut1`) 520 /// modem status output. That is, when the bit is programmed to a 1 the 521 /// output is 0. For DTE this can be used as Data Carrier Detect (DCD). 522 pub out_1: bool, 523 /// `Out2` This bit is the complement of the UART Out2 (`nUARTOut2`) 524 /// modem status output. That is, when the bit is programmed to a 1, the 525 /// output is 0. For DTE this can be used as Ring Indicator (RI). 526 pub out_2: bool, 527 /// `RTSEn` RTS hardware flow control enable. If this bit is set to 1, 528 /// RTS hardware flow control is enabled. Data is only requested when 529 /// there is space in the receive FIFO for it to be received. 530 pub rts_hardware_flow_control_enable: bool, 531 /// `CTSEn` CTS hardware flow control enable. If this bit is set to 1, 532 /// CTS hardware flow control is enabled. Data is only transmitted when 533 /// the `nUARTCTS` signal is asserted. 534 pub cts_hardware_flow_control_enable: bool, 535 } 536 537 impl Control { 538 pub fn reset(&mut self) { 539 *self = 0.into(); 540 self.set_enable_receive(true); 541 self.set_enable_transmit(true); 542 } 543 } 544 545 impl Default for Control { 546 fn default() -> Self { 547 let mut ret: Self = 0.into(); 548 ret.reset(); 549 ret 550 } 551 } 552 553 /// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC 554 pub const INT_OE: u32 = 1 << 10; 555 pub const INT_BE: u32 = 1 << 9; 556 pub const INT_PE: u32 = 1 << 8; 557 pub const INT_FE: u32 = 1 << 7; 558 pub const INT_RT: u32 = 1 << 6; 559 pub const INT_TX: u32 = 1 << 5; 560 pub const INT_RX: u32 = 1 << 4; 561 pub const INT_DSR: u32 = 1 << 3; 562 pub const INT_DCD: u32 = 1 << 2; 563 pub const INT_CTS: u32 = 1 << 1; 564 pub const INT_RI: u32 = 1 << 0; 565 pub const INT_E: u32 = INT_OE | INT_BE | INT_PE | INT_FE; 566 pub const INT_MS: u32 = INT_RI | INT_DSR | INT_DCD | INT_CTS; 567 568 #[repr(u32)] 569 pub enum Interrupt { 570 OE = 1 << 10, 571 BE = 1 << 9, 572 PE = 1 << 8, 573 FE = 1 << 7, 574 RT = 1 << 6, 575 TX = 1 << 5, 576 RX = 1 << 4, 577 DSR = 1 << 3, 578 DCD = 1 << 2, 579 CTS = 1 << 1, 580 RI = 1 << 0, 581 } 582 583 impl Interrupt { 584 pub const E: u32 = INT_OE | INT_BE | INT_PE | INT_FE; 585 pub const MS: u32 = INT_RI | INT_DSR | INT_DCD | INT_CTS; 586 } 587 } 588 589 // TODO: You must disable the UART before any of the control registers are 590 // reprogrammed. When the UART is disabled in the middle of transmission or 591 // reception, it completes the current character before stopping 592