aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmaple/usart.c2
-rw-r--r--wirish/comm/HardwareSerial.cpp19
-rw-r--r--wirish/comm/HardwareSerial.h4
3 files changed, 14 insertions, 11 deletions
diff --git a/libmaple/usart.c b/libmaple/usart.c
index de808a7..7fe4f53 100644
--- a/libmaple/usart.c
+++ b/libmaple/usart.c
@@ -99,7 +99,7 @@ void usart_init(usart_dev *dev) {
* @brief Configure a serial port's baud rate.
*
* @param dev Serial port to be configured
- * @param clock_speed MCU clock speed, in megahertz.
+ * @param clock_speed Clock speed, in megahertz.
* @param baud Baud rate for transmit/receive.
*/
void usart_set_baud_rate(usart_dev *dev, uint32 clock_speed, uint32 baud) {
diff --git a/wirish/comm/HardwareSerial.cpp b/wirish/comm/HardwareSerial.cpp
index aa8855b..5c9bff6 100644
--- a/wirish/comm/HardwareSerial.cpp
+++ b/wirish/comm/HardwareSerial.cpp
@@ -46,18 +46,21 @@
#define RX5 BOARD_UART5_RX_PIN
#endif
-HardwareSerial Serial1(USART1, TX1, RX1);
-HardwareSerial Serial2(USART2, TX2, RX2);
-HardwareSerial Serial3(USART3, TX3, RX3);
+// TODO Put these magic numbers into boards.h #defines
+HardwareSerial Serial1(USART1, TX1, RX1, 72000000UL);
+HardwareSerial Serial2(USART2, TX2, RX2, 36000000UL);
+HardwareSerial Serial3(USART3, TX3, RX3, 36000000UL);
#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
-HardwareSerial Serial4(UART4, TX4, RX4);
-HardwareSerial Serial5(UART5, TX5, RX5);
+HardwareSerial Serial4(UART4, TX4, RX4, 36000000UL);
+HardwareSerial Serial5(UART5, TX5, RX5, 36000000UL);
#endif
HardwareSerial::HardwareSerial(usart_dev *usart_device,
uint8 tx_pin,
- uint8 rx_pin) {
+ uint8 rx_pin,
+ uint32 clock_speed) {
this->usart_device = usart_device;
+ this->clock_speed = clock_speed;
this->tx_pin = tx_pin;
this->rx_pin = rx_pin;
}
@@ -93,9 +96,7 @@ void HardwareSerial::begin(uint32 baud) {
}
usart_init(usart_device);
- usart_set_baud_rate(usart_device,
- CYCLES_PER_MICROSECOND * 1000000UL,
- baud);
+ usart_set_baud_rate(usart_device, clock_speed, baud);
usart_enable(usart_device);
}
diff --git a/wirish/comm/HardwareSerial.h b/wirish/comm/HardwareSerial.h
index 5e86f79..934db23 100644
--- a/wirish/comm/HardwareSerial.h
+++ b/wirish/comm/HardwareSerial.h
@@ -50,7 +50,8 @@ class HardwareSerial : public Print {
public:
HardwareSerial(usart_dev *usart_device,
uint8 tx_pin,
- uint8 rx_pin);
+ uint8 rx_pin,
+ uint32 clock_speed);
void begin(uint32 baud);
void end(void);
uint32 available(void);
@@ -62,6 +63,7 @@ private:
usart_dev *usart_device;
uint8 tx_pin;
uint8 rx_pin;
+ uint32 clock_speed;
};
extern HardwareSerial Serial1;