remove (or stub) UART/SPI/I2C peripheral code from initial feather-stm32f405 board support
Этот коммит содержится в:
родитель
097f628955
коммит
cf6b544cd9
2 изменённых файлов: 10 добавлений и 123 удалений
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
package machine
|
package machine
|
||||||
|
|
||||||
import (
|
|
||||||
"device/stm32"
|
|
||||||
"runtime/interrupt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NUM_DIGITAL_IO_PINS = 39
|
NUM_DIGITAL_IO_PINS = 39
|
||||||
NUM_ANALOG_IO_PINS = 7
|
NUM_ANALOG_IO_PINS = 7
|
||||||
|
@ -94,34 +89,6 @@ const (
|
||||||
UART3_TX_PIN = D15
|
UART3_TX_PIN = D15
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// TBD: why do UART0 and UART1 have different types (struct vs reference)?
|
|
||||||
UART0 = UART{
|
|
||||||
Buffer: NewRingBuffer(),
|
|
||||||
Bus: stm32.USART3,
|
|
||||||
AltFuncSelector: stm32.AF7_USART1_2_3,
|
|
||||||
}
|
|
||||||
UART1 = &UART0
|
|
||||||
|
|
||||||
// UART2 = &UART{
|
|
||||||
// Buffer: NewRingBuffer(),
|
|
||||||
// Bus: stm32.USART6,
|
|
||||||
// AltFuncSelector: stm32.AF8_USART4_5_6,
|
|
||||||
// }
|
|
||||||
// UART3 = &UART{
|
|
||||||
// Buffer: NewRingBuffer(),
|
|
||||||
// Bus: stm32.USART1,
|
|
||||||
// AltFuncSelector: stm32.AF7_USART1_2_3,
|
|
||||||
// }
|
|
||||||
)
|
|
||||||
|
|
||||||
// set up RX IRQ handler. Follow similar pattern for other UARTx instances
|
|
||||||
func init() {
|
|
||||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART3, UART0.handleInterrupt)
|
|
||||||
//UART2.Interrupt = interrupt.New(stm32.IRQ_USART6, UART2.handleInterrupt)
|
|
||||||
//UART3.Interrupt = interrupt.New(stm32.IRQ_USART1, UART3.handleInterrupt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SPI pins
|
// SPI pins
|
||||||
const (
|
const (
|
||||||
NUM_SPI_INTERFACES = 3
|
NUM_SPI_INTERFACES = 3
|
||||||
|
@ -145,23 +112,3 @@ const (
|
||||||
SPI3_SDI_PIN = D18
|
SPI3_SDI_PIN = D18
|
||||||
SPI3_SDO_PIN = D19
|
SPI3_SDO_PIN = D19
|
||||||
)
|
)
|
||||||
|
|
||||||
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
|
||||||
// TODO: implement SPI2 and SPI3.
|
|
||||||
var (
|
|
||||||
// TBD: why do SPI0 and SPI1 have different types (struct vs reference)?
|
|
||||||
SPI0 = SPI{
|
|
||||||
Bus: stm32.SPI2,
|
|
||||||
AltFuncSelector: stm32.AF5_SPI1_SPI2,
|
|
||||||
}
|
|
||||||
SPI1 = &SPI0
|
|
||||||
|
|
||||||
// SPI2 = &SPI{
|
|
||||||
// Bus: stm32.SPI3,
|
|
||||||
// AltFuncSelector: stm32.AF6_SPI3,
|
|
||||||
// }
|
|
||||||
// SPI3 = &SPI{
|
|
||||||
// Bus: stm32.SPI1,
|
|
||||||
// AltFuncSelector: stm32.AF5_SPI1_SPI2,
|
|
||||||
// }
|
|
||||||
)
|
|
||||||
|
|
|
@ -13,9 +13,8 @@ func CPUFrequency() uint32 {
|
||||||
return 168000000
|
return 168000000
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- UART related types and code
|
// -- UART ---------------------------------------------------------------------
|
||||||
|
|
||||||
// UART representation
|
|
||||||
type UART struct {
|
type UART struct {
|
||||||
Buffer *RingBuffer
|
Buffer *RingBuffer
|
||||||
Bus *stm32.USART_Type
|
Bus *stm32.USART_Type
|
||||||
|
@ -23,81 +22,22 @@ type UART struct {
|
||||||
AltFuncSelector stm32.AltFunc
|
AltFuncSelector stm32.AltFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the UART.
|
func (uart UART) configurePins(config UARTConfig) {}
|
||||||
func (uart UART) configurePins(config UARTConfig) {
|
func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 { return 0 }
|
||||||
// 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
|
// -- SPI ----------------------------------------------------------------------
|
||||||
// NOTE: keep this in sync with the runtime/runtime_stm32f407.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() / 4 // APB1 Frequency
|
|
||||||
}
|
|
||||||
return clock / baudRate
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------- SPI related types and code
|
|
||||||
|
|
||||||
// SPI on the STM32Fxxx using MODER / alternate function pins
|
|
||||||
type SPI struct {
|
type SPI struct {
|
||||||
Bus *stm32.SPI_Type
|
Bus *stm32.SPI_Type
|
||||||
AltFuncSelector stm32.AltFunc
|
AltFuncSelector stm32.AltFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set baud rate for SPI
|
func (spi SPI) configurePins(config SPIConfig) {}
|
||||||
func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
func (spi SPI) getBaudRate(config SPIConfig) uint32 { return 0 }
|
||||||
var conf uint32
|
|
||||||
|
|
||||||
localFrequency := config.Frequency
|
// -- I2C ----------------------------------------------------------------------
|
||||||
if spi.Bus != stm32.SPI1 {
|
|
||||||
// Assume it's SPI2 or SPI3 on APB1 at 1/2 the clock frequency of APB2, so
|
|
||||||
// we want to pretend to request 2x the baudrate asked for
|
|
||||||
localFrequency = localFrequency * 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// set frequency dependent on PCLK prescaler. Since these are rather weird
|
type I2C struct {
|
||||||
// speeds due to the CPU freqency, pick a range up to that frquency for
|
Bus *stm32.I2C_Type
|
||||||
// clients to use more human-understandable numbers, e.g. nearest 100KHz
|
AltFuncSelector stm32.AltFunc
|
||||||
|
|
||||||
// These are based on APB2 clock frquency (84MHz on the discovery board)
|
|
||||||
// TODO: also include the MCU/APB clock setting in the equation
|
|
||||||
switch true {
|
|
||||||
case localFrequency < 328125:
|
|
||||||
conf = stm32.SPI_PCLK_256
|
|
||||||
case localFrequency < 656250:
|
|
||||||
conf = stm32.SPI_PCLK_128
|
|
||||||
case localFrequency < 1312500:
|
|
||||||
conf = stm32.SPI_PCLK_64
|
|
||||||
case localFrequency < 2625000:
|
|
||||||
conf = stm32.SPI_PCLK_32
|
|
||||||
case localFrequency < 5250000:
|
|
||||||
conf = stm32.SPI_PCLK_16
|
|
||||||
case localFrequency < 10500000:
|
|
||||||
conf = stm32.SPI_PCLK_8
|
|
||||||
// NOTE: many SPI components won't operate reliably (or at all) above 10MHz
|
|
||||||
// Check the datasheet of the part
|
|
||||||
case localFrequency < 21000000:
|
|
||||||
conf = stm32.SPI_PCLK_4
|
|
||||||
case localFrequency < 42000000:
|
|
||||||
conf = stm32.SPI_PCLK_2
|
|
||||||
default:
|
|
||||||
// None of the specific baudrates were selected; choose the lowest speed
|
|
||||||
conf = stm32.SPI_PCLK_256
|
|
||||||
}
|
|
||||||
|
|
||||||
return conf << stm32.SPI_CR1_BR_Pos
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure SPI pins for input output and clock
|
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
|
||||||
config.SCK.ConfigureAltFunc(PinConfig{Mode: PinModeSPICLK}, spi.AltFuncSelector)
|
|
||||||
config.SDO.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDO}, spi.AltFuncSelector)
|
|
||||||
config.SDI.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDI}, spi.AltFuncSelector)
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче