diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-08-28 19:36:00 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-08-28 19:44:52 -0400 |
commit | 27e3863a0558a21b4364a39595873e5902d87464 (patch) | |
tree | fd9d1b9dfc8fa8489f9cda347a4e5a5c19e28aa1 /watch-library/watch/watch_uart.c | |
parent | 048b5c1d3fdc9c58acccd5558fd3254fbf19ece8 (diff) | |
download | Sensor-Watch-27e3863a0558a21b4364a39595873e5902d87464.tar.gz Sensor-Watch-27e3863a0558a21b4364a39595873e5902d87464.tar.bz2 Sensor-Watch-27e3863a0558a21b4364a39595873e5902d87464.zip |
add alternate _write for debugging USB issues
Diffstat (limited to 'watch-library/watch/watch_uart.c')
-rw-r--r-- | watch-library/watch/watch_uart.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/watch-library/watch/watch_uart.c b/watch-library/watch/watch_uart.c index 68ac872e..afebff1b 100644 --- a/watch-library/watch/watch_uart.c +++ b/watch-library/watch/watch_uart.c @@ -53,8 +53,25 @@ #include "peripheral_clk_config.h" void watch_enable_debug_uart(uint32_t baud) { - /// FIXME: UART baud rate calculation will be incorrect if plugged into USB / running at 16 MHz - uint64_t br = (uint64_t)65536 * (CONF_CPU_FREQUENCY - 16 * baud) / CONF_CPU_FREQUENCY; + uint8_t fsel = hri_oscctrl_get_OSC16MCTRL_FSEL_bf(OSCCTRL, OSCCTRL_OSC16MCTRL_MASK); + uint32_t freq = 0; + switch (fsel) { + case OSCCTRL_OSC16MCTRL_FSEL_4_Val: + freq = 4000000; + break; + case OSCCTRL_OSC16MCTRL_FSEL_8_Val: + freq = 8000000; + break; + case OSCCTRL_OSC16MCTRL_FSEL_12_Val: + freq = 12000000; + break; + case OSCCTRL_OSC16MCTRL_FSEL_16_Val: + freq = 16000000; + break; + default: + return; + } + uint64_t br = (uint64_t)65536 * ((freq * 4) - 16 * baud) / (freq * 4); gpio_set_pin_direction(D1, GPIO_DIRECTION_IN); gpio_set_pin_function(D1, PINMUX_PB00C_SERCOM3_PAD2); |