github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/board_stm32f4disco.go (about) 1 //go:build stm32f4disco 2 3 package machine 4 5 import ( 6 "device/stm32" 7 "runtime/interrupt" 8 ) 9 10 const ( 11 LED1 = LED_GREEN 12 LED2 = LED_ORANGE 13 LED3 = LED_RED 14 LED4 = LED_BLUE 15 LED_GREEN = PD12 16 LED_ORANGE = PD13 17 LED_RED = PD14 18 LED_BLUE = PD15 19 LED = LED_BUILTIN 20 LED_BUILTIN = LED_GREEN 21 ) 22 23 const ( 24 BUTTON = PA0 25 ) 26 27 // Analog Pins 28 const ( 29 ADC0 = PA0 30 ADC1 = PA1 31 ADC2 = PA2 32 ADC3 = PA3 33 ADC4 = PA4 34 ADC5 = PA5 35 ADC6 = PA6 36 ADC7 = PA7 37 ADC8 = PB0 38 ADC9 = PB1 39 ADC10 = PC0 40 ADC11 = PC1 41 ADC12 = PC2 42 ADC13 = PC3 43 ADC14 = PC4 44 ADC15 = PC5 45 ) 46 47 // UART pins 48 const ( 49 UART_TX_PIN = PA2 50 UART_RX_PIN = PA3 51 ) 52 53 var ( 54 UART1 = &_UART1 55 _UART1 = UART{ 56 Buffer: NewRingBuffer(), 57 Bus: stm32.USART2, 58 TxAltFuncSelector: AF7_USART1_2_3, 59 RxAltFuncSelector: AF7_USART1_2_3, 60 } 61 DefaultUART = UART1 62 ) 63 64 // set up RX IRQ handler. Follow similar pattern for other UARTx instances 65 func init() { 66 UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) 67 } 68 69 // SPI pins 70 const ( 71 SPI1_SCK_PIN = PA5 72 SPI1_SDI_PIN = PA6 73 SPI1_SDO_PIN = PA7 74 SPI0_SCK_PIN = SPI1_SCK_PIN 75 SPI0_SDI_PIN = SPI1_SDI_PIN 76 SPI0_SDO_PIN = SPI1_SDO_PIN 77 ) 78 79 // MEMs accelerometer 80 const ( 81 MEMS_ACCEL_CS = PE3 82 MEMS_ACCEL_INT1 = PE0 83 MEMS_ACCEL_INT2 = PE1 84 ) 85 86 // Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1. 87 // TODO: implement SPI2 and SPI3. 88 var ( 89 SPI0 = SPI{ 90 Bus: stm32.SPI1, 91 AltFuncSelector: AF5_SPI1_SPI2, 92 } 93 SPI1 = &SPI0 94 ) 95 96 const ( 97 I2C0_SCL_PIN = PB6 98 I2C0_SDA_PIN = PB9 99 ) 100 101 var ( 102 I2C0 = &I2C{ 103 Bus: stm32.I2C1, 104 AltFuncSelector: AF4_I2C1_2_3, 105 } 106 )