Skip to content

Commit 0afffde

Browse files
cfsamsonandre-richter
authored andcommitted
Added short explanation of the BRD calculations for setting up UART re #70
1 parent 14be6a5 commit 0afffde

File tree

10 files changed

+60
-20
lines changed

10 files changed

+60
-20
lines changed

06_drivers_gpio_uart/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

07_uart_chainloader/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

08_timestamps/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

09_hw_debug_JTAG/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

10_privilege_level/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

11_virtual_memory/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

12_exceptions_part1_groundwork/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

13_integrated_testing/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

14_exceptions_part2_peripheral_IRQs/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ impl PL011UartInner {
226226

227227
/// Set up baud rate and characteristics.
228228
///
229-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
230-
/// firmware).
229+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
230+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
231+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
232+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
233+
///
234+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
231235
pub fn init(&mut self) {
232236
// Turn it off temporarily.
233237
self.registers.CR.set(0);

X1_JTAG_boot/src/bsp/device_driver/bcm/bcm2xxx_pl011_uart.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ impl PL011UartInner {
174174

175175
/// Set up baud rate and characteristics.
176176
///
177-
/// Results in 8N1 and 230400 baud (if the clk has been previously set to 48 MHz by the
178-
/// firmware).
177+
/// The calculation for the BRD given a target rate of 2300400 and a clock set to 48 MHz is:
178+
/// `(48_000_000/16)/230400 = 13,02083`. `13` goes to the `IBRD` (integer field). The `FBRD`
179+
/// (fractional field) is only 6 bits so `0,0208*64 = 1,3312 rounded to 1` will give the best
180+
/// approximation we can get. A 5 % error margin is acceptable for UART and we're now at 0,01 %.
181+
///
182+
/// This results in 8N1 and 230400 baud (we set the clock to 48 MHz in config.txt).
179183
pub fn init(&mut self) {
180184
// Turn it off temporarily.
181185
self.registers.CR.set(0);

0 commit comments

Comments
 (0)