aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/machine_stm32f7x2.go
diff options
context:
space:
mode:
authorkenbell <[email protected]>2020-12-14 21:51:35 -0800
committerGitHub <[email protected]>2020-12-15 06:51:35 +0100
commit43a31467d36412978804d54a71655695d31a1eb4 (patch)
tree5209b0c663485e0d0e65e06133832bf787125f65 /src/machine/machine_stm32f7x2.go
parentae92ea149c30bb90082a627d30d663b3359a6e4c (diff)
downloadtinygo-43a31467d36412978804d54a71655695d31a1eb4.tar.gz
tinygo-43a31467d36412978804d54a71655695d31a1eb4.zip
Nucleo f722ze (#1526)
machine/nucleo-f722ze: Add support for ST Micro NUCLEO-F722ZE
Diffstat (limited to 'src/machine/machine_stm32f7x2.go')
-rw-r--r--src/machine/machine_stm32f7x2.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/machine/machine_stm32f7x2.go b/src/machine/machine_stm32f7x2.go
new file mode 100644
index 000000000..632a77005
--- /dev/null
+++ b/src/machine/machine_stm32f7x2.go
@@ -0,0 +1,44 @@
+// +build stm32f7x2
+
+package machine
+
+// Peripheral abstraction layer for the stm32f407
+
+import (
+ "device/stm32"
+ "runtime/interrupt"
+)
+
+func CPUFrequency() uint32 {
+ return 216000000
+}
+
+//---------- UART related types and code
+
+// UART representation
+type UART struct {
+ Buffer *RingBuffer
+ Bus *stm32.USART_Type
+ Interrupt interrupt.Interrupt
+ AltFuncSelector stm32.AltFunc
+}
+
+// Configure the UART.
+func (uart UART) configurePins(config UARTConfig) {
+ // enable the alternate functions on the TX and RX pins
+ config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.AltFuncSelector)
+ config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.AltFuncSelector)
+}
+
+// UART baudrate calc based on the bus and clockspeed
+// NOTE: keep this in sync with the runtime/runtime_stm32f7x2.go clock init code
+func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 {
+ var clock uint32
+ switch uart.Bus {
+ case stm32.USART1, stm32.USART6:
+ clock = CPUFrequency() / 2 // APB2 Frequency
+ case stm32.USART2, stm32.USART3, stm32.UART4, stm32.UART5:
+ clock = CPUFrequency() / 8 // APB1 Frequency
+ }
+ return clock / baudRate
+}