stm32f4disco

Constants

  1. const (
  2. PA0 = portA + 0
  3. PA1 = portA + 1
  4. PA2 = portA + 2
  5. PA3 = portA + 3
  6. PA4 = portA + 4
  7. PA5 = portA + 5
  8. PA6 = portA + 6
  9. PA7 = portA + 7
  10. PA8 = portA + 8
  11. PA9 = portA + 9
  12. PA10 = portA + 10
  13. PA11 = portA + 11
  14. PA12 = portA + 12
  15. PA13 = portA + 13
  16. PA14 = portA + 14
  17. PA15 = portA + 15
  18. PB0 = portB + 0
  19. PB1 = portB + 1
  20. PB2 = portB + 2
  21. PB3 = portB + 3
  22. PB4 = portB + 4
  23. PB5 = portB + 5
  24. PB6 = portB + 6
  25. PB7 = portB + 7
  26. PB8 = portB + 8
  27. PB9 = portB + 9
  28. PB10 = portB + 10
  29. PB11 = portB + 11
  30. PB12 = portB + 12
  31. PB13 = portB + 13
  32. PB14 = portB + 14
  33. PB15 = portB + 15
  34. PC0 = portC + 0
  35. PC1 = portC + 1
  36. PC2 = portC + 2
  37. PC3 = portC + 3
  38. PC4 = portC + 4
  39. PC5 = portC + 5
  40. PC6 = portC + 6
  41. PC7 = portC + 7
  42. PC8 = portC + 8
  43. PC9 = portC + 9
  44. PC10 = portC + 10
  45. PC11 = portC + 11
  46. PC12 = portC + 12
  47. PC13 = portC + 13
  48. PC14 = portC + 14
  49. PC15 = portC + 15
  50. PD0 = portD + 0
  51. PD1 = portD + 1
  52. PD2 = portD + 2
  53. PD3 = portD + 3
  54. PD4 = portD + 4
  55. PD5 = portD + 5
  56. PD6 = portD + 6
  57. PD7 = portD + 7
  58. PD8 = portD + 8
  59. PD9 = portD + 9
  60. PD10 = portD + 10
  61. PD11 = portD + 11
  62. PD12 = portD + 12
  63. PD13 = portD + 13
  64. PD14 = portD + 14
  65. PD15 = portD + 15
  66. PE0 = portE + 0
  67. PE1 = portE + 1
  68. PE2 = portE + 2
  69. PE3 = portE + 3
  70. PE4 = portE + 4
  71. PE5 = portE + 5
  72. PE6 = portE + 6
  73. PE7 = portE + 7
  74. PE8 = portE + 8
  75. PE9 = portE + 9
  76. PE10 = portE + 10
  77. PE11 = portE + 11
  78. PE12 = portE + 12
  79. PE13 = portE + 13
  80. PE14 = portE + 14
  81. PE15 = portE + 15
  82. PH0 = portH + 0
  83. PH1 = portH + 1
  84. )
  1. const (
  2. LED = LED_BUILTIN
  3. LED1 = LED_GREEN
  4. LED2 = LED_ORANGE
  5. LED3 = LED_RED
  6. LED4 = LED_BLUE
  7. LED_BUILTIN = LED_GREEN
  8. LED_GREEN = PD12
  9. LED_ORANGE = PD13
  10. LED_RED = PD14
  11. LED_BLUE = PD15
  12. )
  1. const (
  2. UART_TX_PIN = PA2
  3. UART_RX_PIN = PA3
  4. )

UART pins

  1. const NoPin = Pin(-1)

NoPin explicitly indicates “not a pin”. Use this pin if you want to leave oneof the pins in a peripheral unconfigured (if supported by the hardware).

  1. const (
  2. // Mode Flag
  3. PinOutput PinMode = 0
  4. PinInput PinMode = PinInputFloating
  5. PinInputFloating PinMode = 1
  6. PinInputPulldown PinMode = 2
  7. PinInputPullup PinMode = 3
  8. // for UART
  9. PinModeUartTX PinMode = 4
  10. PinModeUartRX PinMode = 5
  11. //GPIOx_MODER
  12. GPIO_MODE_INPUT = 0
  13. GPIO_MODE_GENERAL_OUTPUT = 1
  14. GPIO_MODE_ALTERNABTIVE = 2
  15. GPIO_MODE_ANALOG = 3
  16. //GPIOx_OTYPER
  17. GPIO_OUTPUT_MODE_PUSH_PULL = 0
  18. GPIO_OUTPUT_MODE_OPEN_DRAIN = 1
  19. // GPIOx_OSPEEDR
  20. GPIO_SPEED_LOW = 0
  21. GPIO_SPEED_MID = 1
  22. GPIO_SPEED_HI = 2
  23. GPIO_SPEED_VERY_HI = 3
  24. // GPIOx_PUPDR
  25. GPIO_FLOATING = 0
  26. GPIO_PULL_UP = 1
  27. GPIO_PULL_DOWN = 2
  28. )

Variables

  1. var (
  2. ErrInvalidInputPin = errors.New("machine: invalid input pin")
  3. ErrInvalidOutputPin = errors.New("machine: invalid output pin")
  4. ErrInvalidClockPin = errors.New("machine: invalid clock pin")
  5. ErrInvalidDataPin = errors.New("machine: invalid data pin")
  6. )
  1. var (
  2. // Both UART0 and UART1 refer to USART2.
  3. UART0 = UART{Buffer: NewRingBuffer()}
  4. UART1 = &UART0
  5. )

func CPUFrequency

  1. func CPUFrequency() uint32

func NewRingBuffer

  1. func NewRingBuffer() *RingBuffer

NewRingBuffer returns a new ring buffer.

type ADC

  1. type ADC struct {
  2. Pin Pin
  3. }

type PWM

  1. type PWM struct {
  2. Pin Pin
  3. }

type Pin

  1. type Pin int8

Pin is a single pin on a chip, which may be connected to other hardwaredevices. It can either be used directly as GPIO pin or it can be used inother peripherals like ADC, I2C, etc.

func (Pin) Configure

  1. func (p Pin) Configure(config PinConfig)

Configure this pin with the given configuration.

func (Pin) High

  1. func (p Pin) High()

High sets this GPIO pin to high, assuming it has been configured as an outputpin. It is hardware dependent (and often undefined) what happens if you set apin to high that is not configured as an output pin.

func (Pin) Low

  1. func (p Pin) Low()

Low sets this GPIO pin to low, assuming it has been configured as an outputpin. It is hardware dependent (and often undefined) what happens if you set apin to low that is not configured as an output pin.

func (Pin) Set

  1. func (p Pin) Set(high bool)

Set the pin to high or low.Warning: only use this on an output pin!

type PinConfig

  1. type PinConfig struct {
  2. Mode PinMode
  3. }

type PinMode

  1. type PinMode uint8

type RingBuffer

  1. type RingBuffer struct {
  2. rxbuffer [bufferSize]volatile.Register8
  3. head volatile.Register8
  4. tail volatile.Register8
  5. }

RingBuffer is ring buffer implementation inspired by post athttps://www.embeddedrelated.com/showthread/comp.arch.embedded/77084-1.php

It has some limitations currently due to how “volatile” variables that aremembers of a struct are not compiled correctly by TinyGo.See https://github.com/tinygo-org/tinygo/issues/151 for details.

func (*RingBuffer) Get

  1. func (rb *RingBuffer) Get() (byte, bool)

Get returns a byte from the buffer. If the buffer is empty,the method will return a false as the second value.

func (*RingBuffer) Put

  1. func (rb *RingBuffer) Put(val byte) bool

Put stores a byte in the buffer. If the buffer is alreadyfull, the method will return false.

func (*RingBuffer) Used

  1. func (rb *RingBuffer) Used() uint8

Used returns how many bytes in buffer have been used.

type UART

  1. type UART struct {
  2. Buffer *RingBuffer
  3. }

UART

func (UART) Buffered

  1. func (uart UART) Buffered() int

Buffered returns the number of bytes currently stored in the RX buffer.

func (UART) Configure

  1. func (uart UART) Configure(config UARTConfig)

Configure the UART.

func (UART) Read

  1. func (uart UART) Read(data []byte) (n int, err error)

Read from the RX buffer.

func (UART) ReadByte

  1. func (uart UART) ReadByte() (byte, error)

ReadByte reads a single byte from the RX buffer.If there is no data in the buffer, returns an error.

func (UART) Receive

  1. func (uart UART) Receive(data byte)

Receive handles adding data to the UART’s data buffer.Usually called by the IRQ handler for a machine.

func (UART) Write

  1. func (uart UART) Write(data []byte) (n int, err error)

Write data to the UART.

func (UART) WriteByte

  1. func (uart UART) WriteByte(c byte) error

WriteByte writes a byte of data to the UART.

type UARTConfig

  1. type UARTConfig struct {
  2. BaudRate uint32
  3. TX Pin
  4. RX Pin
  5. }