tinygo/src/machine/machine_stm32f7x2.go
2021-02-16 12:48:52 +01:00

43 строки
1,2 КиБ
Go

// +build stm32f7x2
package machine
// Peripheral abstraction layer for the stm32f407
import (
"device/stm32"
)
func CPUFrequency() uint32 {
return 216000000
}
//---------- UART related code
// 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
}
// Register names vary by ST processor, these are for STM F7x2
func (uart *UART) setRegisters() {
uart.rxReg = &uart.Bus.RDR
uart.txReg = &uart.Bus.TDR
uart.statusReg = &uart.Bus.ISR
uart.txEmptyFlag = stm32.USART_ISR_TXE
}