aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine
diff options
context:
space:
mode:
authorardnew <[email protected]>2020-09-01 04:31:41 -0500
committerGitHub <[email protected]>2020-09-01 11:31:41 +0200
commit7f829fe1538671800674d90a5ef47eb6f7a81cd7 (patch)
tree09f3379901a0f42cb5ac732cb5f2a3107da21205 /src/machine
parent946184b8bac112b5a574a86af4425f84dc55e21e (diff)
downloadtinygo-7f829fe1538671800674d90a5ef47eb6f7a81cd7.tar.gz
tinygo-7f829fe1538671800674d90a5ef47eb6f7a81cd7.zip
machine/stm32f4: refactor common code and add new build tag stm32f4 (#1332)
* machine/STM32F4: break out STM32F4 machine with new build tag
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/board_stm32.go13
-rw-r--r--src/machine/board_stm32f4disco.go90
-rw-r--r--src/machine/i2c.go2
-rw-r--r--src/machine/machine_stm32.go13
-rw-r--r--src/machine/machine_stm32f4.go229
-rw-r--r--src/machine/machine_stm32f407.go70
6 files changed, 246 insertions, 171 deletions
diff --git a/src/machine/board_stm32.go b/src/machine/board_stm32.go
index 8dbea217e..7153be860 100644
--- a/src/machine/board_stm32.go
+++ b/src/machine/board_stm32.go
@@ -1,16 +1,5 @@
-// +build bluepill nucleof103rb stm32f4disco
+// +build bluepill nucleof103rb stm32f4
package machine
// Peripheral abstraction layer for the stm32.
-
-const (
- portA Pin = iota * 16
- portB
- portC
- portD
- portE
- portF
- portG
- portH
-)
diff --git a/src/machine/board_stm32f4disco.go b/src/machine/board_stm32f4disco.go
index 5367b66c4..20e37a32c 100644
--- a/src/machine/board_stm32f4disco.go
+++ b/src/machine/board_stm32f4disco.go
@@ -8,96 +8,6 @@ import (
)
const (
- PA0 = portA + 0
- PA1 = portA + 1
- PA2 = portA + 2
- PA3 = portA + 3
- PA4 = portA + 4
- PA5 = portA + 5
- PA6 = portA + 6
- PA7 = portA + 7
- PA8 = portA + 8
- PA9 = portA + 9
- PA10 = portA + 10
- PA11 = portA + 11
- PA12 = portA + 12
- PA13 = portA + 13
- PA14 = portA + 14
- PA15 = portA + 15
-
- PB0 = portB + 0
- PB1 = portB + 1
- PB2 = portB + 2
- PB3 = portB + 3
- PB4 = portB + 4
- PB5 = portB + 5
- PB6 = portB + 6
- PB7 = portB + 7
- PB8 = portB + 8
- PB9 = portB + 9
- PB10 = portB + 10
- PB11 = portB + 11
- PB12 = portB + 12
- PB13 = portB + 13
- PB14 = portB + 14
- PB15 = portB + 15
-
- PC0 = portC + 0
- PC1 = portC + 1
- PC2 = portC + 2
- PC3 = portC + 3
- PC4 = portC + 4
- PC5 = portC + 5
- PC6 = portC + 6
- PC7 = portC + 7
- PC8 = portC + 8
- PC9 = portC + 9
- PC10 = portC + 10
- PC11 = portC + 11
- PC12 = portC + 12
- PC13 = portC + 13
- PC14 = portC + 14
- PC15 = portC + 15
-
- PD0 = portD + 0
- PD1 = portD + 1
- PD2 = portD + 2
- PD3 = portD + 3
- PD4 = portD + 4
- PD5 = portD + 5
- PD6 = portD + 6
- PD7 = portD + 7
- PD8 = portD + 8
- PD9 = portD + 9
- PD10 = portD + 10
- PD11 = portD + 11
- PD12 = portD + 12
- PD13 = portD + 13
- PD14 = portD + 14
- PD15 = portD + 15
-
- PE0 = portE + 0
- PE1 = portE + 1
- PE2 = portE + 2
- PE3 = portE + 3
- PE4 = portE + 4
- PE5 = portE + 5
- PE6 = portE + 6
- PE7 = portE + 7
- PE8 = portE + 8
- PE9 = portE + 9
- PE10 = portE + 10
- PE11 = portE + 11
- PE12 = portE + 12
- PE13 = portE + 13
- PE14 = portE + 14
- PE15 = portE + 15
-
- PH0 = portH + 0
- PH1 = portH + 1
-)
-
-const (
LED = LED_BUILTIN
LED1 = LED_GREEN
LED2 = LED_ORANGE
diff --git a/src/machine/i2c.go b/src/machine/i2c.go
index 3bab81d0d..b46506063 100644
--- a/src/machine/i2c.go
+++ b/src/machine/i2c.go
@@ -1,4 +1,4 @@
-// +build avr nrf sam stm32,!stm32f4disco fe310 k210
+// +build avr nrf sam stm32,!stm32f4 fe310 k210
package machine
diff --git a/src/machine/machine_stm32.go b/src/machine/machine_stm32.go
index b1ee97aab..8ef5fed7e 100644
--- a/src/machine/machine_stm32.go
+++ b/src/machine/machine_stm32.go
@@ -4,6 +4,19 @@ package machine
// Peripheral abstraction layer for the stm32.
+const (
+ portA Pin = iota * 16
+ portB
+ portC
+ portD
+ portE
+ portF
+ portG
+ portH
+ portI
+ portJ
+)
+
type PinMode uint8
// Peripheral operations sequence:
diff --git a/src/machine/machine_stm32f4.go b/src/machine/machine_stm32f4.go
new file mode 100644
index 000000000..a0b00a811
--- /dev/null
+++ b/src/machine/machine_stm32f4.go
@@ -0,0 +1,229 @@
+// +build stm32f4
+
+package machine
+
+// Peripheral abstraction layer for the stm32f4
+
+import (
+ "device/stm32"
+ "unsafe"
+)
+
+const (
+ PA0 = portA + 0
+ PA1 = portA + 1
+ PA2 = portA + 2
+ PA3 = portA + 3
+ PA4 = portA + 4
+ PA5 = portA + 5
+ PA6 = portA + 6
+ PA7 = portA + 7
+ PA8 = portA + 8
+ PA9 = portA + 9
+ PA10 = portA + 10
+ PA11 = portA + 11
+ PA12 = portA + 12
+ PA13 = portA + 13
+ PA14 = portA + 14
+ PA15 = portA + 15
+
+ PB0 = portB + 0
+ PB1 = portB + 1
+ PB2 = portB + 2
+ PB3 = portB + 3
+ PB4 = portB + 4
+ PB5 = portB + 5
+ PB6 = portB + 6
+ PB7 = portB + 7
+ PB8 = portB + 8
+ PB9 = portB + 9
+ PB10 = portB + 10
+ PB11 = portB + 11
+ PB12 = portB + 12
+ PB13 = portB + 13
+ PB14 = portB + 14
+ PB15 = portB + 15
+
+ PC0 = portC + 0
+ PC1 = portC + 1
+ PC2 = portC + 2
+ PC3 = portC + 3
+ PC4 = portC + 4
+ PC5 = portC + 5
+ PC6 = portC + 6
+ PC7 = portC + 7
+ PC8 = portC + 8
+ PC9 = portC + 9
+ PC10 = portC + 10
+ PC11 = portC + 11
+ PC12 = portC + 12
+ PC13 = portC + 13
+ PC14 = portC + 14
+ PC15 = portC + 15
+
+ PD0 = portD + 0
+ PD1 = portD + 1
+ PD2 = portD + 2
+ PD3 = portD + 3
+ PD4 = portD + 4
+ PD5 = portD + 5
+ PD6 = portD + 6
+ PD7 = portD + 7
+ PD8 = portD + 8
+ PD9 = portD + 9
+ PD10 = portD + 10
+ PD11 = portD + 11
+ PD12 = portD + 12
+ PD13 = portD + 13
+ PD14 = portD + 14
+ PD15 = portD + 15
+
+ PE0 = portE + 0
+ PE1 = portE + 1
+ PE2 = portE + 2
+ PE3 = portE + 3
+ PE4 = portE + 4
+ PE5 = portE + 5
+ PE6 = portE + 6
+ PE7 = portE + 7
+ PE8 = portE + 8
+ PE9 = portE + 9
+ PE10 = portE + 10
+ PE11 = portE + 11
+ PE12 = portE + 12
+ PE13 = portE + 13
+ PE14 = portE + 14
+ PE15 = portE + 15
+
+ PH0 = portH + 0
+ PH1 = portH + 1
+)
+
+func (p Pin) getPort() *stm32.GPIO_Type {
+ switch p / 16 {
+ case 0:
+ return stm32.GPIOA
+ case 1:
+ return stm32.GPIOB
+ case 2:
+ return stm32.GPIOC
+ case 3:
+ return stm32.GPIOD
+ case 4:
+ return stm32.GPIOE
+ case 5:
+ return stm32.GPIOF
+ case 6:
+ return stm32.GPIOG
+ case 7:
+ return stm32.GPIOH
+ case 8:
+ return stm32.GPIOI
+ default:
+ panic("machine: unknown port")
+ }
+}
+
+// enableClock enables the clock for this desired GPIO port.
+func (p Pin) enableClock() {
+ switch p / 16 {
+ case 0:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOAEN)
+ case 1:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOBEN)
+ case 2:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOCEN)
+ case 3:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIODEN)
+ case 4:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOEEN)
+ case 5:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOFEN)
+ case 6:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOGEN)
+ case 7:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOHEN)
+ case 8:
+ stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOIEN)
+ default:
+ panic("machine: unknown port")
+ }
+}
+
+// Enable peripheral clock
+func enableAltFuncClock(bus unsafe.Pointer) {
+ switch bus {
+ case unsafe.Pointer(stm32.DAC): // DAC interface clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_DACEN)
+ case unsafe.Pointer(stm32.PWR): // Power interface clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_PWREN)
+ case unsafe.Pointer(stm32.CAN2): // CAN 2 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_CAN2EN)
+ case unsafe.Pointer(stm32.CAN1): // CAN 1 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_CAN1EN)
+ case unsafe.Pointer(stm32.I2C3): // I2C3 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_I2C3EN)
+ case unsafe.Pointer(stm32.I2C2): // I2C2 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_I2C2EN)
+ case unsafe.Pointer(stm32.I2C1): // I2C1 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_I2C1EN)
+ case unsafe.Pointer(stm32.UART5): // UART5 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_UART5EN)
+ case unsafe.Pointer(stm32.UART4): // UART4 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_UART4EN)
+ case unsafe.Pointer(stm32.USART3): // USART3 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_USART3EN)
+ case unsafe.Pointer(stm32.USART2): // USART2 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_USART2EN)
+ case unsafe.Pointer(stm32.SPI3): // SPI3 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_SPI3EN)
+ case unsafe.Pointer(stm32.SPI2): // SPI2 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_SPI2EN)
+ case unsafe.Pointer(stm32.WWDG): // Window watchdog clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_WWDGEN)
+ case unsafe.Pointer(stm32.TIM14): // TIM14 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM14EN)
+ case unsafe.Pointer(stm32.TIM13): // TIM13 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM13EN)
+ case unsafe.Pointer(stm32.TIM12): // TIM12 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM12EN)
+ case unsafe.Pointer(stm32.TIM7): // TIM7 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM7EN)
+ case unsafe.Pointer(stm32.TIM6): // TIM6 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM6EN)
+ case unsafe.Pointer(stm32.TIM5): // TIM5 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM5EN)
+ case unsafe.Pointer(stm32.TIM4): // TIM4 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM4EN)
+ case unsafe.Pointer(stm32.TIM3): // TIM3 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM3EN)
+ case unsafe.Pointer(stm32.TIM2): // TIM2 clock enable
+ stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_TIM2EN)
+ case unsafe.Pointer(stm32.TIM11): // TIM11 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM11EN)
+ case unsafe.Pointer(stm32.TIM10): // TIM10 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM10EN)
+ case unsafe.Pointer(stm32.TIM9): // TIM9 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM9EN)
+ case unsafe.Pointer(stm32.SYSCFG): // System configuration controller clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_SYSCFGEN)
+ case unsafe.Pointer(stm32.SPI1): // SPI1 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_SPI1EN)
+ case unsafe.Pointer(stm32.SDIO): // SDIO clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_SDIOEN)
+ case unsafe.Pointer(stm32.ADC3): // ADC3 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_ADC3EN)
+ case unsafe.Pointer(stm32.ADC2): // ADC2 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_ADC2EN)
+ case unsafe.Pointer(stm32.ADC1): // ADC1 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_ADC1EN)
+ case unsafe.Pointer(stm32.USART6): // USART6 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_USART6EN)
+ case unsafe.Pointer(stm32.USART1): // USART1 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_USART1EN)
+ case unsafe.Pointer(stm32.TIM8): // TIM8 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM8EN)
+ case unsafe.Pointer(stm32.TIM1): // TIM1 clock enable
+ stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM1EN)
+ }
+}
diff --git a/src/machine/machine_stm32f407.go b/src/machine/machine_stm32f407.go
index 16d1e10bf..232b8e3d2 100644
--- a/src/machine/machine_stm32f407.go
+++ b/src/machine/machine_stm32f407.go
@@ -1,84 +1,18 @@
-// +build stm32,stm32f407
+// +build stm32f407
package machine
-// Peripheral abstraction layer for the stm32f4(07)
+// Peripheral abstraction layer for the stm32f407
import (
"device/stm32"
"runtime/interrupt"
- "unsafe"
)
func CPUFrequency() uint32 {
return 168000000
}
-func (p Pin) getPort() *stm32.GPIO_Type {
- switch p / 16 {
- case 0:
- return stm32.GPIOA
- case 1:
- return stm32.GPIOB
- case 2:
- return stm32.GPIOC
- case 3:
- return stm32.GPIOD
- case 4:
- return stm32.GPIOE
- case 5:
- return stm32.GPIOF
- case 6:
- return stm32.GPIOG
- case 7:
- return stm32.GPIOH
- case 8:
- return stm32.GPIOI
- default:
- panic("machine: unknown port")
- }
-}
-
-// enableClock enables the clock for this desired GPIO port.
-func (p Pin) enableClock() {
- switch p / 16 {
- case 0:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOAEN)
- case 1:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOBEN)
- case 2:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOCEN)
- case 3:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIODEN)
- case 4:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOEEN)
- case 5:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOFEN)
- case 6:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOGEN)
- case 7:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOHEN)
- case 8:
- stm32.RCC.AHB1ENR.SetBits(stm32.RCC_AHB1ENR_GPIOIEN)
- default:
- panic("machine: unknown port")
- }
-}
-
-// Enable peripheral clock
-func enableAltFuncClock(bus unsafe.Pointer) {
- switch bus {
- case unsafe.Pointer(stm32.USART1):
- stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_USART1EN)
- case unsafe.Pointer(stm32.USART2):
- stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_USART2EN)
- case unsafe.Pointer(stm32.I2C1):
- stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_I2C1EN)
- case unsafe.Pointer(stm32.SPI1):
- stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_SPI1EN)
- }
-}
-
//---------- UART related types and code
// UART representation