Skip to content

Commit

Permalink
stm32f103 (bluepill): add pwm
Browse files Browse the repository at this point in the history
  • Loading branch information
kenbell authored and deadprogram committed May 27, 2021
1 parent ac54302 commit 003c96e
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 111 deletions.
11 changes: 11 additions & 0 deletions src/examples/pwm/bluepill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build bluepill

package main

import "machine"

var (
pwm = &machine.TIM2
pinA = machine.PA0
pinB = machine.PA1
)
39 changes: 0 additions & 39 deletions src/machine/board_bluepill.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,6 @@ import (
"runtime/interrupt"
)

// https://wiki.stm32duino.com/index.php?title=File:Bluepillpinout.gif
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
PC13 = portC + 13
PC14 = portC + 14
PC15 = portC + 15
)

const (
LED = PC13
)
Expand Down
70 changes: 0 additions & 70 deletions src/machine/board_nucleof103rb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,6 @@ import (
"runtime/interrupt"
)

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
)

const (
LED = LED_BUILTIN
LED_BUILTIN = LED_GREEN
Expand Down
5 changes: 3 additions & 2 deletions src/machine/machine_stm32_tim.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build stm32f4 stm32l5 stm32l0 stm32l4 stm32l5 stm32f7
// +build stm32

package machine

Expand Down Expand Up @@ -178,7 +178,8 @@ func (t *TIM) Channel(pin Pin) (uint8, error) {
for chi, ch := range t.Channels {
for _, p := range ch.Pins {
if p.Pin == pin {
p.Pin.ConfigureAltFunc(PinConfig{Mode: PinModePWMOutput}, p.AltFunc)
t.configurePin(uint8(chi), p)
//p.Pin.ConfigureAltFunc(PinConfig{Mode: PinModePWMOutput}, p.AltFunc)
return uint8(chi), nil
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/machine/machine_stm32_tim_moder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build stm32,!stm32f1

package machine

// Configuration of a GPIO pin for PWM output for STM32 MCUs with MODER
// register (most MCUs except STM32F1 series).

func (t *TIM) configurePin(channel uint8, pf PinFunction) {
pf.Pin.ConfigureAltFunc(PinConfig{Mode: PinModePWMOutput}, pf.AltFunc)
}
Loading

0 comments on commit 003c96e

Please sign in to comment.