From ee52e8e288ef6f00416eed94921c2b0e1acfab73 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Fri, 1 Jan 2021 23:12:42 +0100 Subject: [PATCH] Bump UART to 576000 baud --- 06_drivers_gpio_uart/README.md | 18 ++++++++++-------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- 07_uart_chainloader/README.md | 4 ++-- 07_uart_chainloader/demo_payload_rpi3.img | Bin 6712 -> 6720 bytes 07_uart_chainloader/demo_payload_rpi4.img | Bin 6592 -> 6600 bytes .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- 08_timestamps/README.md | 2 +- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- 14_exceptions_part2_peripheral_IRQs/README.md | 12 ++++++------ .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- 15_virtual_mem_part2_mmio_remap/README.md | 16 ++++++++-------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- .../device_driver/bcm/bcm2xxx_pl011_uart.rs | 16 +++++++++------- utils/miniterm.rb | 2 +- 19 files changed, 127 insertions(+), 103 deletions(-) diff --git a/06_drivers_gpio_uart/README.md b/06_drivers_gpio_uart/README.md index 33df63e8..0588109d 100644 --- a/06_drivers_gpio_uart/README.md +++ b/06_drivers_gpio_uart/README.md @@ -433,7 +433,7 @@ diff -uNr 05_safe_globals/src/bsp/device_driver/bcm/bcm2xxx_gpio.rs 06_drivers_g diff -uNr 05_safe_globals/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs 06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs --- 05_safe_globals/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ 06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs -@@ -0,0 +1,305 @@ +@@ -0,0 +1,307 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2018-2021 Andre Richter @@ -610,19 +610,21 @@ diff -uNr 05_safe_globals/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs 06_dri + + /// Set up baud rate and characteristics. + /// -+ /// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is: -+ /// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD` -+ /// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best -+ /// approximation we can get. A 5 modulo error margin is acceptable for UART and we're now at 0,01 modulo. ++ /// This results in 8N1 and 576000 baud (we set the clock to 48 MHz in config.txt). + /// -+ /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). ++ /// The calculation for the BRD given a target rate of 576000 and a clock set to 48 MHz is: ++ /// `(48_000_000 / 16) / 576000 = 5.2083`. `5` goes to the `IBRD` (integer field). ++ /// ++ /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will ++ /// give the best approximation we can get. A 5 modulo error margin is acceptable for UART and we're ++ /// now at 0.01 modulo. + pub fn init(&mut self) { + // Turn it off temporarily. + self.registers.CR.set(0); + + self.registers.ICR.write(ICR::ALL::CLEAR); -+ self.registers.IBRD.write(IBRD::IBRD.val(13)); -+ self.registers.FBRD.write(FBRD::FBRD.val(1)); ++ self.registers.IBRD.write(IBRD::IBRD.val(5)); ++ self.registers.FBRD.write(FBRD::FBRD.val(13)); + self.registers + .LCRH + .write(LCRH::WLEN::EightBit + LCRH::FEN::FifosEnabled); // 8N1 + Fifo on diff --git a/06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs b/06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs index de0bf813..fdd92f65 100644 --- a/06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ b/06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs @@ -174,19 +174,21 @@ impl PL011UartInner { /// Set up baud rate and characteristics. /// - /// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is: - /// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD` - /// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best - /// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %. + /// This results in 8N1 and 576000 baud (we set the clock to 48 MHz in config.txt). /// - /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). + /// The calculation for the BRD given a target rate of 576000 and a clock set to 48 MHz is: + /// `(48_000_000 / 16) / 576000 = 5.2083`. `5` goes to the `IBRD` (integer field). + /// + /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will + /// give the best approximation we can get. A 5 % error margin is acceptable for UART and we're + /// now at 0.01 %. pub fn init(&mut self) { // Turn it off temporarily. self.registers.CR.set(0); self.registers.ICR.write(ICR::ALL::CLEAR); - self.registers.IBRD.write(IBRD::IBRD.val(13)); - self.registers.FBRD.write(FBRD::FBRD.val(1)); + self.registers.IBRD.write(IBRD::IBRD.val(5)); + self.registers.FBRD.write(FBRD::FBRD.val(13)); self.registers .LCRH .write(LCRH::WLEN::EightBit + LCRH::FEN::FifosEnabled); // 8N1 + Fifo on diff --git a/07_uart_chainloader/README.md b/07_uart_chainloader/README.md index 1491c84b..2b7d797b 100644 --- a/07_uart_chainloader/README.md +++ b/07_uart_chainloader/README.md @@ -222,7 +222,7 @@ diff -uNr 06_drivers_gpio_uart/src/_arch/aarch64/cpu.rs 07_uart_chainloader/src/ diff -uNr 06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs 07_uart_chainloader/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs --- 06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ 07_uart_chainloader/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs -@@ -268,6 +268,15 @@ +@@ -270,6 +270,15 @@ // readability. self.inner.lock(|inner| fmt::Write::write_fmt(inner, args)) } @@ -238,7 +238,7 @@ diff -uNr 06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs 0 } impl console::interface::Read for PL011Uart { -@@ -278,18 +287,20 @@ +@@ -280,18 +289,20 @@ cpu::nop(); } diff --git a/07_uart_chainloader/demo_payload_rpi3.img b/07_uart_chainloader/demo_payload_rpi3.img index a002d0525555b040896b5c76cbfb2571010361bd..983c85c293b8c3a8cf564f8951f2ae20016e22c5 100755 GIT binary patch delta 1105 zcmaJ@g6q<^N z;DDQ&b{Z|>8_cs zd-YP|O9xzK0Qbzdz~e?CBK5Hb2=W5d<|qX zmslH*-^ADQAS)G8j_pihZFpMQD5(J)bw+VkxgoJYVbr;cDO9TW7M|68lUcm*ba_=` zZ}4g3es%?QkHLm;#FJpR@rtKU@6dQf25#0l^LAr#Si#Lc;N^Blek+Mq+LgSUaD4*5 zdbYU765IzcdGa<6c$?iU%IDT=GzcE|rri@!{!pS84SeM7tUsINrtF_8`@m|z&)#Ii z*%n@|)<~%&r4BL!PpO>^r6?!i$pI3xe^oaty)8D$7qydVm}+X)qW#w0C^S7+fIr>< zW9!)E$hIi%ZfZUh?zb)xdNiz9^;*AmIcyY^dZGI4xR(tT!Eg`5CEC%tQX#WIlQG+cABG^>K zi>>W2f+xY?X$yi7mF8qhp%f3Lp!6u43KC;I^q_RBb^SKGLa7c6?Dx%^_ujnyiXC$u zFYB24_crtxBlJ@Jgh)ipH!(@`N?9OU#!&` zJWm(v2k|70x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ij@yDotIv}cy zxbNd#ymdk3L&85JeEdqh^?rRp{CNK2vDPSkX^%#JPr*1#R43FFcxA1J>70zX`Z646#$STa|Jhtt5SB zMFd)n*^UDHUaJvckw7}tr_(W9w~_?69sw8_zlZ&=1T%>DgBKQ2KSn=chXM&=uycWW zy--h6I5mv<+d|yswsVsCEmvitN&~vV#sf)z{~|gehOSOANogegtXa|U^Uca8heS!P zE!WcyB&l2$%}Lv5+D|02(ZOl3JdzNdxCr#ENa(d0`%GSf^cN89giMYqL(ojMBcJ$@C}NR#BD#fH)N~?#eb$ zAI2jS4ep#CDW93fSq;$e)R`kcYO|UoqjU_N+Y=78G)d?w=47~5ed@!xv`jzCE& z<2Nack#)rXu@_+5(jOj~S77sk@tPqCZaGHqR7Y@47Uf4bN?I67a;rA%NGlh#;p&=v zrn;;RH)Szmy|T--Z=mCRf;uX-W8Y*#H0>N(n*g*y;_^Gn5&HH%&}Qe~un$2)!Xfw+ zn?sS_cI0eC&i21K%Q~&h0&6lUnx5Tp>hhwkf84+s4ri6aIc=}_N6C@6r=*c^dmJST z>}Dt!yfouzZdikEMC~UQ6rYEBiIR`vpubLuZHcJ*#fX>1cj%rH#{$P^+0n?l+-cS8 z3h=BN^DwUJo&v9jINr}OzG(OS-@lXBe^2e=xQh30=a_FHfXX(iyJJIq>?ki^;rKHf xQ#E-s char { @@ -2003,7 +2003,7 @@ diff -uNr 13_integrated_testing/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs } fn clear(&self) { -@@ -321,3 +410,24 @@ +@@ -323,3 +412,24 @@ self.inner.lock(|inner| inner.chars_read) } } diff --git a/14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs b/14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs index 29bf95c1..9504cfc3 100644 --- a/14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ b/14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs @@ -226,19 +226,21 @@ impl PL011UartInner { /// Set up baud rate and characteristics. /// - /// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is: - /// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD` - /// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best - /// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %. + /// This results in 8N1 and 576000 baud (we set the clock to 48 MHz in config.txt). /// - /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). + /// The calculation for the BRD given a target rate of 576000 and a clock set to 48 MHz is: + /// `(48_000_000 / 16) / 576000 = 5.2083`. `5` goes to the `IBRD` (integer field). + /// + /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will + /// give the best approximation we can get. A 5 % error margin is acceptable for UART and we're + /// now at 0.01 %. pub fn init(&mut self) { // Turn it off temporarily. self.registers.CR.set(0); self.registers.ICR.write(ICR::ALL::CLEAR); - self.registers.IBRD.write(IBRD::IBRD.val(13)); - self.registers.FBRD.write(FBRD::FBRD.val(1)); + self.registers.IBRD.write(IBRD::IBRD.val(5)); + self.registers.FBRD.write(FBRD::FBRD.val(13)); self.registers .LCRH .write(LCRH::WLEN::EightBit + LCRH::FEN::FifosEnabled); // 8N1 + Fifo on diff --git a/15_virtual_mem_part2_mmio_remap/README.md b/15_virtual_mem_part2_mmio_remap/README.md index ab11fbfa..77f6ad62 100644 --- a/15_virtual_mem_part2_mmio_remap/README.md +++ b/15_virtual_mem_part2_mmio_remap/README.md @@ -1304,10 +1304,10 @@ diff -uNr 14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_ inner: IRQSafeNullLock, irq_number: bsp::device_driver::IRQNumber, } -@@ -232,7 +237,15 @@ - /// approximation we can get. A 5 modulo error margin is acceptable for UART and we're now at 0,01 modulo. - /// - /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). +@@ -234,7 +239,15 @@ + /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will + /// give the best approximation we can get. A 5 modulo error margin is acceptable for UART and we're + /// now at 0.01 modulo. - pub fn init(&mut self) { + /// + /// # Safety @@ -1321,7 +1321,7 @@ diff -uNr 14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_ // Turn it off temporarily. self.registers.CR.set(0); -@@ -249,6 +262,8 @@ +@@ -251,6 +264,8 @@ self.registers .CR .write(CR::UARTEN::Enabled + CR::TXE::Enabled + CR::RXE::Enabled); @@ -1330,7 +1330,7 @@ diff -uNr 14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_ } /// Send a character. -@@ -318,13 +333,18 @@ +@@ -320,13 +335,18 @@ /// /// # Safety /// @@ -1352,7 +1352,7 @@ diff -uNr 14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_ irq_number, } } -@@ -341,7 +361,14 @@ +@@ -343,7 +363,14 @@ } unsafe fn init(&self) -> Result<(), &'static str> { @@ -1368,7 +1368,7 @@ diff -uNr 14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_ Ok(()) } -@@ -360,6 +387,16 @@ +@@ -362,6 +389,16 @@ Ok(()) } diff --git a/15_virtual_mem_part2_mmio_remap/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs b/15_virtual_mem_part2_mmio_remap/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs index c2354d43..b2fc254b 100644 --- a/15_virtual_mem_part2_mmio_remap/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ b/15_virtual_mem_part2_mmio_remap/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs @@ -231,12 +231,14 @@ impl PL011UartInner { /// Set up baud rate and characteristics. /// - /// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is: - /// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD` - /// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best - /// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %. + /// This results in 8N1 and 576000 baud (we set the clock to 48 MHz in config.txt). /// - /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). + /// The calculation for the BRD given a target rate of 576000 and a clock set to 48 MHz is: + /// `(48_000_000 / 16) / 576000 = 5.2083`. `5` goes to the `IBRD` (integer field). + /// + /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will + /// give the best approximation we can get. A 5 % error margin is acceptable for UART and we're + /// now at 0.01 %. /// /// # Safety /// @@ -250,8 +252,8 @@ impl PL011UartInner { self.registers.CR.set(0); self.registers.ICR.write(ICR::ALL::CLEAR); - self.registers.IBRD.write(IBRD::IBRD.val(13)); - self.registers.FBRD.write(FBRD::FBRD.val(1)); + self.registers.IBRD.write(IBRD::IBRD.val(5)); + self.registers.FBRD.write(FBRD::FBRD.val(13)); self.registers .LCRH .write(LCRH::WLEN::EightBit + LCRH::FEN::FifosEnabled); // 8N1 + Fifo on diff --git a/X1_JTAG_boot/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs b/X1_JTAG_boot/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs index 66b73463..46cceff9 100644 --- a/X1_JTAG_boot/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs +++ b/X1_JTAG_boot/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs @@ -174,19 +174,21 @@ impl PL011UartInner { /// Set up baud rate and characteristics. /// - /// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is: - /// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD` - /// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best - /// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %. + /// This results in 8N1 and 576000 baud (we set the clock to 48 MHz in config.txt). /// - /// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt). + /// The calculation for the BRD given a target rate of 576000 and a clock set to 48 MHz is: + /// `(48_000_000 / 16) / 576000 = 5.2083`. `5` goes to the `IBRD` (integer field). + /// + /// The `FBRD` (fractional field) is only 6 bits so `0.2083 * 64 = 13.3 rounded to 13` will + /// give the best approximation we can get. A 5 % error margin is acceptable for UART and we're + /// now at 0.01 %. pub fn init(&mut self) { // Turn it off temporarily. self.registers.CR.set(0); self.registers.ICR.write(ICR::ALL::CLEAR); - self.registers.IBRD.write(IBRD::IBRD.val(13)); - self.registers.FBRD.write(FBRD::FBRD.val(1)); + self.registers.IBRD.write(IBRD::IBRD.val(5)); + self.registers.FBRD.write(FBRD::FBRD.val(13)); self.registers .LCRH .write(LCRH::WLEN::EightBit + LCRH::FEN::FifosEnabled); // 8N1 + Fifo on diff --git a/utils/miniterm.rb b/utils/miniterm.rb index 0875ada5..010761cd 100755 --- a/utils/miniterm.rb +++ b/utils/miniterm.rb @@ -41,7 +41,7 @@ class MiniTerm def open_serial wait_for_serial - @target_serial = SerialPort.new(@target_serial_name, 230_400, 8, 1, SerialPort::NONE) + @target_serial = SerialPort.new(@target_serial_name, 576_000, 8, 1, SerialPort::NONE) # Ensure all output is immediately flushed to the device. @target_serial.sync = true